dockerhelper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 175951aa3c1e8a37f9ae332f110502b62fc79e15
4
+ data.tar.gz: 469962fce86e7d83ddb6cdda06adedc5b5e52b0b
5
+ SHA512:
6
+ metadata.gz: 6b0325ed7ff753b267495f3d042c3dd92b27ae1a1fc7922d270b096c27adac6328f8c09c176bb118f9f42f3929d7bb1785b4c32dea8bc8d8ad20fd2fca27a586
7
+ data.tar.gz: 7733b57ed2f9e536efe233b6cc4186dad97852794839b32f57751db8adf62c7f6b1afd504d95dbfe2d78241af42e177c255f1d0f0b50a47683d71b14d1a8b179
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dockerhelper.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Dockerhelper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dockerhelper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dockerhelper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dockerhelper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dockerhelper.
36
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dockerhelper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dockerhelper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dockerhelper"
8
+ spec.version = Dockerhelper::VERSION
9
+ spec.authors = ["Josh McDade"]
10
+ spec.email = ["josh.ncsu@gmail.com"]
11
+
12
+ spec.summary = %q{Docker and Kubernetes helper scripts}
13
+ spec.description = %q{Docker and Kubernetes helper scripts}
14
+ spec.homepage = "https://github.com/joshm1/dockerhelper"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ end
@@ -0,0 +1,11 @@
1
+ require "dockerhelper/command"
2
+ require "dockerhelper/docker"
3
+ require "dockerhelper/git"
4
+ require "dockerhelper/version"
5
+
6
+ module Dockerhelper
7
+ def cmd(cmd, label: '')
8
+ Command.new(cmd, label: label).run
9
+ end
10
+ module_function :cmd
11
+ end
@@ -0,0 +1,68 @@
1
+ module Dockerhelper
2
+ class Command
3
+ attr_reader :cmd, :label, :chdir
4
+
5
+ def initialize(cmd, label: '', chdir: Dir.pwd)
6
+ @label = " #{label}" if label.size > 0
7
+ @cmd = cmd
8
+ @chdir = chdir
9
+ end
10
+
11
+ def capture
12
+ stdout, stderr, status = Open3.capture3(cmd)
13
+ pid = status.pid
14
+ cmd_prefix = "[#{pid}#{label}]"
15
+
16
+ $stdout.puts ">> #{yellow(cmd_prefix)} cwd: #{chdir} cmd: #{cmd}"
17
+ unless stdout.empty?
18
+ stdout.lines.each do |line|
19
+ $stdout.puts " #{green(cmd_prefix)} #{line}"
20
+ end
21
+ end
22
+
23
+ unless stderr.empty?
24
+ stderr.lines.each do |line|
25
+ $stderr.puts " #{red(cmd_prefix)} #{line}"
26
+ end
27
+ end
28
+
29
+ $stdout.puts "<< #{yellow(cmd_prefix)} exit_status: #{status}"
30
+ stdout
31
+ end
32
+
33
+ def run
34
+ Open3.popen3(cmd, chdir: chdir) do |stdin, stdout, stderr, wait_thr|
35
+ pid = wait_thr.pid
36
+ cmd_prefix = "[#{pid}#{label}]"
37
+ $stdout.puts ">> #{yellow(cmd_prefix)} cwd: #{chdir} cmd: #{cmd}"
38
+
39
+ stdin.close
40
+ stderr_thr = Thread.new do
41
+ while line = stderr.gets
42
+ $stderr.puts " #{red(cmd_prefix)} #{line}"
43
+ end
44
+ end
45
+
46
+ stdout_thr = Thread.new do
47
+ while line = stdout.gets
48
+ $stdout.puts " #{green(cmd_prefix)} #{line}"
49
+ end
50
+ end
51
+
52
+ stderr_thr.join
53
+ stdout_thr.join
54
+
55
+ exit_status = wait_thr.value
56
+ $stdout.puts "<< #{yellow(cmd_prefix)} exit_status: #{exit_status}"
57
+ end
58
+ end
59
+
60
+ def colorize(text, color_code)
61
+ "\e[#{color_code}m#{text}\e[0m"
62
+ end
63
+
64
+ def red(text); colorize(text, 31); end
65
+ def green(text); colorize(text, 32); end
66
+ def yellow(text); colorize(text, 33); end
67
+ end
68
+ end
@@ -0,0 +1,22 @@
1
+ module Dockerhelper
2
+ class Docker
3
+ attr_reader :chdir
4
+
5
+ def initialize(chdir: Dir.pwd)
6
+ @chdir = chdir
7
+ end
8
+
9
+ def tag(image, tag)
10
+ Command.new("docker tag -f #{image} #{tag}", label: 'docker-tag').run
11
+ end
12
+
13
+ def build(dockerfile, tag: nil)
14
+ tag || (raise 'Tag option is required')
15
+ Command.new("docker build -t #{tag} -f #{dockerfile} .", label: 'docker-build', chdir: chdir).run
16
+ end
17
+
18
+ def push(repo, tag: 'latest')
19
+ Command.new("docker push #{repo}:#{tag}", label: 'docker-build').run
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ module Dockerhelper
2
+ class Git
3
+ attr_reader :git_root
4
+ def initialize(git_root)
5
+ @git_root = git_root
6
+ end
7
+
8
+ def clone(git_repo_url, branch)
9
+ check_file = File.join(git_root, '.git')
10
+ if File.exist?(check_file)
11
+ Command.new("git fetch --depth=1 origin #{branch}", label: 'git-fetch', chdir: git_root).run
12
+ Command.new("git checkout FETCH_HEAD", label: 'git-pull', chdir: git_root).run
13
+ else
14
+ Command.new("git clone --depth=1 --branch #{branch} #{git_repo_url} #{git_root}",
15
+ label: 'git-clone', chdir: git_root).run
16
+ end
17
+ end
18
+
19
+ def rev_list(max_count: 1, rev: 'FETCH_HEAD')
20
+ cmd = "git rev-list --max-count=#{max_count} #{rev}"
21
+ Command.new(cmd, label: 'git-rev-list', chdir: git_root).capture
22
+ end
23
+
24
+ def latest_rev
25
+ rev_list[0..7]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Dockerhelper
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dockerhelper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh McDade
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Docker and Kubernetes helper scripts
42
+ email:
43
+ - josh.ncsu@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - dockerhelper.gemspec
55
+ - lib/dockerhelper.rb
56
+ - lib/dockerhelper/command.rb
57
+ - lib/dockerhelper/docker.rb
58
+ - lib/dockerhelper/git.rb
59
+ - lib/dockerhelper/version.rb
60
+ homepage: https://github.com/joshm1/dockerhelper
61
+ licenses: []
62
+ metadata:
63
+ allowed_push_host: https://rubygems.org
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Docker and Kubernetes helper scripts
84
+ test_files: []