nutkins 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -5
- data/bin/nutkins +7 -0
- data/lib/nutkins/docker.rb +25 -5
- data/lib/nutkins/version.rb +1 -1
- data/lib/nutkins.rb +45 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7180a966807e27688ba070e225f11faad2f46dbc
|
4
|
+
data.tar.gz: 4a7427067089d88a6a82d576ae7089293fd18cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f32b2b6fd85b135b5c492450277a354375b1a64cb6128af26223fb1e3715cd61f066892837048a54aef03b4292f5004f2c6653e2acf5e27a575aa54a45c3c0c
|
7
|
+
data.tar.gz: 39f709c64bfe4f7ef19f6286c21562b1fbe4ef5aec90f65f2ba64557fb287c68ccaf12fc7cdea6db3a61ec4e6642b54e8cbeb53bf57046c04d92919d3000f660
|
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
[![build status](https://circleci.com/gh/ohjames/nutkins.png)](https://circleci.com/gh/ohjames/nutkins)
|
4
4
|
|
5
|
-
Nutkins is a tool to
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* A wrapper around `fleetctl` to make upgrading services easy.
|
9
|
-
* Extra configuation in `nutkins.yaml` and `nutkin.yaml` to add extra functionality missing from docker.
|
5
|
+
Nutkins is a tool to help build and test multiple docker containers configured via etcd and confd. You can:
|
6
|
+
* Describe test volumes and etcd variables using yaml.
|
7
|
+
* Easily rebuild and test containers with a few simple commands.
|
data/bin/nutkins
CHANGED
@@ -42,6 +42,9 @@ module Nutkins::Command
|
|
42
42
|
op.subcommand 'build-secret,B path', 'build secret files/volumes'
|
43
43
|
op.subcommand 'extract-secrets,X [*names]', 'extract secret files/volumes'
|
44
44
|
|
45
|
+
op.subcommand 'start-etcd', 'start container running etcd'
|
46
|
+
op.subcommand 'stop-etcd', 'stop container running etcd'
|
47
|
+
|
45
48
|
parsed_cfg = op.parse(args).to_h
|
46
49
|
|
47
50
|
global_config = OpenStruct.new parsed_cfg[:config]
|
@@ -75,6 +78,10 @@ module Nutkins::Command
|
|
75
78
|
nutkins.build_secret config.path
|
76
79
|
when 'extract-secrets'
|
77
80
|
nutkins.extract_secrets config.names
|
81
|
+
when 'start-etcd'
|
82
|
+
nutkins.start_etcd_container
|
83
|
+
when 'stop-etcd'
|
84
|
+
nutkins.stop_etcd_container
|
78
85
|
end
|
79
86
|
rescue RuntimeError => e
|
80
87
|
puts e.to_s
|
data/lib/nutkins/docker.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
module Nutkins::Docker
|
2
4
|
def self.image_id_for_tag tag
|
3
|
-
|
4
|
-
`docker images`.each_line do |line|
|
5
|
-
return line.split(' ')[2] if line =~ regex
|
6
|
-
end
|
7
|
-
nil
|
5
|
+
self.run_get_stdout 'inspect', '--format="{{.Id}}"', tag
|
8
6
|
end
|
9
7
|
|
10
8
|
def self.container_id_for_tag tag
|
@@ -14,4 +12,26 @@ module Nutkins::Docker
|
|
14
12
|
end
|
15
13
|
nil
|
16
14
|
end
|
15
|
+
|
16
|
+
def self.container_id_for_name name
|
17
|
+
self.run_get_stdout 'inspect', '--format="{{.Id}}"', name
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.run_get_stdout *args
|
21
|
+
stdout_str, stderr_str, status = Open3.capture3 'docker', *args
|
22
|
+
status.success? && stdout_str.chomp
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.run *args, stdout: false, stderr: true
|
26
|
+
stdout_backup = ! stdout && $stdout.clone
|
27
|
+
stderr_backup = ! stderr && $stderr.clone
|
28
|
+
$stdout.reopen File.new('/dev/null', 'w') unless stdout
|
29
|
+
$stderr.reopen File.new('/dev/null', 'w') unless stderr
|
30
|
+
begin
|
31
|
+
system 'docker', *args
|
32
|
+
ensure
|
33
|
+
$stdout.reopen stdout_backup unless stdout
|
34
|
+
$stderr.reopen stderr_backup unless stderr
|
35
|
+
end
|
36
|
+
end
|
17
37
|
end
|
data/lib/nutkins/version.rb
CHANGED
data/lib/nutkins.rb
CHANGED
@@ -32,7 +32,7 @@ module Nutkins
|
|
32
32
|
cfg = get_image_config img_name
|
33
33
|
img_dir = get_project_dir img_name
|
34
34
|
raise "directory `#{img_dir}' does not exist" unless Dir.exists? img_dir
|
35
|
-
tag =
|
35
|
+
tag = cfg['tag']
|
36
36
|
|
37
37
|
build_cfg = cfg["build"]
|
38
38
|
if build_cfg
|
@@ -43,11 +43,11 @@ module Nutkins
|
|
43
43
|
|
44
44
|
prev_image_id = Docker.image_id_for_tag tag
|
45
45
|
|
46
|
-
if
|
46
|
+
if Docker.run 'build', '-t', cfg['latest_tag'], '-t', tag, img_dir, stdout: true
|
47
47
|
image_id = Docker.image_id_for_tag tag
|
48
48
|
if not prev_image_id.nil? and image_id != prev_image_id
|
49
49
|
puts "deleting previous image #{prev_image_id}"
|
50
|
-
|
50
|
+
Docker.run "rmi", prev_image_id
|
51
51
|
end
|
52
52
|
else
|
53
53
|
raise "issue building docker image for #{img_name}"
|
@@ -75,10 +75,10 @@ module Nutkins
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
tag =
|
78
|
+
tag = cfg['tag']
|
79
79
|
prev_container_id = Docker.container_id_for_tag tag unless preserve
|
80
80
|
puts "creating new docker image"
|
81
|
-
unless
|
81
|
+
unless Docker.run "create", "-it", *flags, tag, *docker_args
|
82
82
|
raise "failed to create `#{img_name}' container"
|
83
83
|
end
|
84
84
|
|
@@ -86,7 +86,7 @@ module Nutkins
|
|
86
86
|
container_id = Docker.container_id_for_tag tag
|
87
87
|
if not prev_container_id.nil? and container_id != prev_container_id
|
88
88
|
puts "deleting previous container #{prev_container_id}"
|
89
|
-
|
89
|
+
Docker.run "rm", prev_container_id
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -95,7 +95,7 @@ module Nutkins
|
|
95
95
|
|
96
96
|
def run img_name, reuse: false, shell: false
|
97
97
|
cfg = get_image_config img_name
|
98
|
-
tag =
|
98
|
+
tag = cfg['tag']
|
99
99
|
create_args = []
|
100
100
|
if shell
|
101
101
|
raise '--shell and --reuse arguments are incompatible' if reuse
|
@@ -124,11 +124,12 @@ module Nutkins
|
|
124
124
|
|
125
125
|
def delete img_name
|
126
126
|
cfg = get_image_config img_name
|
127
|
-
tag =
|
127
|
+
tag = cfg['tag']
|
128
128
|
container_id = Docker.container_id_for_tag tag
|
129
129
|
raise "no container to delete" if container_id.nil?
|
130
130
|
puts "deleting container #{container_id}"
|
131
|
-
|
131
|
+
# TODO: also delete :latest
|
132
|
+
Docker.run "rm", container_id
|
132
133
|
end
|
133
134
|
|
134
135
|
def delete_all
|
@@ -176,11 +177,46 @@ module Nutkins
|
|
176
177
|
puts "TODO: exec #{img_name}: #{cmd.join ' '}"
|
177
178
|
end
|
178
179
|
|
180
|
+
def start_etcd_container
|
181
|
+
name = get_etcd_container_name
|
182
|
+
return unless name
|
183
|
+
existing = Docker.container_id_for_name name
|
184
|
+
unless existing
|
185
|
+
Docker.run 'create', '--name', name, '-p', '4001:4001', 'microbox/etcd:latest', '-name', name
|
186
|
+
end
|
187
|
+
|
188
|
+
if Docker.run 'start', name
|
189
|
+
puts 'started etcd container'
|
190
|
+
else
|
191
|
+
puts 'failed to start etcd container'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def stop_etcd_container
|
196
|
+
name = get_etcd_container_name
|
197
|
+
return unless name
|
198
|
+
if Docker.run 'stop', name
|
199
|
+
puts 'stopped etcd container'
|
200
|
+
else
|
201
|
+
puts 'failed to stop etcd container'
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
179
205
|
private
|
206
|
+
def get_etcd_container_name
|
207
|
+
repository = @config.repository
|
208
|
+
repository && "nutkins-etcd-#{repository}"
|
209
|
+
end
|
210
|
+
|
180
211
|
def get_image_config path
|
181
212
|
img_cfg_path = File.join get_project_dir(path), IMG_CONFIG_FILE_NAME
|
182
213
|
img_cfg = File.exists?(img_cfg_path) ? YAML.load_file(img_cfg_path) : {}
|
183
214
|
img_cfg["image"] ||= path if path != '.'
|
215
|
+
img_cfg["version"] ||= @config.version if @config.version
|
216
|
+
img_cfg['version'] = img_cfg['version'].to_s
|
217
|
+
raise 'missing mandatory version field' unless img_cfg.has_key? 'version'
|
218
|
+
img_cfg['latest_tag'] = get_tag img_cfg
|
219
|
+
img_cfg['tag'] = img_cfg['latest_tag'] + ':' + img_cfg['version']
|
184
220
|
img_cfg
|
185
221
|
end
|
186
222
|
|
@@ -211,9 +247,5 @@ module Nutkins
|
|
211
247
|
img_dir = get_project_dir img_name
|
212
248
|
Dir.glob("#{img_dir}/{volumes,secrets}/*.gpg")
|
213
249
|
end
|
214
|
-
|
215
|
-
def run_docker *args
|
216
|
-
system 'docker', *args
|
217
|
-
end
|
218
250
|
end
|
219
251
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nutkins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Pike
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|