nutkins 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a50484d569a045dee261e24b487378e573c7cfc
4
- data.tar.gz: 6c0db6d0f5501ae03af069158077e6c03faa858f
3
+ metadata.gz: e39c7d9fb6cf2c1c75ea934110db18766e507ab8
4
+ data.tar.gz: b8e2dbfa8a16cd68b564db04bd024114cf4c042a
5
5
  SHA512:
6
- metadata.gz: a4e534198a34b3e27dc6a1858449feda482c6d4fa7a211b47595c482c1c3167df7779e55bdb7d831f2b4a198f0ff29b3c9177f98a001ea8743c923672a391b85
7
- data.tar.gz: 2e7aca7855fbb48911aeec5b77f944c355b6445da42c6caa5070a7c4e42d8ff544ed53c9ea2e153a928821477b0e98971ed57502250ff75c65ad64eed0c10a2f
6
+ metadata.gz: ec3ae892c0dd327696cee6e7254a1cfb3e50bf2a4e3348b012184fc4a1ff61adba402abe451e9b21a15c0bf2f54d49e85cef11ff9706673ce56fcc115ce0fde8
7
+ data.tar.gz: c1db55842f25e02cb6163218e6e74d881ab8364f0bbd13763f876cde5c533c9115f7f83fd578ec8a08e400e5e9cac483fa199fef47f11c95af7d616be99e87e1
data/bin/nutkins CHANGED
@@ -58,12 +58,7 @@ module Nutkins::Command
58
58
 
59
59
  case command
60
60
  when 'build'
61
- names = config.names
62
- if names.empty?
63
- nutkins.build
64
- else
65
- config.names.each &nutkins.method(:build)
66
- end
61
+ config.names.each &nutkins.method(:build)
67
62
  when 'create'
68
63
  config.names.each do |name|
69
64
  nutkins.create name, preserve: config.preserve
@@ -1,3 +1,3 @@
1
1
  module Nutkins
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/nutkins.rb CHANGED
@@ -28,15 +28,11 @@ module Nutkins
28
28
  end
29
29
  end
30
30
 
31
- def build img_name = '.'
31
+ def build img_name
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
-
36
- if img_name == '.'
37
- img_name = cfg["image"]
38
- raise "nutkin.yaml requires image entry for `build .'" unless img_name
39
- end
35
+ tag = get_tag cfg
40
36
 
41
37
  build_cfg = cfg["build"]
42
38
  if build_cfg
@@ -45,7 +41,6 @@ module Nutkins
45
41
  Download.download_resources img_dir, resources if resources
46
42
  end
47
43
 
48
- tag = get_tag img_name
49
44
  prev_image_id = Docker.image_id_for_tag tag
50
45
 
51
46
  if run_docker "build", "-t", tag, img_dir
@@ -80,7 +75,7 @@ module Nutkins
80
75
  end
81
76
  end
82
77
 
83
- tag = get_tag img_name
78
+ tag = get_tag cfg
84
79
  prev_container_id = Docker.container_id_for_tag tag unless preserve
85
80
  puts "creating new docker image"
86
81
  unless run_docker "create", "-it", *flags, tag, *docker_args
@@ -100,15 +95,20 @@ module Nutkins
100
95
 
101
96
  def run img_name, reuse: false, shell: false
102
97
  cfg = get_image_config img_name
103
- tag = get_tag img_name
98
+ tag = get_tag cfg
104
99
  create_args = []
105
100
  if shell
106
101
  raise '--shell and --reuse arguments are incompatible' if reuse
107
102
 
108
103
  # TODO: test for smell-baron
109
104
  create_args = JSON.parse(`docker inspect #{tag}`)[0]["Config"]["Cmd"]
105
+
106
+ kill_everything = create_args[0] == '-a'
107
+ create_args.shift if kill_everything
108
+
110
109
  create_args.unshift '/bin/bash', '---'
111
110
  create_args.unshift '-f' unless create_args[0] == '-f'
111
+ create_args.unshift '-a' if kill_everything
112
112
  # TODO: provide version that doesn't require smell-baron
113
113
  end
114
114
 
@@ -123,7 +123,12 @@ module Nutkins
123
123
  end
124
124
 
125
125
  def delete img_name
126
- puts "TODO: delete #{img_name}"
126
+ cfg = get_image_config img_name
127
+ tag = get_tag cfg
128
+ container_id = Docker.container_id_for_tag tag
129
+ raise "no container to delete" if container_id.nil?
130
+ puts "deleting container #{container_id}"
131
+ run_docker "rm", container_id
127
132
  end
128
133
 
129
134
  def delete_all
@@ -147,9 +152,9 @@ module Nutkins
147
152
  end
148
153
 
149
154
  def extract_secrets img_names
150
- with_current = img_names.empty?
151
- img_names = get_image_names(img_names)
152
- img_names.push '.' if with_current
155
+ if img_names.empty?
156
+ img_names = get_all_img_names(img_names).push '.'
157
+ end
153
158
 
154
159
  img_names.each do |img_name|
155
160
  get_secrets(img_name).each do |secret|
@@ -175,7 +180,7 @@ module Nutkins
175
180
  def get_image_config path
176
181
  img_cfg_path = File.join get_project_dir(path), IMG_CONFIG_FILE_NAME
177
182
  img_cfg = File.exists?(img_cfg_path) ? YAML.load_file(img_cfg_path) : {}
178
- @repository = img_cfg['repository'] || @config.repository
183
+ img_cfg["image"] ||= path if path != '.'
179
184
  img_cfg
180
185
  end
181
186
 
@@ -183,18 +188,21 @@ module Nutkins
183
188
  path == '.' ? @project_root : File.join(@project_root, path)
184
189
  end
185
190
 
186
- def get_tag tag
187
- raise "command requires `repository' entry in nutkins.yaml or nutkin.yaml" if @repository.nil?
188
- @repository + '/' + tag
191
+ def get_tag img_cfg
192
+ unless img_cfg.has_key? "image"
193
+ raise "nutkins.yaml should contain `image' entry for this command"
194
+ end
195
+
196
+ repository = img_cfg['repository'] || @config.repository
197
+ if repository.nil?
198
+ raise "nutkins.yaml or nutkin.yaml should contain `repository' entry for this command"
199
+ end
200
+ repository + '/' + img_cfg['image']
189
201
  end
190
202
 
191
- def get_image_names img_names
192
- if img_names.empty?
193
- Dir.glob("#{@project_root}/*/Dockerfile").map do |path|
194
- File.basename File.dirname(path)
195
- end
196
- else
197
- img_names
203
+ def get_all_img_names img_names
204
+ Dir.glob("#{@project_root}/*/Dockerfile").map do |path|
205
+ File.basename File.dirname(path)
198
206
  end
199
207
  end
200
208
 
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.1.5
4
+ version: 0.1.6
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-06-30 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler