puppet_docker_tools 0.1.3 → 0.1.4

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: 279a8c6d6a95b7d1c5f3f0dc4c045f2b67e363fd
4
- data.tar.gz: fa7be0251b3e84ae7fe7be4942c795a578f116e9
3
+ metadata.gz: 83418018be00481fd020d44eb91dc3e91cbe64d9
4
+ data.tar.gz: 981bd7c153e5cfec42bf8f97bc6e791278d76dd8
5
5
  SHA512:
6
- metadata.gz: d1156f61257a15d2bb792ab555d146e6041d0782d072a2467a1766174562f9a10af9486d2b9d82f350ae45f18053467937cfa444664c70ebc0cfaec03c3d51b6
7
- data.tar.gz: 5f2e135989bc479afca3e1116c45fff26cb6a43e21c2eacc904a1adf454ae627fb6e67e61d83a248d74fbea348c305f8933e090a2115e14edf2bfe21847629af
6
+ metadata.gz: 27d23f46ffe35d28e41e5fe9c66493d35eadcfde6adfc97b55ad01159f517b6052e769a99f3da9428b0405a5b533d972856160a5bb55c26902d2017eae594d26
7
+ data.tar.gz: 18f9ec6d818748ec65ebb58142b9b65832259d679211f8d2a0a0761548b73be7e9c903f5a40a92945cfde5c8f5402e5eb56e4e2f04c99041bf2cc228c4a603e4
data/README.md CHANGED
@@ -15,11 +15,11 @@ $ puppet-docker help
15
15
  Utilities for building and releasing Puppet docker images.
16
16
 
17
17
  Usage:
18
- puppet-docker build [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>] [--no-cache] [--version=<version] [--build-arg=<buildarg> ...]
18
+ puppet-docker build [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>] [--no-cache] [--version=<version] [--build-arg=<buildarg> ...] [--no-latest]
19
19
  puppet-docker lint [DIRECTORY] [--dockerfile=<dockerfile>]
20
20
  puppet-docker local-lint [DIRECTORY] [--dockerfile=<dockerfile>]
21
21
  puppet-docker pull [IMAGE] [--repository=<repo>]
22
- puppet-docker push [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>]
22
+ puppet-docker push [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>] [--no-latest]
23
23
  puppet-docker rev-labels [DIRECTORY] [--dockerfile=<dockerfile>] [--namespace=<namespace>]
24
24
  puppet-docker spec [DIRECTORY]
25
25
  puppet-docker test [DIRECTORY] [--dockerfile=<dockerfile>]
@@ -40,6 +40,8 @@ Options:
40
40
  --version=<version> Version to build. This field will be used to determine the label and will be passed as the version build arg.
41
41
  **NOTE** `--build-arg version='<version>'` overrides `--version <version>`
42
42
  --build-arg=<buildarg> Build arg to pass to container build, can be passed multiple times.
