puppet_docker_tools 0.1.4 → 0.1.5

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: 83418018be00481fd020d44eb91dc3e91cbe64d9
4
- data.tar.gz: 981bd7c153e5cfec42bf8f97bc6e791278d76dd8
3
+ metadata.gz: d9a052ffa04d431161f3d63267430416c2857234
4
+ data.tar.gz: bad61b2a4a18d434760e620c7dfe3fe531f63a1d
5
5
  SHA512:
6
- metadata.gz: 27d23f46ffe35d28e41e5fe9c66493d35eadcfde6adfc97b55ad01159f517b6052e769a99f3da9428b0405a5b533d972856160a5bb55c26902d2017eae594d26
7
- data.tar.gz: 18f9ec6d818748ec65ebb58142b9b65832259d679211f8d2a0a0761548b73be7e9c903f5a40a92945cfde5c8f5402e5eb56e4e2f04c99041bf2cc228c4a603e4
6
+ metadata.gz: ab37a2fc5f60e35a88dd59a447c72d45d461083a77edda97a868c6d02abe519565b994e5925f1b3d6cb6599e0d2a0c279e07b166c2919bca6fc07cdf94361ef0
7
+ data.tar.gz: bc64d63f6cd8bc8285021b1746057a7236c9669217559517044e2016d23ec11fe4ae14faf8355a332b5293c90dd849d3adc57dbd3cf80f17f7c27c510c6a4833
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> ...] [--no-latest]
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>] [--no-latest]
22
+ puppet-docker push [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>] [--version=<version>] [--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>]
@@ -33,15 +33,14 @@ Arguments:
33
33
  TAG Pull latest versions of images at TAG. Defaults to ['ubuntu:16.04', 'centos:7', 'alpine:3.4', 'debian:9', 'postgres:9.6.8']
34
34
 
35
35
  Options:
36
- --repository=<repo> Dockerhub repository containing the image [default: puppet]
36
+ --repository=<repo> Docker repository containing the image [default: puppet]
37
37
  --no-cache Disable use of layer cache when building this image. Defaults to using the cache.
38
38
  --namespace=<namespace> Namespace for labels on the container [default: org.label-schema]
