dockage 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.md +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/bin/dockage +9 -0
- data/dockage.gemspec +29 -0
- data/lib/dockage/cli.rb +100 -0
- data/lib/dockage/docker/parse.rb +44 -0
- data/lib/dockage/docker/shell.rb +154 -0
- data/lib/dockage/docker.rb +15 -0
- data/lib/dockage/settings.rb +27 -0
- data/lib/dockage/ssh.rb +48 -0
- data/lib/dockage/templates/dockage.yml +21 -0
- data/lib/dockage/version.rb +3 -0
- data/lib/dockage.rb +73 -0
- data/spec/spec_helper.rb +87 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2417e272201a9a36b24260d7e8b168379718e9e3
|
4
|
+
data.tar.gz: eb9a331706bfe55962f6dcc90a265221eec0367b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46ab38e61c9d00034b60c539306f22c6d57d1921722f92ba2b17cb1049016005e94572894a255acbb8a83bc8633a511abb6c40b1248dcbd52624fb2414ec6bfe
|
7
|
+
data.tar.gz: 7cc2aa98103a73399c8c8935cc3a9c134e05018fab01f9af29b45b0c3e7fcf9ceda1f24f2c553da19b362d73c63ffa9044562dcb543685c3efa4cc1501caa663
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Sergey Besedin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Dockage [](https://gemnasium.com/kressh/dockage) [](https://codeclimate.com/github/kressh/dockage) [](https://travis-ci.org/kressh/dockage)
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dockage'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dockage
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/dockage/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/dockage
ADDED
data/dockage.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dockage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dockage'
|
8
|
+
spec.version = Dockage::VERSION
|
9
|
+
spec.authors = ['Sergey Besedin']
|
10
|
+
spec.email = ['kr3ssh@gmail.com']
|
11
|
+
spec.summary = 'Control multiple docker containers with ease'
|
12
|
+
spec.description = 'Gem to manage multiple docker containers at once'
|
13
|
+
spec.homepage = 'http://github.com/kr3ssh/dockage'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.required_ruby_version = '>= 1.9'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = %w( dockage )
|
20
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'thor'
|
24
|
+
spec.add_dependency 'colorize'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
end
|
data/lib/dockage/cli.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'dockage'
|
2
|
+
require 'thor'
|
3
|
+
require 'colorize'
|
4
|
+
|
5
|
+
module Dockage
|
6
|
+
class CLI < Thor
|
7
|
+
def initialize(*)
|
8
|
+
super
|
9
|
+
Dockage.verbose_mode = options[:debug] || !!options[:verbose]
|
10
|
+
Dockage.debug_mode = !!options[:debug]
|
11
|
+
Dockage.force_mode = !!options[:force]
|
12
|
+
end
|
13
|
+
|
14
|
+
default_task :help
|
15
|
+
class_option 'verbose', type: :boolean, banner: 'Enable verbose output mode', aliases: '-v'
|
16
|
+
class_option 'debug', type: :boolean, banner: 'Enable debug output mode'
|
17
|
+
class_option 'quiet', type: :boolean, banner: 'Suppress all output', aliases: '-q'
|
18
|
+
class_option 'force', type: :boolean, banner: 'Run actions with force', aliases: '-f'
|
19
|
+
|
20
|
+
desc 'status [CONTAINER]', 'Show status overall or specified container'
|
21
|
+
def status(name = nil)
|
22
|
+
find_container(name) if name
|
23
|
+
puts Dockage::Docker.shell.status(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'init', 'Create example config file'
|
27
|
+
def init
|
28
|
+
Dockage.create_example_config
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'up [CONTAINER]', 'Create and run specified [CONTAINER] or all configured containers'
|
32
|
+
def up(name = nil)
|
33
|
+
find_containers(name).each do |container|
|
34
|
+
Dockage.logger("Bringing up #{container[:name].yellow.bold}")
|
35
|
+
Dockage::Docker.shell.up(container)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'reload [CONTAINER]', 'Reload specified [CONTAINER] or all configured containers'
|
40
|
+
def reload(name = nil)
|
41
|
+
find_containers(name).each do |container|
|
42
|
+
puts "Reloading #{container[:name].yellow.bold}"
|
43
|
+
Dockage::Docker.shell.reload(container)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'provide CONTAINER', 'Run provision scripts on specified CONTAINER'
|
48
|
+
def provide(name)
|
49
|
+
container = find_container(name)
|
50
|
+
Dockage.error("SSH is not configured for #{container[:name].bold}") unless container[:ssh]
|
51
|
+
Dockage::Docker.shell.provide(container)
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'destroy [CONTAINER]', 'Destroy specified [CONTAINER] or all configured containers'
|
55
|
+
def destroy(name = nil)
|
56
|
+
find_containers(name).each do |container|
|
57
|
+
Dockage::Docker.shell.stop(container[:name])
|
58
|
+
Dockage::Docker.shell.destroy(container[:name])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'ssh CONTAINER', 'SSH login to CONTAINER'
|
63
|
+
def ssh(name)
|
64
|
+
container = find_container(name)
|
65
|
+
Dockage.error("SSH is not configured for #{container[:name].bold}") unless container[:ssh]
|
66
|
+
Dockage::SSH.connect(container[:ssh])
|
67
|
+
end
|
68
|
+
|
69
|
+
desc 'shellinit', 'export DOCKER_HOST variable to current shell'
|
70
|
+
def shellinit
|
71
|
+
puts Dockage::Docker.shell.shellinit
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'version', 'dockage and docker versions'
|
75
|
+
def version
|
76
|
+
puts <<CMD
|
77
|
+
#{'Dockage'.bold}:
|
78
|
+
\tGem version #{Dockage::VERSION}
|
79
|
+
#{'Docker'.bold}:
|
80
|
+
\t#{Dockage::Docker.shell.version.gsub(/\n/, "\n\t")}
|
81
|
+
CMD
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
86
|
+
def find_containers(name = nil)
|
87
|
+
if name
|
88
|
+
Dockage.settings[:containers].select { |x| x[:name].to_s == name.to_s }
|
89
|
+
else
|
90
|
+
Dockage.settings[:containers]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def find_container(name = nil)
|
95
|
+
container = find_containers(name).first
|
96
|
+
Dockage.error("There is no settings for container #{name.bold}") unless container
|
97
|
+
container
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Dockage
|
2
|
+
module Docker
|
3
|
+
module Parse
|
4
|
+
class << self
|
5
|
+
def parse_docker_ps(string)
|
6
|
+
header = string.shift
|
7
|
+
|
8
|
+
spaces = column_width = 0
|
9
|
+
keys = {}
|
10
|
+
header.chars.each_with_index do |char, i|
|
11
|
+
if i == (header.size - 1) || (char !~ /\s/ && spaces > 1)
|
12
|
+
keys.merge!(slice_column_from_string(header, i, column_width))
|
13
|
+
column_width = 0
|
14
|
+
end
|
15
|
+
spaces = char =~ /\s/ ? spaces + 1 : 0
|
16
|
+
column_width += 1
|
17
|
+
end
|
18
|
+
|
19
|
+
string.map do |container_string|
|
20
|
+
container = Hash[keys.map { |k, v| [k, container_string[v[:start]..v[:stop]].strip] }]
|
21
|
+
container[:name] = container[:names].to_s
|
22
|
+
.split(',')
|
23
|
+
.reject{ |v| v.include?('/') }
|
24
|
+
.first
|
25
|
+
container[:running] = container[:status].downcase
|
26
|
+
.include?('up') ? true : false
|
27
|
+
container
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def slice_column_from_string(string, index, column_width)
|
32
|
+
start = index - column_width
|
33
|
+
stop = index < string.length - 1 ? (index - 1) : -1
|
34
|
+
header_key = string[start..stop].strip
|
35
|
+
.downcase
|
36
|
+
.gsub(/\s/, '_')
|
37
|
+
.to_sym
|
38
|
+
|
39
|
+
{ header_key => { start: start, stop: stop } }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module Dockage
|
2
|
+
module Docker
|
3
|
+
class Shell
|
4
|
+
|
5
|
+
DOCKER_DEFAULT_HOST = 'unix:///var/run/docker.sock'
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@env = "DOCKER_HOST=#{Dockage.settings[:docker_host] || DOCKER_DEFAULT_HOST}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def pull(image)
|
12
|
+
invoke("pull #{image}", attach_std: true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def start(name)
|
16
|
+
if container_running?(name)
|
17
|
+
Dockage.logger("Container #{name.bold.yellow} is already running")
|
18
|
+
return
|
19
|
+
end
|
20
|
+
invoke("start #{name}", catch_errors: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def stop(name)
|
24
|
+
unless container_running?(name)
|
25
|
+
Dockage.logger("Container #{name.bold.yellow} is not running")
|
26
|
+
return
|
27
|
+
end
|
28
|
+
invoke("stop #{name}", catch_errors: true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy(name)
|
32
|
+
unless container_exists?(name)
|
33
|
+
Dockage.logger("Container #{name.bold.yellow} not found")
|
34
|
+
return
|
35
|
+
end
|
36
|
+
Dockage.logger("Destroying container #{name.bold.yellow}")
|
37
|
+
invoke("rm #{name}", catch_errors: false)
|
38
|
+
end
|
39
|
+
|
40
|
+
def provide(container)
|
41
|
+
raise SSHOptionsError unless container[:ssh]
|
42
|
+
unless container_running?(container[:name])
|
43
|
+
Dockage.error("Container #{container[:name].bold.yellow} is not running")
|
44
|
+
end
|
45
|
+
container[:provision].each do |provision|
|
46
|
+
SSH.execute(provision, container[:ssh])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def build
|
51
|
+
invoke('build', attach_std: true)
|
52
|
+
end
|
53
|
+
|
54
|
+
def ps(name = nil, all = false)
|
55
|
+
ps_output = invoke("ps --no-trunc #{all && '-a '}", attach_std: false).split(/\n/)
|
56
|
+
containers = Parse.parse_docker_ps(ps_output)
|
57
|
+
containers.reject! { |con| con[:name] != name } if name
|
58
|
+
containers
|
59
|
+
end
|
60
|
+
|
61
|
+
def up(container)
|
62
|
+
if container_running?(container[:name])
|
63
|
+
Dockage.logger("Container #{container[:name].bold} is already up. Nothing to do")
|
64
|
+
return
|
65
|
+
end
|
66
|
+
return start(container[:name]) if container_exists?(container[:name])
|
67
|
+
pull(container[:image]) if container[:keep_fresh]
|
68
|
+
run(container[:image], container)
|
69
|
+
end
|
70
|
+
|
71
|
+
def reload(container)
|
72
|
+
stop(container[:name]) if container_running?(container[:name])
|
73
|
+
destroy(container[:name]) if container_exists?(container[:name])
|
74
|
+
up(container)
|
75
|
+
end
|
76
|
+
|
77
|
+
def status(name = nil)
|
78
|
+
output = ''
|
79
|
+
|
80
|
+
containers = Dockage.settings[:containers]
|
81
|
+
containers = containers.select { |con| con[:name] == name } if name
|
82
|
+
|
83
|
+
active_containers = ps(name, true)
|
84
|
+
containers.each do |container|
|
85
|
+
output += "#{container[:name].to_s.bold.yellow} is "
|
86
|
+
docker_container = active_containers.select { |con| con[:name] == container[:name] }.first
|
87
|
+
if docker_container
|
88
|
+
output += docker_container[:running] ? 'running'.green : 'not running'.red
|
89
|
+
else
|
90
|
+
output += 'not exists'.red
|
91
|
+
end
|
92
|
+
output += "\n"
|
93
|
+
end
|
94
|
+
|
95
|
+
output
|
96
|
+
end
|
97
|
+
|
98
|
+
def version
|
99
|
+
invoke('version')
|
100
|
+
end
|
101
|
+
|
102
|
+
def shellinit
|
103
|
+
"export #{env}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def container_running?(name)
|
107
|
+
ps(name).any?
|
108
|
+
end
|
109
|
+
|
110
|
+
def container_exists?(name)
|
111
|
+
ps(name, true).any?
|
112
|
+
end
|
113
|
+
|
114
|
+
def run(image, opts = {})
|
115
|
+
command = "run" \
|
116
|
+
"#{opts[:detach] == false || ' -d'}" \
|
117
|
+
"#{opts[:links] && opts[:links].map { |link| " --link #{link}" }.join}" \
|
118
|
+
"#{opts[:volumes] && opts[:volumes].map { |volume| " -v #{volume}" }.join}" \
|
119
|
+
"#{opts[:ports] && opts[:ports].map { |port| " -p #{port}" }.join}" \
|
120
|
+
"#{opts[:name] && " --name #{opts[:name]}"}" \
|
121
|
+
" #{image}" \
|
122
|
+
"#{opts[:cmd] && " /bin/sh -c '#{opts[:cmd]}'"}"
|
123
|
+
invoke(command)
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def invoke(cmd, opts = {})
|
129
|
+
command = "#{@env} docker #{cmd}"
|
130
|
+
Dockage.verbose(command)
|
131
|
+
if opts[:attach_std]
|
132
|
+
output = sys_exec(command, opts[:catch_errors])
|
133
|
+
else
|
134
|
+
output = `#{command}`
|
135
|
+
end
|
136
|
+
Dockage.debug(output)
|
137
|
+
output
|
138
|
+
end
|
139
|
+
|
140
|
+
def sys_exec(cmd, catch_errors = true)
|
141
|
+
Open3.popen3(cmd.to_s) do |stdin, stdout, stderr|
|
142
|
+
@in, @out, @err = stdin, stdout.gets, stderr.gets
|
143
|
+
@in.close
|
144
|
+
Dockage.verbose(@out.strip) if @out && !@out.empty?
|
145
|
+
if @err && !@err.strip.empty?
|
146
|
+
puts @err.strip.red
|
147
|
+
@ruined = true
|
148
|
+
end
|
149
|
+
end
|
150
|
+
exit 1 if catch_errors && @ruined
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Dockage
|
4
|
+
class Settings
|
5
|
+
class << self
|
6
|
+
def load(config_path = 'dockage.yml')
|
7
|
+
raise DockageConfigNotFound unless File.exist? config_path
|
8
|
+
deep_symbolize_keys(YAML.load_file(config_path))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def deep_symbolize_keys(object)
|
14
|
+
case object
|
15
|
+
when Array
|
16
|
+
object.map{ |v| deep_symbolize_keys(v) }
|
17
|
+
when Hash
|
18
|
+
result = {}
|
19
|
+
object.each { |k,v| result[k.to_sym] = deep_symbolize_keys(v) }
|
20
|
+
result
|
21
|
+
else
|
22
|
+
object
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/dockage/ssh.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Dockage
|
2
|
+
class SSH
|
3
|
+
class << self
|
4
|
+
SSH_OPTS = %w( StrictHostKeyChecking=no UserKnownHostsFile=/dev/null )
|
5
|
+
|
6
|
+
def execute(provision, opts)
|
7
|
+
return Dockage.logger('Nothing to provide') unless provision
|
8
|
+
set_ssh_command(opts)
|
9
|
+
Dockage.logger("Provisioning #{ provision.map{ |k,v| "#{k.to_s.yellow}: #{v}" }.join }")
|
10
|
+
execute = "#{@command} #{provision[:inline]}" if provision[:inline]
|
11
|
+
if provision[:script]
|
12
|
+
Dockage.error("File #{provision[:script].bold} is not exist") unless File.exist?(provision[:script])
|
13
|
+
execute = "cat #{provision[:script]} | #{@command}"
|
14
|
+
end
|
15
|
+
Dockage.verbose(execute)
|
16
|
+
system(execute)
|
17
|
+
end
|
18
|
+
|
19
|
+
def connect(opts)
|
20
|
+
set_ssh_command(opts)
|
21
|
+
Dockage.debug(@command)
|
22
|
+
system(@command)
|
23
|
+
exit 0
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_ssh_command(opts)
|
27
|
+
raise SSHOptionsError if !opts[:login] || !opts[:host]
|
28
|
+
return if @command
|
29
|
+
@command = which_ssh
|
30
|
+
@command += SSH_OPTS.map { |opt| " -o #{opt}" }.join if SSH_OPTS.any?
|
31
|
+
@command += " -i #{opts[:identity_file]}" if opts[:identity_file]
|
32
|
+
@command += " #{opts[:login]}@#{opts[:host]}"
|
33
|
+
@command += " -p #{opts[:port]}" if opts[:port]
|
34
|
+
@command += " -q" unless Dockage.verbose_mode
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def which_ssh
|
40
|
+
Dockage.which('ssh')
|
41
|
+
end
|
42
|
+
|
43
|
+
def which_ssh_add
|
44
|
+
Dockage.which('ssh-add')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
docker_host: unix:///var/run/docker.sock
|
2
|
+
containers:
|
3
|
+
- name: postgres
|
4
|
+
image: postgres:latest
|
5
|
+
keep_fresh: false
|
6
|
+
ports:
|
7
|
+
- '2220:22'
|
8
|
+
volumes:
|
9
|
+
- /tmp/data/pg:/var/lib/postgres/data
|
10
|
+
ssh:
|
11
|
+
enabled: true
|
12
|
+
login: root
|
13
|
+
host: 127.0.0.1
|
14
|
+
port: 2220
|
15
|
+
provision:
|
16
|
+
- inline: 'whoami'
|
17
|
+
|
18
|
+
- name: hello
|
19
|
+
keep_fresh: true
|
20
|
+
image: debian:jessie
|
21
|
+
cmd: 'while true; do echo hello world; sleep 1; done'
|
data/lib/dockage.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'dockage/version'
|
3
|
+
require 'colorize'
|
4
|
+
|
5
|
+
module Dockage
|
6
|
+
autoload :Settings, 'dockage/settings'
|
7
|
+
autoload :Docker, 'dockage/docker'
|
8
|
+
autoload :SSH, 'dockage/ssh'
|
9
|
+
|
10
|
+
class DockageError < StandardError; end
|
11
|
+
class DockageConfigNotFound < DockageError; end
|
12
|
+
class DockageConfigExists < DockageError; end
|
13
|
+
class ProvideError < DockageError; end
|
14
|
+
class InstallError < DockageError; end
|
15
|
+
class InvalidOptionError < DockageError; end
|
16
|
+
class SSHOptionsError < DockageError; end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :debug_mode
|
20
|
+
attr_accessor :verbose_mode
|
21
|
+
attr_accessor :quiet_mode
|
22
|
+
attr_accessor :force_mode
|
23
|
+
|
24
|
+
def root
|
25
|
+
@root ||= Dir.pwd
|
26
|
+
end
|
27
|
+
|
28
|
+
def config_path
|
29
|
+
File.join(root, 'dockage.yml')
|
30
|
+
end
|
31
|
+
|
32
|
+
def settings
|
33
|
+
@settings ||= Settings.load(config_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_example_config
|
37
|
+
raise DockageConfigExists if File.exist? config_path
|
38
|
+
FileUtils.cp(File.expand_path('../dockage/templates/dockage.yml', __FILE__), config_path)
|
39
|
+
puts 'Created example config dockage.yml'
|
40
|
+
end
|
41
|
+
|
42
|
+
def which(executable)
|
43
|
+
if File.file?(executable) && File.executable?(executable)
|
44
|
+
executable
|
45
|
+
elsif ENV['PATH']
|
46
|
+
path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p|
|
47
|
+
File.executable?(File.join(p, executable))
|
48
|
+
end
|
49
|
+
path && File.expand_path(executable, path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def debug(string)
|
54
|
+
return unless string
|
55
|
+
puts string.magenta if Dockage.debug_mode
|
56
|
+
end
|
57
|
+
|
58
|
+
def verbose(string)
|
59
|
+
return unless string
|
60
|
+
puts string.blue if Dockage.verbose_mode
|
61
|
+
end
|
62
|
+
|
63
|
+
def logger(string)
|
64
|
+
return unless string
|
65
|
+
puts "> #{string}" unless Dockage.quiet_mode
|
66
|
+
end
|
67
|
+
|
68
|
+
def error(string = 'unknown error')
|
69
|
+
puts string.red unless Dockage.quiet_mode
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# rspec-expectations config goes here. You can use an alternate
|
19
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
|
+
# assertions if you prefer.
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
|
+
# and `failure_message` of custom matchers include text for helper methods
|
24
|
+
# defined using `chain`, e.g.:
|
25
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
26
|
+
# # => "be bigger than 2 and smaller than 4"
|
27
|
+
# ...rather than:
|
28
|
+
# # => "be bigger than 2"
|
29
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
34
|
+
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
38
|
+
mocks.verify_partial_doubles = true
|
39
|
+
end
|
40
|
+
|
41
|
+
# The settings below are suggested to provide a good initial experience
|
42
|
+
# with RSpec, but feel free to customize to your heart's content.
|
43
|
+
# # These two settings work together to allow you to limit a spec run
|
44
|
+
# # to individual examples or groups you care about by tagging them with
|
45
|
+
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
46
|
+
# # get run.
|
47
|
+
# config.filter_run :focus
|
48
|
+
# config.run_all_when_everything_filtered = true
|
49
|
+
#
|
50
|
+
# # Limits the available syntax to the non-monkey patched syntax that is recommended.
|
51
|
+
# # For more details, see:
|
52
|
+
# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
53
|
+
# # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
54
|
+
# # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
55
|
+
# config.disable_monkey_patching!
|
56
|
+
#
|
57
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
58
|
+
# # be too noisy due to issues in dependencies.
|
59
|
+
# config.warnings = true
|
60
|
+
#
|
61
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
62
|
+
# # file, and it's useful to allow more verbose output when running an
|
63
|
+
# # individual spec file.
|
64
|
+
# if config.files_to_run.one?
|
65
|
+
# # Use the documentation formatter for detailed output,
|
66
|
+
# # unless a formatter has already been configured
|
67
|
+
# # (e.g. via a command-line flag).
|
68
|
+
# config.default_formatter = 'doc'
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# # Print the 10 slowest examples and example groups at the
|
72
|
+
# # end of the spec run, to help surface which specs are running
|
73
|
+
# # particularly slow.
|
74
|
+
# config.profile_examples = 10
|
75
|
+
#
|
76
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
77
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
78
|
+
# # the seed, which is printed after each run.
|
79
|
+
# # --seed 1234
|
80
|
+
# config.order = :random
|
81
|
+
#
|
82
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
83
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
84
|
+
# # test failures related to randomization by passing the same `--seed` value
|
85
|
+
# # as the one that triggered the failure.
|
86
|
+
# Kernel.srand config.seed
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dockage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Besedin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Gem to manage multiple docker containers at once
|
84
|
+
email:
|
85
|
+
- kr3ssh@gmail.com
|
86
|
+
executables:
|
87
|
+
- dockage
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.md
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/dockage
|
99
|
+
- dockage.gemspec
|
100
|
+
- lib/dockage.rb
|
101
|
+
- lib/dockage/cli.rb
|
102
|
+
- lib/dockage/docker.rb
|
103
|
+
- lib/dockage/docker/parse.rb
|
104
|
+
- lib/dockage/docker/shell.rb
|
105
|
+
- lib/dockage/settings.rb
|
106
|
+
- lib/dockage/ssh.rb
|
107
|
+
- lib/dockage/templates/dockage.yml
|
108
|
+
- lib/dockage/version.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
homepage: http://github.com/kr3ssh/dockage
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '1.9'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.2.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Control multiple docker containers with ease
|
134
|
+
test_files:
|
135
|
+
- spec/spec_helper.rb
|