43
+ --no-latest Do not include the 'latest' tag when building and shipping images. By default, the 'latest' tag is built and
44
+ shipped with the versioned tag.
43
45
  ```
44
46
 
45
47
  ### `puppet-docker build`
@@ -7,11 +7,11 @@ doc = <<DOC
7
7
  Utilities for building and releasing Puppet docker images.
8
8
 
9
9
  Usage:
10
- puppet-docker build [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>] [--no-cache] [--version=<version] [--build-arg=<buildarg> ...]
10
+ puppet-docker build [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>] [--no-cache] [--version=<version] [--build-arg=<buildarg> ...] [--no-latest]
11
11
  puppet-docker lint [DIRECTORY] [--dockerfile=<dockerfile>]
12
12
  puppet-docker local-lint [DIRECTORY] [--dockerfile=<dockerfile>]
13
13
  puppet-docker pull [IMAGE] [--repository=<repo>]
14
- puppet-docker push [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>]
14
+ puppet-docker push [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>] [--no-latest]
15
15
  puppet-docker rev-labels [DIRECTORY] [--dockerfile=<dockerfile>] [--namespace=<namespace>]
16
16
  puppet-docker spec [DIRECTORY]
17
17
  puppet-docker test [DIRECTORY] [--dockerfile=<dockerfile>]
@@ -32,6 +32,8 @@ Options:
32
32
  --version=<version> Version to build. This field will be used to determine the label and will be passed as the version build arg.
33
33
  **NOTE** `--build-arg version='<version>'` overrides `--version <version>`
34
34
  --build-arg=<buildarg> Build arg to pass to container build, can be passed multiple times.
35
+ --no-latest Do not include the 'latest' tag when building and shipping images. By default, the 'latest' tag is built and
36
+ shipped with the versioned tag.
35
37
  DOC
36
38
 
37
39
  begin
@@ -49,6 +51,7 @@ defaults = {
49
51
  '--dockerfile' => 'Dockerfile',
50
52
  '--version' => nil,
51
53
  '--build-arg' => [],
54
+ '--no-latest' => false,
52
55
  }
53
56
 
54
57
  options.merge!(defaults) do |key, option, default|
@@ -73,14 +76,19 @@ begin
73
76
  else
74
77
  command_runner = PuppetDockerTools::Runner.new(directory: options['DIRECTORY'], repository: options['--repository'], namespace: options['--namespace'], dockerfile: options['--dockerfile'])
75
78
 
79
+ latest = true
80
+ if options['--no-latest']
81
+ latest = false
82
+ end
83
+
76
84
  if options['build']
77
- command_runner.build(no_cache: options['--no-cache'], version: options['--version'], build_args: options['--build-arg'])
85
+ command_runner.build(no_cache: options['--no-cache'], version: options['--version'], build_args: options['--build-arg'], latest: latest)
78
86
  elsif options['lint']
79
87
  command_runner.lint
80
88
  elsif options['local-lint']
81
89
  command_runner.local_lint
82
90
  elsif options['push']
83
- command_runner.push
91
+ command_runner.push(latest: latest)
84
92
  elsif options['rev-labels']
85
93
  command_runner.rev_labels
86
94
  elsif options['spec']
@@ -29,7 +29,9 @@ class PuppetDockerTools
29
29
  # @param build_args Pass arbitrary buildargs to the container build.
30
30
  # Expected to be an array of strings, each string formatted like
31
31
  # 'arg=value'.
32
- def build(no_cache: false, version: nil, build_args: [])
32
+ # @param latest Whether or not to build the latest tag along with the
33
+ # versioned image build.
34
+ def build(no_cache: false, version: nil, build_args: [], latest: true)
33
35
  image_name = File.basename(directory)
34
36
  build_args_hash = {
35
37
  'vcs_ref' => PuppetDockerTools::Utilities.current_git_sha(directory),
@@ -47,6 +49,8 @@ class PuppetDockerTools
47
49
  build_args_hash.merge!(PuppetDockerTools::Utilities.parse_build_args(Array(build_args)))
48
50
  end
49
51
 
52
+ build_args_hash = PuppetDockerTools::Utilities.filter_build_args(build_args: build_args_hash, dockerfile: "#{directory}/#{dockerfile}")
53
+
50
54
  # This variable is meant to be used for building the non-latest tagged build
51
55
  # If the version was set via `version` or `build_args`, use that. If not,
52
56
  # use `get_value_from_env` to parse that value from the dockerfile.
@@ -58,17 +62,22 @@ class PuppetDockerTools
58
62
  version = build_args_hash['version'] || PuppetDockerTools::Utilities.get_value_from_env('version', namespace: namespace, directory: directory, dockerfile: dockerfile)
59
63
 
60
64
  path = "#{repository}/#{image_name}"
61
- puts "Building #{path}:latest"
62
65
 
63
- # 't' in the build_options sets the tag for the image we're building
64
- build_options = { 't' => "#{path}:latest", 'dockerfile' => dockerfile, 'buildargs' => "#{build_args_hash.to_json}"}
66
+ build_options = {'dockerfile' => dockerfile, 'buildargs' => "#{build_args_hash.to_json}"}
65
67
 
66
68
  if no_cache
67
69
  puts "Ignoring cache for #{path}"
68
70
  build_options['nocache'] = true
69
71
  end
70
72
 
71
- Docker::Image.build_from_dir(directory, build_options)
73
+ if latest
74
+ puts "Building #{path}:latest"
75
+
76
+ # 't' in the build_options sets the tag for the image we're building
77
+ build_options['t'] = "#{path}:latest"
78
+
79
+ Docker::Image.build_from_dir(directory, build_options)
80
+ end
72
81
 
73
82
  if version
74
83
  puts "Building #{path}:#{version}"
@@ -107,12 +116,14 @@ class PuppetDockerTools
107
116
 
108
117
  # Push an image to hub.docker.com
109
118
  #
110
- def push
119
+ # @param latest Whether or not to push the latest tag along with the
120
+ # versioned image build.
121
+ def push(latest: true)
111
122
  image_name = File.basename(directory)
112
123
  path = "#{repository}/#{image_name}"
113
124
  version = PuppetDockerTools::Utilities.get_value_from_label(path, value: 'version', namespace: namespace)
114
125
 
115
- # We always want to push a versioned label in addition to the latest label
126
+ # We always want to push a versioned label
116
127
  unless version
117
128
  fail "No version specified in #{dockerfile} for #{path}"
118
129
  end
@@ -123,10 +134,12 @@ class PuppetDockerTools
123
134
  fail "Pushing #{path}:#{version} to dockerhub failed!"
124
135
  end
125
136
 
126
- puts "Pushing #{path}:latest to Docker Hub"
127
- exitstatus, _ = PuppetDockerTools::Utilities.push_to_dockerhub("#{path}:latest")
128
- unless exitstatus == 0
129
- fail "Pushing #{path}:latest to dockerhub failed!"
137
+ if latest
138
+ puts "Pushing #{path}:latest to Docker Hub"
139
+ exitstatus, _ = PuppetDockerTools::Utilities.push_to_dockerhub("#{path}:latest")
140
+ unless exitstatus == 0
141
+ fail "Pushing #{path}:latest to dockerhub failed!"
142
+ end
130
143
  end
131
144
  end
132
145
 
@@ -45,6 +45,32 @@ class PuppetDockerTools
45
45
  args_hash
46
46
  end
47
47
 
48
+ # Filter build args to only include ARGs listed in the dockerfile. This is
49
+ # meant for compatibility with old versions of docker.
50
+ #
51
+ # @param build_args hash of build args to filter
52
+ # @param dockerfile the dockerfile to look for ARGs in
53
+ def filter_build_args(build_args: , dockerfile: )
54
+ fail "File #{dockerfile} doesn't exist!" unless File.exist? dockerfile
55
+ text = File.read(dockerfile)
56
+
57
+ # Docker only supports passing a single ARG on each line, so
58
+ # look for arg, and ignore any default settings since we only care
59
+ # whether or not the key is available
60
+ implemented_args = text.scan(/arg +([^\n=]+)/i).flatten
61
+
62
+ # reject any entries for args that are not in the dockerfile
63
+ build_args.reject { |k,v|
64
+ if implemented_args.include?(k)
65
+ false
66
+ else
67
+ puts "Rejecting `--build-arg #{k}` since that ARG isn't in the Dockerfile"
68
+ true
69
+ end
70
+ }
71
+ end
72
+
73
+
48
74
  # Get a value from the labels on a docker image