39
39
  --dockerfile=<dockerfile> File name for your dockerfile [default: Dockerfile]
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
+ --no-latest Do not include the 'latest' tag when building and shipping images. By default, the 'latest' tag is built and shipped with the versioned tag.
45
44
  ```
46
45
 
47
46
  ### `puppet-docker build`
@@ -66,7 +65,7 @@ Pull the specified image, i.e. 'puppet/puppetserver'. *NOTE*: If you don't inclu
66
65
 
67
66
  ### `puppet-docker push`
68
67
 
69
- Push images built from the dockerfile in DIRECTORY to hub.docker.com. This task will fail if you do not have a version specified in your dockerfile. It will push both a versioned and a 'latest' tagged image.
68
+ Push images built from the dockerfile in DIRECTORY to <repo>. This task will fail if you do not have a version specified in your dockerfile. It will push both a versioned and a 'latest' tagged image.
70
69
 
71
70
  ### `puppet-docker rev-labels`
72
71
 
data/bin/puppet-docker CHANGED
@@ -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> ...] [--no-latest]
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>] [--no-latest]
14
+ puppet-docker push [DIRECTORY] [--dockerfile=<dockerfile>] [--repository=<repo>] [--namespace=<namespace>] [--version=<version>] [--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>]
@@ -25,15 +25,14 @@ Arguments:
25
25
  TAG Pull latest versions of images at TAG. Defaults to ['ubuntu:16.04', 'centos:7', 'alpine:3.4', 'debian:9', 'postgres:9.6.8']
26
26
 
27
27
  Options:
28
- --repository=<repo> Dockerhub repository containing the image [default: puppet]
28
+ --repository=<repo> Docker repository containing the image [default: puppet]
29
29
  --no-cache Disable use of layer cache when building this image. Defaults to using the cache.
30
30
  --namespace=<namespace> Namespace for labels on the container [default: org.label-schema]
31
31
  --dockerfile=<dockerfile> File name for your dockerfile [default: Dockerfile]
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
+ --no-latest Do not include the 'latest' tag when building and shipping images. By default, the 'latest' tag is built and shipped with the versioned tag.
37
36
  DOC
38
37
 
39
38
  begin
@@ -88,7 +87,7 @@ begin
88
87
  elsif options['local-lint']
89
88
  command_runner.local_lint
90
89
  elsif options['push']
91
- command_runner.push(latest: latest)
90
+ command_runner.push(latest: latest, version: options['--version'])
92
91
  elsif options['rev-labels']
93
92
  command_runner.rev_labels
94
93
  elsif options['spec']
@@ -114,31 +114,35 @@ class PuppetDockerTools
114
114
  fail output unless status == 0
115
115
  end
116
116
 
117
- # Push an image to hub.docker.com
117
+ # Push an image to $repository
118
118
  #
119
119
  # @param latest Whether or not to push the latest tag along with the
120
120
  # versioned image build.
121
- def push(latest: true)
121
+ def push(latest: true, version: nil)
122
122
  image_name = File.basename(directory)
123
123
  path = "#{repository}/#{image_name}"
124
- version = PuppetDockerTools::Utilities.get_value_from_label(path, value: 'version', namespace: namespace)
125
124
 
126
- # We always want to push a versioned label
125
+ # only check for version from the label if we didn't pass it in
126
+ if version.nil?
127
+ version = PuppetDockerTools::Utilities.get_value_from_label(path, value: 'version', namespace: namespace)
128
+ end
129
+
130
+ # We always want to push a versioned container
127
131
  unless version
128
132
  fail "No version specified in #{dockerfile} for #{path}"
129
133
  end
130
134
 
131
- puts "Pushing #{path}:#{version} to Docker Hub"
132
- exitstatus, _ = PuppetDockerTools::Utilities.push_to_dockerhub("#{path}:#{version}")
135
+ puts "Pushing #{path}:#{version}"
136
+ exitstatus, _ = PuppetDockerTools::Utilities.push_to_docker_repo("#{path}:#{version}")
133
137
  unless exitstatus == 0
134
- fail "Pushing #{path}:#{version} to dockerhub failed!"
138
+ fail "Pushing #{path}:#{version} failed!"
135
139
  end
136
140
 
137
141
  if latest
138
- puts "Pushing #{path}:latest to Docker Hub"
139
- exitstatus, _ = PuppetDockerTools::Utilities.push_to_dockerhub("#{path}:latest")
142
+ puts "Pushing #{path}:latest"
143
+ exitstatus, _ = PuppetDockerTools::Utilities.push_to_docker_repo("#{path}:latest")
140
144
  unless exitstatus == 0
141
- fail "Pushing #{path}:latest to dockerhub failed!"
145
+ fail "Pushing #{path}:latest failed!"
142
146
  end
143
147
  end
144
148
  end
@@ -5,14 +5,16 @@ class PuppetDockerTools
5
5
  module Utilities
6
6
  module_function
7
7
 
8
- # Push an image to hub.docker.com
8
+ # Push an image to a docker repository
9
9
  #
10
10
  # @param image_name The image to push, including the tag e.g., puppet/puppetserver:latest
11
+ # If pushing to a private repo, the image name should include the repo endpoint,
12
+ # like my-docker-repo.internal.net/puppet/puppetserver:latest
11
13
  # @param stream_output Whether or not to stream output as it comes in, defaults to true
12
14
  # @return Returns an array containing the integer exitstatus of the push
13
15
  # command and a string containing the combined stdout and stderr
14
16
  # from the push
15
- def push_to_dockerhub(image_name, stream_output=true)
17
+ def push_to_docker_repo(image_name, stream_output=true)
16
18
  Open3.popen2e("docker push #{image_name}") do |stdin, output_stream, wait_thread|
17
19
  output=''
18
20
  while line = output_stream.gets
@@ -147,29 +147,36 @@ describe PuppetDockerTools::Runner do
147
147
 
148
148
  it 'should raise an error if something bad happens pushing the versioned tag' do
149
149
  expect(PuppetDockerTools::Utilities).to receive(:get_value_from_label).with('test/test-image', value: 'version', namespace: runner.namespace).and_return('1.2.3')
150
- expect(PuppetDockerTools::Utilities).to receive(:push_to_dockerhub).with('test/test-image:1.2.3').and_return([1, nil])
151
- expect { runner.push }.to raise_error(RuntimeError, /1.2.3 to dockerhub/i)
150
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_docker_repo).with('test/test-image:1.2.3').and_return([1, nil])
151
+ expect { runner.push }.to raise_error(RuntimeError, /1.2.3 failed/i)
152
152
  end
153
153
 
154
154
  it 'should raise an error if something bad happens pushing the latest tag' do
155
155
  expect(PuppetDockerTools::Utilities).to receive(:get_value_from_label).with('test/test-image', value: 'version', namespace: runner.namespace).and_return('1.2.3')
156
- expect(PuppetDockerTools::Utilities).to receive(:push_to_dockerhub).with('test/test-image:1.2.3').and_return([0, nil])
157
- expect(PuppetDockerTools::Utilities).to receive(:push_to_dockerhub).with('test/test-image:latest').and_return([1, nil])
158
- expect { runner.push }.to raise_error(RuntimeError, /latest to dockerhub/i)
156
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_docker_repo).with('test/test-image:1.2.3').and_return([0, nil])
157
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_docker_repo).with('test/test-image:latest').and_return([1, nil])
158
+ expect { runner.push }.to raise_error(RuntimeError, /latest failed/i)
159
159
  end
160
160
 
161
161
  it 'should push the versioned and latest tags if nothing goes wrong' do
162
162
  expect(PuppetDockerTools::Utilities).to receive(:get_value_from_label).with('test/test-image', value: 'version', namespace: runner.namespace).and_return('1.2.3')
163
- expect(PuppetDockerTools::Utilities).to receive(:push_to_dockerhub).with('test/test-image:1.2.3').and_return([0, nil])
164
- expect(PuppetDockerTools::Utilities).to receive(:push_to_dockerhub).with('test/test-image:latest').and_return([0, nil])
163
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_docker_repo).with('test/test-image:1.2.3').and_return([0, nil])
164
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_docker_repo).with('test/test-image:latest').and_return([0, nil])
165
165
  runner.push
166
166
  end
167
167
 
168
168
  it 'should not push the latest tag if latest is set to false' do
169
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])
170
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_docker_repo).with('test/test-image:1.2.3').and_return([0, nil])
171
171
  runner.push(latest: false)
172
172
  end
173
+
174
+ it "shouldn't look for the version if it's passed" do
175
+ expect(PuppetDockerTools::Utilities).not_to receive(:get_value_from_label)
176
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_docker_repo).with('test/test-image:4.5.6').and_return([0, nil])
177
+ expect(PuppetDockerTools::Utilities).to receive(:push_to_docker_repo).with('test/test-image:latest').and_return([0, nil])
178
+ runner.push(version: '4.5.6')
179
+ end
173
180
  end
174
181
 
175
182
  describe '#rev_labels' 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.4
4
+ version: 0.1.5
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-27 00:00:00.000000000 Z
11
+ date: 2018-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api