kitchen-docker_cli 0.8.1 → 0.9.0

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: 5c9c4456fdccbcadfaf197bfff4bae971e77223a
4
- data.tar.gz: 1b87bccb3bbacd66150b6a0e0422777bad742af3
3
+ metadata.gz: 86d1304084493a93678033f12fb9c16782cb72d4
4
+ data.tar.gz: 225c65f8e05d2eea4ae1376d4a0dd8028afa52dc
5
5
  SHA512:
6
- metadata.gz: 98f996d40938f78ccd4698204874f0f6781764b850ed5919a5e5ea53e9d6016494abe17aa9ee7ab47de5c8c4e57158da63963e41d9b1e5c68df985c6d9417947
7
- data.tar.gz: 02c9683adb5a47fee7463391d45edc7200e2900852764dc44292aab47be4689a349a8feba93e93fe320cdc23757ef006832f09e246c82486dd31a7c10e3fb372
6
+ metadata.gz: a78202c0d1dc6344ac7c79aac2cd11ed7694ced1e475dc687a4dd4af1f238341179a0b24117ecb7ed22ac062928c6f20a5d20ed8685541348147d481ebd7957c
7
+ data.tar.gz: b97a94d845e713af5f7336b5a79cbd1b16919f17cc48f00c1c978e5bea59fdb92e6f5c1db23dd89fc7e45a15bfd0ffdbbce243ede8bebb377cb3f174cee422ef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.9.0
2
+
3
+ * Change custom Dockerfile to ERB template [#11][] [#12][]
4
+
1
5
  ## 0.8.1
2
6
 
3
7
  * Support test-kitchen `1.4.0`
@@ -51,5 +55,7 @@
51
55
  <!--- The following link definition list is generated by PimpMyChangelog --->
52
56
  [#2]: https://github.com/marcy-terui/kitchen-docker_cli/issues/2
53
57
  [#4]: https://github.com/marcy-terui/kitchen-docker_cli/issues/4
58
+ [#11]: https://github.com/marcy-terui/kitchen-docker_cli/issues/11
59
+ [#12]: https://github.com/marcy-terui/kitchen-docker_cli/issues/12
54
60
  [@grubernaut]: https://github.com/grubernaut
55
- [@hd-deman]: https://github.com/hd-deman
61
+ [@hd-deman]: https://github.com/hd-deman
data/README.md CHANGED
@@ -257,7 +257,8 @@ Examples:
257
257
 
258
258
  ### dockerfile
259
259
 
260
- Create test image using a supplied dockerfile, instead of the default dockerfile created.
260
+ Create test image using a supplied Dockerfile, instead of the default Dockerfile created.
261
+ And it can be written as ERB template.
261
262
  For best results, please:
262
263
  - Ensure Package Repositories are updated
263
264
  - Ensure Dockerfile installs sudo, curl, and tar
@@ -267,6 +268,44 @@ For best results, please:
267
268
  dockerfile: my/dockerfile
268
269
  ```
269
270
 
271
+ ### dockerfile_vars
272
+ Template variables for the custom Dockerfile.
273
+
274
+ Example:
275
+
276
+ - .kitchen.yml
277
+
278
+ ```yml
279
+ driver:
280
+ image: marcy/hoge
281
+ dockerfile: dockerfile.erb
282
+ dockerfile_vars:
283
+ envs:
284
+ LANG: ja_JP.UTF-8
285
+ cmds:
286
+ - yum -y install httpd
287
+ ```
288
+
289
+ - dockerfile.erb
290
+
291
+ ```erb
292
+ FROM <%= config[:image] %>
293
+ <% @envs.each do |k,v| %>
294
+ ENV <%= k %> <%= v %>
295
+ <% end %>
296
+ <% @cmds.each do |c| %>
297
+ RUN <%= c %>
298
+ <% end %>
299
+ ```
300
+
301
+ - Result
302
+
303
+ ```
304
+ FROM marcy/hoge
305
+ ENV LANG ja_JP.UTF-8
306
+ RUN yum -y install httpd
307
+ ```
308
+
270
309
  ### memory_limit
271
310
 
272
311
  Constrain the memory available.
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Masashi Terui (<marcy9114@gmail.com>)
4
+ #
5
+ # Copyright (C) 2015, Masashi Terui
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'erb'
20
+
21
+ module Kitchen
22
+
23
+ module DockerCli
24
+
25
+ class DockerfileTemplate
26
+ def initialize(vars={}, config={})
27
+ vars.each do |k, v|
28
+ instance_variable_set("@#{k.to_s}", v)
29
+ end
30
+ self.class.class_eval <<-EOF
31
+ def config
32
+ return #{config.to_s}
33
+ end
34
+ EOF
35
+ end
36
+
37
+ def result
38
+ ERB.new(IO.read(File.expand_path(config[:dockerfile]))).result(binding)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -17,6 +17,7 @@
17
17
  # limitations under the License.
18
18
 
19
19
  require 'kitchen'
20
+ require 'kitchen/docker_cli/dockerfile_template'
20
21
 
21
22
  module Kitchen
22
23
 
@@ -121,7 +122,10 @@ module Kitchen
121
122
 
122
123
  def docker_file
123
124
  if config[:dockerfile]
124
- file = IO.read(File.expand_path(config[:dockerfile]))
125
+ file = ::Kitchen::DockerCli::DockerfileTemplate.new(
126
+ config[:dockerfile_vars],
127
+ config.to_hash
128
+ ).result
125
129
  else
126
130
  file = ["FROM #{config[:image]}"]
127
131
  case config[:platform]
@@ -134,8 +138,8 @@ module Kitchen
134
138
  else
135
139
  # TODO: Support other distribution
136
140
  end
137
- Array(config[:run_command]).each { |cmd| file << "RUN #{cmd}" }
138
141
  Array(config[:environment]).each { |env, value| file << "ENV #{env}=#{value}" }
142
+ Array(config[:run_command]).each { |cmd| file << "RUN #{cmd}" }
139
143
  file.join("\n")
140
144
  end
141
145
  end
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for DockerCli Kitchen driver
24
- DOCKER_CLI_VERSION = '0.8.1'
24
+ DOCKER_CLI_VERSION = '0.9.0'
25
25
  end
26
26
  end
@@ -210,13 +210,29 @@ describe Kitchen::Driver::DockerCli, "docker_file" do
210
210
  }
211
211
  }
212
212
  example do
213
- ret = "FROM ubuntu/12.04\n"
214
213
  ret = "FROM ubuntu/12.04\n"
215
214
  ret << "RUN apt-get update\n"
216
215
  ret << "RUN apt-get -y install sudo curl tar\n"
216
+ ret << "ENV test=hoge\n"
217
217
  ret << "RUN test\n"
218
- ret << "RUN test2\n"
219
- ret << "ENV test=hoge"
218
+ ret << "RUN test2"
219
+ expect(@docker_cli.send(:docker_file)).to eq ret
220
+ end
221
+ end
222
+ context 'dockerfile template' do
223
+ let(:config) {
224
+ {
225
+ image: "ubuntu/12.04",
226
+ platform: "ubuntu",
227
+ dockerfile: File.join(File.dirname(__FILE__), 'dockerfile.erb'),
228
+ dockerfile_vars: {"LANG" => "ja_JP.UTF-8"}
229
+ }
230
+ }
231
+ example do
232
+ ret = <<-EOH
233
+ FROM ubuntu/12.04
234
+ ENV LANG ja_JP.UTF-8
235
+ EOH
220
236
  expect(@docker_cli.send(:docker_file)).to eq ret
221
237
  end
222
238
  end
@@ -0,0 +1,2 @@
1
+ FROM <%= config[:image] %>
2
+ ENV LANG <%= @LANG %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-docker_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masashi Terui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-07 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -121,10 +121,12 @@ files:
121
121
  - integration-test/test/integration/default/serverspec/default_spec.rb
122
122
  - integration-test/test/integration/default/serverspec/spec_helper.rb
123
123
  - kitchen-docker_cli.gemspec
124
+ - lib/kitchen/docker_cli/dockerfile_template.rb
124
125
  - lib/kitchen/driver/docker_cli.rb
125
126
  - lib/kitchen/driver/docker_cli_version.rb
126
127
  - lib/kitchen/transport/docker_cli.rb
127
128
  - spec/kitchen/driver/docker_cli_spec.rb
129
+ - spec/kitchen/driver/dockerfile.erb
128
130
  - spec/spec_helper.rb
129
131
  homepage: https://github.com/marcy-terui/kitchen-docker_cli
130
132
  licenses:
@@ -152,4 +154,5 @@ specification_version: 4
152
154
  summary: A Test Kitchen Driver for Docker native CLI
153
155
  test_files:
154
156
  - spec/kitchen/driver/docker_cli_spec.rb
157
+ - spec/kitchen/driver/dockerfile.erb
155
158
  - spec/spec_helper.rb