49
75
  #
50
76
  # @param image The docker image you want to get a value from, e.g. 'puppet/puppetserver'
@@ -70,11 +96,18 @@ class PuppetDockerTools
70
96
  text = File.read(file)
71
97
 
72
98
  value = text.scan(/#{Regexp.escape(namespace)}\.(.+)=(.+) \\?/).to_h[label]
99
+ # tracking to make sure we aren't in an infinite variable loop
100
+ checked_variables = []
101
+
73
102
  # expand out environment variables
74
103
  # This supports either label=$variable or label="$variable"
75
- if value.start_with?('$') || value.start_with?('"$')
104
+ while ! value.nil? && (value.start_with?('$') || value.start_with?('"$'))
76
105
  # if variable is quoted, get rid of leading and trailing quotes
77
106
  value.gsub!(/\A"|"\Z/, '')
107
+
108
+ fail "Looks like there's an infinite loop with '#{value}'" if checked_variables.include?(value)
109
+
110
+ checked_variables << value
78
111
  value = get_value_from_variable(value, directory: directory, dockerfile: dockerfile, dockerfile_contents: text)
79
112
  end
80
113
  # check in higher-level image if we didn't find it defined in this docker file
@@ -208,9 +241,11 @@ class PuppetDockerTools
208
241
  fail "File #{file} doesn't exist!" unless File.exist? file
209
242
  dockerfile_contents = File.read("#{file}")
210
243
  end
244
+ variable_clone = String.new(variable)
211
245
  # get rid of the leading $ for the variable
212
- variable[0] = ''
213
- dockerfile_contents[/#{variable}=(["a-zA-Z0-9\.]+)/, 1]
246
+ variable_clone[0] = ''
247
+
248
+ dockerfile_contents[/#{variable_clone}=([^\s]+)/, 1]
214
249
  end
215
250
  private :get_value_from_variable
216
251
  end
@@ -14,6 +14,15 @@ describe PuppetDockerTools::Runner do
14
14
  let(:buildargs) {{ 'vcs_ref' => 'b0c5ead01b6cabdb3f01871bce699be165c3288f', 'build_date' => '2018-06-08T17:18:13Z' }.to_json}
15
15
  let(:buildargs_with_version) {{ 'vcs_ref' => 'b0c5ead01b6cabdb3f01871bce699be165c3288f', 'build_date' => '2018-06-08T17:18:13Z', 'version' => '1.2.3' }.to_json}
16
16
  let(:extra_buildargs) {{ 'vcs_ref' => 'b0c5ead01b6cabdb3f01871bce699be165c3288f', 'build_date' => '2018-06-08T17:18:13Z', 'foo' => 'bar', 'baz' => 'test=with=equals' }.to_json}
17
+ let(:read_dockerfile) {
18
+ "FROM ubuntu:16.04\n\nARG vcs_ref\nARG build_date"
19
+ }
20
+ let(:read_dockerfile_with_version) {
21
+ "FROM ubuntu:16.04\n\nARG version\nARG vcs_ref\nARG build_date"
22
+ }
23
+ let(:read_dockerfile_with_arbitrary_args) {
24
+ "FROM ubuntu:16.04\n\nARG foo\nARG baz\nARG vcs_ref\nARG build_date"
25
+ }
17
26
 
18
27
  describe '#initialize' do
19
28
  it "should fail if the dockerfile doesn't exist" do
@@ -26,6 +35,7 @@ describe PuppetDockerTools::Runner do
26
35
  let(:image) { double(Docker::Image) }
27
36
 
28
37
  it 'builds a latest and version tag if version is found' do
38
+ expect(File).to receive(:read).with("#{runner.directory}/#{runner.dockerfile}").and_return(read_dockerfile)
29
39
  expect(PuppetDockerTools::Utilities).to receive(:get_value_from_env).with('version', namespace: runner.namespace, directory: runner.directory, dockerfile: runner.dockerfile).and_return('1.2.3')
30
40
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:1.2.3', 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs }).and_return(image)
31
41
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:latest', 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs }).and_return(image)
@@ -33,30 +43,42 @@ describe PuppetDockerTools::Runner do
33
43
  end
34
44
 
35
45
  it 'builds just a latest tag if no version is found' do
46
+ expect(File).to receive(:read).with("#{runner.directory}/#{runner.dockerfile}").and_return(read_dockerfile)
36
47
  expect(PuppetDockerTools::Utilities).to receive(:get_value_from_env).with('version', namespace: runner.namespace, directory: runner.directory, dockerfile: runner.dockerfile).and_return(nil)
37
48
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:latest', 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs }).and_return(image)
38
49
  runner.build
39
50
  end
40
51
 
52
+ it 'does not build a latest tag if latest is set to false' do
53
+ expect(File).to receive(:read).with("#{runner.directory}/#{runner.dockerfile}").and_return(read_dockerfile)
54
+ expect(PuppetDockerTools::Utilities).to receive(:get_value_from_env).with('version', namespace: runner.namespace, directory: runner.directory, dockerfile: runner.dockerfile).and_return('1.2.3')
55
+ expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:1.2.3', 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs }).and_return(image)
56
+ runner.build(latest: false)
57
+ end
58
+
41
59
  it 'ignores the cache when that parameter is set' do
60
+ expect(File).to receive(:read).with("#{runner.directory}/#{runner.dockerfile}").and_return(read_dockerfile)
42
61
  expect(PuppetDockerTools::Utilities).to receive(:get_value_from_env).with('version', namespace: runner.namespace, directory: runner.directory, dockerfile: runner.dockerfile).and_return(nil)
43
62
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:latest', 'nocache' => true, 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs }).and_return(image)
44
63
  runner.build(no_cache: true)
45
64
  end
46
65
 
47
66
  it 'passes the version when that parameter is set' do
67
+ expect(File).to receive(:read).with("#{runner.directory}/#{runner.dockerfile}").and_return(read_dockerfile_with_version)
48
68
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:latest', 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs_with_version }).and_return(image)
49
69
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:1.2.3', 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs_with_version }).and_return(image)
50
70
  runner.build(version: '1.2.3')
51
71
  end
52
72
 
53
73
  it 'passes arbitrary build args' do
74
+ expect(File).to receive(:read).with("#{runner.directory}/#{runner.dockerfile}").and_return(read_dockerfile_with_arbitrary_args)
54
75
  expect(PuppetDockerTools::Utilities).to receive(:get_value_from_env).with('version', namespace: runner.namespace, directory: runner.directory, dockerfile: runner.dockerfile).and_return(nil)
55
76
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:latest', 'dockerfile' => runner.dockerfile, 'buildargs' => extra_buildargs }).and_return(image)
56
77
  runner.build(build_args: ['foo=bar', 'baz=test=with=equals'])
57
78
  end
58
79
 
59
80
  it 'prioritizes version as a build arg over regular version' do
81
+ expect(File).to receive(:read).with("#{runner.directory}/#{runner.dockerfile}").and_return(read_dockerfile_with_version)
60
82
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:latest', 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs_with_version }).and_return(image)
61
83
  expect(Docker::Image).to receive(:build_from_dir).with(runner.directory, { 't' => 'test/test-image:1.2.3', 'dockerfile' => runner.dockerfile, 'buildargs' => buildargs_with_version }).and_return(image)
62
84
  runner.build(version: '1.2.4', build_args: ['version=1.2.3'])
@@ -64,6 +86,7 @@ describe PuppetDockerTools::Runner do
64
86
 
65
87
  it 'uses a custom dockerfile if passed' do
66
88
  allow(File).to receive(:exist?).with('/tmp/test-image/Dockerfile.test').and_return(true)
89
+ expect(File).to receive(:read).with('/tmp/test-image/Dockerfile.test').and_return(read_dockerfile)
67
90
  expect(PuppetDockerTools::Utilities).to receive(:get_value_from_env).with('version', namespace: 'org.label-schema', directory: '/tmp/test-image', dockerfile: 'Dockerfile.test').and_return(nil)
68
91
  expect(Docker::Image).to receive(:build_from_dir).with('/tmp/test-image', { 't' => 'test/test-image:latest', 'dockerfile' => 'Dockerfile.test', 'buildargs' => buildargs }).and_return(image)
69
92
  local_runner = create_runner(directory: '/tmp/test-image', repository: 'test', namespace: 'org.label-schema', dockerfile: 'Dockerfile.test')
@@ -141,6 +164,12 @@ describe PuppetDockerTools::Runner do
141
164
  expect(PuppetDockerTools::Utilities).to receive(:push_to_dockerhub).with('test/test-image:latest').and_return([0, nil])
142
165
  runner.push
143
166
  end
167
+
168
+ it 'should not push the latest tag if latest is set to false' do
169
+ expect(PuppetDockerTools::Utilities).to receive(:get_value_from_label).with('test/test-image', value: 'version', namespace: runner.namespace).and_return('1.2.3')
170
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_dockerhub).with('test/test-image:1.2.3').and_return([0, nil])
171
+ runner.push(latest: false)
172
+ end
144
173
  end
145
174
 
146
175
  describe '#rev_labels' do
@@ -37,6 +37,49 @@ LABEL maintainer="Puppet Release Team <release@puppet.com>" \\
37
37
  com.puppet.dockerfile="/Dockerfile"
38
38
  HERE
39
39
  }
40
+ let(:infinite_dockerfile_contents) { <<-HERE
41
+ FROM ubuntu:16.04
42
+
43
+ ENV PUPPET_SERVER_VERSION=$foo foo=$PUPPET_SERVER_VERSION
44
+
45
+ LABEL maintainer="Puppet Release Team <release@puppet.com>" \\
46
+ org.label-schema.vendor="Puppet" \\
47
+ org.label-schema.url="https://github.com/puppetlabs/puppet-in-docker" \\
48
+ org.label-schema.name="Puppet Server (No PuppetDB)" \\
49
+ org.label-schema.license="Apache-2.0" \\
50
+ org.label-schema.version="$PUPPET_SERVER_VERSION" \\
51
+ org.label-schema.vcs-url="https://github.com/puppetlabs/puppet-in-docker" \\
52
+ org.label-schema.vcs-ref="b75674e1fbf52f7821f7900ab22a19f1a10cafdb" \\
53
+ org.label-schema.build-date="2018-05-09T20:11:01Z" \\
54
+ org.label-schema.schema-version="1.0" \\
55
+ com.puppet.dockerfile="/Dockerfile"
56
+ HERE
57
+ }
58
+ let(:dockerfile_with_args) { <<-HERE
59
+ FROM puppet/puppetserver-standalone:5.3.1
60
+
61
+ ARG version
62
+ ARG foo
63
+ ARG bar
64
+ HERE
65
+ }
66
+
67
+ let(:build_args) {
68
+ {
69
+ 'version' => '1.2.3',
70
+ 'foo' => 'test',
71
+ 'bar' => 'baz',
72
+ 'test' => 'test2',
73
+ }
74
+ }
75
+
76
+ let(:filtered_build_args) {
77
+ {
78
+ 'version' => '1.2.3',
79
+ 'foo' => 'test',
80
+ 'bar' => 'baz',
81
+ }
82
+ }
40
83
 
41
84
  let(:config_labels) { {
42
85
  'Config' => {
@@ -49,6 +92,20 @@ HERE
49
92
  }
50
93
  }
51
94
 
95
+ describe "#filter_build_args" do
96
+ it "should fail if the dockerfile doesn't exist" do
97
+ allow(File).to receive(:exist?).with("/tmp/test-dir/#{dockerfile}").and_return(false)
98
+ expect { PuppetDockerTools::Utilities.filter_build_args(build_args: build_args, dockerfile: "/tmp/test-dir/#{dockerfile}") }.to raise_error(RuntimeError, /doesn't exist/)
99
+ end
100
+
101
+ it "should filter out any buildargs not in the dockerfile" do
102
+ allow(File).to receive(:exist?).with("/tmp/test-dir/#{dockerfile}").and_return(true)
103
+ allow(File).to receive(:read).with("/tmp/test-dir/#{dockerfile}").and_return(dockerfile_with_args)
104
+ expect(PuppetDockerTools::Utilities.filter_build_args(build_args: build_args, dockerfile: "/tmp/test-dir/#{dockerfile}")).to eq(filtered_build_args)
105
+ end
106
+
107
+ end
108
+
52
109
  describe "#get_value_from_label" do
53
110
  let(:image) { double(Docker::Image).as_null_object }
54
111
 
@@ -89,6 +146,12 @@ HERE
89
146
  allow(File).to receive(:read).with("/tmp/test-dir/../puppetserver-standalone/#{dockerfile}").and_return(base_dockerfile_contents)
90
147
  expect(PuppetDockerTools::Utilities.get_value_from_env('version', namespace: 'org.label-schema', directory: '/tmp/test-dir')).to eq('5.3.1')
91
148
  end
149
+
150
+ it "doesn't get stuck in an infinite loop if there's a bad variable definition" do
151
+ allow(File).to receive(:exist?).with("/tmp/test-dir/#{dockerfile}").and_return(true)
152
+ allow(File).to receive(:read).with("/tmp/test-dir/#{dockerfile}").and_return(infinite_dockerfile_contents)
153
+ expect { PuppetDockerTools::Utilities.get_value_from_env('version', namespace: 'org.label-schema', directory: '/tmp/test-dir')}.to raise_error(RuntimeError, /infinite loop/)
154
+ end
92
155
  end
93
156
 
94
157
  describe "#format_timestamp" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_docker_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api