rake_docker 2.18.0.pre.3 → 2.18.0.pre.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
  SHA256:
3
- metadata.gz: 46278acb600e916d70c94a54563dd1174414b3f84d669dca1ada50727fc45779
4
- data.tar.gz: 076cfa6dda33a6a215f88ea9a82f7e1d6ad3bb1654fa99c4b3c684c7d25344af
3
+ metadata.gz: 4a932921ad25b056f1a6511de649ac1d33001808f709a04f12e4b489da651f9c
4
+ data.tar.gz: d651071a7bf66207d7fd3f4746f845e6834d768e8710b78e2b0433bc92e0240e
5
5
  SHA512:
6
- metadata.gz: 46b5aabf9ab0199f3bcb90aa09502182ca5ce4aafae7bd635657e5681e5019d24759e6dfd36c7f2ce91457292db23ba8405d8d8b103cb758d8ac93c1843c5365
7
- data.tar.gz: 348a89a1159fe404bc61f151d61d99cb98649f7cfa9d64f96f9231c9d87e69f63349debd4abfcce2c84fd17a29d2b5113d7b379b17fe869dcae7754ed31728c1
6
+ metadata.gz: 6aa7afc73ba5467db5ef310f504a2700ac780db71c163fa472258acdaf161703cbb722ce2a40ed06d3749dc4eac7f0eba8c7506cdcfccb7116551d967850cd40
7
+ data.tar.gz: 5649029539578dceb8ffd07dc7e4f73bafd683477c0d4afdbaa3418b52bdb5bbedd3ccf20a44015b0faae584f1c667b57f4fd8fbd8fba9d0d3e26d14162a9978
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in rake_docker.gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_docker (2.18.0.pre.3)
4
+ rake_docker (2.18.0.pre.4)
5
5
  aws-sdk-ecr (~> 1.2)
6
6
  colored2 (~> 3.1)
7
7
  docker-api (>= 1.34, < 3.0)
@@ -17,14 +17,15 @@ GEM
17
17
  tzinfo (~> 2.0)
18
18
  addressable (2.8.0)
19
19
  public_suffix (>= 2.0.2, < 5.0)
20
+ ast (2.4.2)
20
21
  aws-eventstream (1.2.0)
21
- aws-partitions (1.566.0)
22
+ aws-partitions (1.568.0)
22
23
  aws-sdk-core (3.130.0)
23
24
  aws-eventstream (~> 1, >= 1.0.2)
24
25
  aws-partitions (~> 1, >= 1.525.0)
25
26
  aws-sigv4 (~> 1.1)
26
27
  jmespath (~> 1.0)
27
- aws-sdk-ecr (1.55.0)
28
+ aws-sdk-ecr (1.56.0)
28
29
  aws-sdk-core (~> 3, >= 3.127.0)
29
30
  aws-sigv4 (~> 1.1)
30
31
  aws-sigv4 (1.4.0)
@@ -77,7 +78,11 @@ GEM
77
78
  faraday (>= 0.9)
78
79
  sawyer (~> 0.8.0, >= 0.5.3)
79
80
  open4 (1.3.4)
81
+ parallel (1.22.1)
82
+ parser (3.1.1.0)
83
+ ast (~> 2.4.1)
80
84
  public_suffix (4.0.6)
85
+ rainbow (3.1.1)
81
86
  rake (13.0.6)
82
87
  rake_circle_ci (0.9.0)
83
88
  colored2 (~> 3.1)
@@ -99,6 +104,8 @@ GEM
99
104
  colored2 (~> 3.1)
100
105
  rake_factory (~> 0.23)
101
106
  sshkey (~> 2.0)
107
+ regexp_parser (2.2.1)
108
+ rexml (3.2.5)
102
109
  rspec (3.11.0)
103
110
  rspec-core (~> 3.11.0)
104
111
  rspec-expectations (~> 3.11.0)
@@ -112,6 +119,22 @@ GEM
112
119
  diff-lcs (>= 1.2.0, < 2.0)
113
120
  rspec-support (~> 3.11.0)
114
121
  rspec-support (3.11.0)
122
+ rubocop (1.26.1)
123
+ parallel (~> 1.10)
124
+ parser (>= 3.1.0.0)
125
+ rainbow (>= 2.2.2, < 4.0)
126
+ regexp_parser (>= 1.8, < 3.0)
127
+ rexml
128
+ rubocop-ast (>= 1.16.0, < 2.0)
129
+ ruby-progressbar (~> 1.7)
130
+ unicode-display_width (>= 1.4.0, < 3.0)
131
+ rubocop-ast (1.16.0)
132
+ parser (>= 3.1.1.0)
133
+ rubocop-rake (0.6.0)
134
+ rubocop (~> 1.0)
135
+ rubocop-rspec (2.9.0)
136
+ rubocop (~> 1.19)
137
+ ruby-progressbar (1.11.0)
115
138
  ruby2_keywords (0.0.5)
116
139
  ruby_gpg2 (0.8.0)
117
140
  lino (>= 1.5)
@@ -127,6 +150,7 @@ GEM
127
150
  sshkey (2.0.0)
128
151
  tzinfo (2.0.4)
129
152
  concurrent-ruby (~> 1.0)
153
+ unicode-display_width (2.1.0)
130
154
 
131
155
  PLATFORMS
132
156
  ruby
@@ -143,7 +167,10 @@ DEPENDENCIES
143
167
  rake_gpg
144
168
  rake_ssh
145
169
  rspec
170
+ rubocop
171
+ rubocop-rake
172
+ rubocop-rspec
146
173
  simplecov
147
174
 
148
175
  BUNDLED WITH
149
- 2.3.9
176
+ 2.3.10
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'rake_circle_ci'
3
5
  require 'rake_github'
@@ -5,17 +7,20 @@ require 'rake_ssh'
5
7
  require 'rake_gpg'
6
8
  require 'securerandom'
7
9
  require 'rspec/core/rake_task'
10
+ require 'rubocop/rake_task'
8
11
 
9
- task :default => :spec
10
-
11
- RSpec::Core::RakeTask.new(:spec)
12
+ task default: %i[
13
+ library:fix
14
+ test:unit
15
+ ]
12
16
 
13
17
  namespace :encryption do
14
18
  namespace :passphrase do
19
+ desc 'Generate encryption passphrase for CI GPG key'
15
20
  task :generate do
16
- File.open('config/secrets/ci/encryption.passphrase', 'w') do |f|
17
- f.write(SecureRandom.base64(36))
18
- end
21
+ FileUtils.mkdir_p('config/secrets/ci/')
22
+ File.write('config/secrets/ci/encryption.passphrase',
23
+ SecureRandom.base64(36))
19
24
  end
20
25
  end
21
26
  end
@@ -23,85 +28,102 @@ end
23
28
  namespace :keys do
24
29
  namespace :deploy do
25
30
  RakeSSH.define_key_tasks(
26
- path: 'config/secrets/ci/',
27
- comment: 'maintainers@infrablocks.io')
31
+ path: 'config/secrets/ci/',
32
+ comment: 'maintainers@infrablocks.io'
33
+ )
28
34
  end
29
35
 
30
36
  namespace :gpg do
31
37
  RakeGPG.define_generate_key_task(
32
- output_directory: 'config/secrets/ci',
33
- name_prefix: 'gpg',
34
- owner_name: 'InfraBlocks Maintainers',
35
- owner_email: 'maintainers@infrablocks.io',
36
- owner_comment: 'rake_docker CI Key')
38
+ output_directory: 'config/secrets/ci',
39
+ name_prefix: 'gpg',
40
+ owner_name: 'InfraBlocks Maintainers',
41
+ owner_email: 'maintainers@infrablocks.io',
42
+ owner_comment: 'rake_docker CI Key'
43
+ )
37
44
  end
38
45
  end
39
46
 
47
+ RuboCop::RakeTask.new
48
+
49
+ namespace :library do
50
+ desc 'Run all checks of the library'
51
+ task check: [:rubocop]
52
+
53
+ desc 'Attempt to automatically fix issues with the library'
54
+ task fix: [:'rubocop:auto_correct']
55
+ end
56
+
57
+ namespace :test do
58
+ RSpec::Core::RakeTask.new(:unit)
59
+ end
60
+
40
61
  RakeCircleCI.define_project_tasks(
41
- namespace: :circle_ci,
42
- project_slug: 'github/infrablocks/rake_docker'
62
+ namespace: :circle_ci,
63
+ project_slug: 'github/infrablocks/rake_docker'
43
64
  ) do |t|
44
65
  circle_ci_config =
45
- YAML.load_file('config/secrets/circle_ci/config.yaml')
66
+ YAML.load_file('config/secrets/circle_ci/config.yaml')
46
67
 
47
- t.api_token = circle_ci_config["circle_ci_api_token"]
68
+ t.api_token = circle_ci_config['circle_ci_api_token']
48
69
  t.environment_variables = {
49
- ENCRYPTION_PASSPHRASE:
50
- File.read('config/secrets/ci/encryption.passphrase')
51
- .chomp
70
+ ENCRYPTION_PASSPHRASE:
71
+ File.read('config/secrets/ci/encryption.passphrase')
72
+ .chomp
52
73
  }
53
74
  t.checkout_keys = []
54
75
  t.ssh_keys = [
55
- {
56
- hostname: "github.com",
57
- private_key: File.read('config/secrets/ci/ssh.private')
58
- }
76
+ {
77
+ hostname: 'github.com',
78
+ private_key: File.read('config/secrets/ci/ssh.private')
79
+ }
59
80
  ]
60
81
  end
61
82
 
62
83
  RakeGithub.define_repository_tasks(
63
- namespace: :github,
64
- repository: 'infrablocks/rake_docker',
84
+ namespace: :github,
85
+ repository: 'infrablocks/rake_docker'
65
86
  ) do |t, args|
66
87
  github_config =
67
- YAML.load_file('config/secrets/github/config.yaml')
88
+ YAML.load_file('config/secrets/github/config.yaml')
68
89
 
69
- t.access_token = github_config["github_personal_access_token"]
90
+ t.access_token = github_config['github_personal_access_token']
70
91
  t.deploy_keys = [
71
- {
72
- title: 'CircleCI',
73
- public_key: File.read('config/secrets/ci/ssh.public')
74
- }
92
+ {
93
+ title: 'CircleCI',
94
+ public_key: File.read('config/secrets/ci/ssh.public')
95
+ }
75
96
  ]
76
97
  t.branch_name = args.branch_name
77
98
  t.commit_message = args.commit_message
78
99
  end
79
100
 
80
101
  namespace :pipeline do
81
- task :prepare => [
82
- :'circle_ci:project:follow',
83
- :'circle_ci:env_vars:ensure',
84
- :'circle_ci:checkout_keys:ensure',
85
- :'circle_ci:ssh_keys:ensure',
86
- :'github:deploy_keys:ensure'
102
+ desc 'Prepare CircleCI Pipeline'
103
+ task prepare: %i[
104
+ circle_ci:project:follow
105
+ circle_ci:env_vars:ensure
106
+ circle_ci:checkout_keys:ensure
107
+ circle_ci:ssh_keys:ensure
108
+ github:deploy_keys:ensure
87
109
  ]
88
110
  end
89
111
 
90
112
  namespace :version do
91
- desc "Bump version for specified type (pre, major, minor, patch)"
113
+ desc 'Bump version for specified type (pre, major, minor, patch)'
92
114
  task :bump, [:type] do |_, args|
93
115
  bump_version_for(args.type)
94
116
  end
95
117
  end
96
118
 
97
- desc "Release gem"
119
+ desc 'Release gem'
98
120
  task :release do
99
- sh "gem release --tag --push"
121
+ sh 'gem release --tag --push'
100
122
  end
101
123
 
102
124
  def bump_version_for(version_type)
103
- sh "gem bump --version #{version_type} " +
104
- "&& bundle install " +
105
- "&& export LAST_MESSAGE=\"$(git log -1 --pretty=%B)\" " +
106
- "&& git commit -a --amend -m \"${LAST_MESSAGE} [ci skip]\""
125
+ sh "gem bump --version #{version_type} " \
126
+ '&& bundle install ' \
127
+ '&& export LAST_MESSAGE="$(git log -1 --pretty=%B)" ' \
128
+ '&& git commit -a --amend -m "${LAST_MESSAGE} [ci skip]"'
107
129
  end
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "rake_docker"
4
+ require 'bundler/setup'
5
+ require 'rake_docker'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "rake_docker"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-sdk-ecr'
2
- require 'ostruct'
3
4
 
4
5
  module RakeDocker
5
6
  module Authentication
6
7
  class ECR
7
- def initialize &block
8
- @config = OpenStruct.new(
9
- region: nil,
10
- registry_id: nil)
8
+ def initialize(&block)
9
+ @config =
10
+ Struct.new(:region, :registry_id)
11
+ .new(nil, nil)
11
12
  block.call(@config)
12
13
 
13
14
  @ecr_client = Aws::ECR::Client.new(region: @config.region)
@@ -18,23 +19,47 @@ module RakeDocker
18
19
  end
19
20
 
20
21
  def call
21
- registry_id = @config.registry_id.respond_to?(:call) ?
22
- @config.registry_id.call :
23
- @config.registry_id
24
-
25
- token_response = @ecr_client.get_authorization_token(
26
- registry_ids: [registry_id])
27
- token_data = token_response.authorization_data[0]
28
- proxy_endpoint = token_data.proxy_endpoint
29
22
  email = 'none'
30
- username, password =
31
- Base64.decode64(token_data.authorization_token).split(':')
23
+ registry_id = resolve_registry_id
24
+ token = get_authorization_token(registry_id)
25
+ proxy_endpoint = extract_proxy_endpoint(token)
26
+ username, password = extract_credentials(token)
27
+
28
+ make_credentials_hash(email, password, username, proxy_endpoint)
29
+ end
32
30
 
31
+ private
32
+
33
+ def make_credentials_hash(email, password, username, proxy_endpoint)
33
34
  {
34
- username: username, password: password, email: email,
35
- serveraddress: proxy_endpoint
35
+ username: username,
36
+ password: password,
37
+ email: email,
38
+ serveraddress: proxy_endpoint
36
39
  }
37
40
  end
41
+
42
+ def resolve_registry_id
43
+ if @config.registry_id.respond_to?(:call)
44
+ @config.registry_id.call
45
+ else
46
+ @config.registry_id
47
+ end
48
+ end
49
+
50
+ def get_authorization_token(registry_id)
51
+ @ecr_client
52
+ .get_authorization_token(registry_ids: [registry_id])
53
+ .authorization_data[0]
54
+ end
55
+
56
+ def extract_proxy_endpoint(token)
57
+ token.proxy_endpoint
58
+ end
59
+
60
+ def extract_credentials(token)
61
+ Base64.decode64(token.authorization_token).split(':')
62
+ end
38
63
  end
39
64
  end
40
- end
65
+ end
@@ -1 +1,3 @@
1
- require_relative 'authentication/ecr'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'authentication/ecr'
@@ -1,34 +1,38 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'docker'
2
4
 
3
5
  module RakeDocker
4
6
  module Container
5
- REPORTER_MESSAGES = [
6
- :checking_if_container_exists,
7
- :container_exists,
8
- :container_does_not_exist,
9
- :checking_if_image_available,
10
- :image_available,
11
- :image_not_available,
12
- :pulling_image,
13
- :image_pulled,
14
- :creating_container,
15
- :container_created,
16
- :checking_if_container_running,
17
- :container_running,
18
- :container_not_running,
19
- :starting_container,
20
- :container_started,
21
- :waiting_for_container_to_be_ready,
22
- :container_ready,
23
- :stopping_container,
24
- :container_stopped,
25
- :deleting_container,
26
- :container_deleted,
27
- :done
28
- ]
7
+ REPORTER_MESSAGES = %i[
8
+ checking_if_container_exists
9
+ container_exists
10
+ container_does_not_exist
11
+ checking_if_image_available
12
+ image_available
13
+ image_not_available
14
+ pulling_image
15
+ image_pulled
16
+ creating_container
17
+ container_created
18
+ checking_if_container_running
19
+ container_running
20
+ container_not_running
21
+ starting_container
22
+ container_started
23
+ waiting_for_container_to_be_ready
24
+ container_ready
25
+ stopping_container
26
+ container_stopped
27
+ deleting_container
28
+ container_deleted
29
+ done
30
+ ].freeze
29
31
 
30
32
  class NullReporter
31
- REPORTER_MESSAGES.each { |message| define_method(message) { |*_| } }
33
+ REPORTER_MESSAGES.each do |message|
34
+ define_method(message, proc { |*_| })
35
+ end
32
36
  end
33
37
 
34
38
  class PrintingReporter
@@ -123,11 +127,9 @@ module RakeDocker
123
127
 
124
128
  module Utilities
125
129
  def find_container(name)
126
- begin
127
- enhance_with_name(Docker::Container.get(name), name)
128
- rescue Docker::Error::NotFoundError
129
- nil
130
- end
130
+ enhance_with_name(Docker::Container.get(name), name)
131
+ rescue Docker::Error::NotFoundError
132
+ nil
131
133
  end
132
134
 
133
135
  def enhance_with_name(container, name)
@@ -138,6 +140,7 @@ module RakeDocker
138
140
  end
139
141
  end
140
142
 
143
+ # rubocop:disable Metrics/ClassLength
141
144
  class Provisioner
142
145
  include Utilities
143
146
 
@@ -152,6 +155,7 @@ module RakeDocker
152
155
  @reporter = opts[:reporter] || NullReporter.new
153
156
  end
154
157
 
158
+ # rubocop:disable Metrics/AbcSize
155
159
  def execute
156
160
  reporter.checking_if_container_exists(name)
157
161
  container = find_container(name)
@@ -160,14 +164,19 @@ module RakeDocker
160
164
  ensure_container_running(container)
161
165
  else
162
166
  reporter.container_does_not_exist(name)
163
- ensure_image_available(image)
164
- create_and_start_container(name, image, ports, environment)
167
+ start_new_container(name, image, ports, environment)
165
168
  end
166
169
  reporter.done
167
170
  end
171
+ # rubocop:enable Metrics/AbcSize
168
172
 
169
173
  private
170
174
 
175
+ def start_new_container(name, image, ports, environment)
176
+ ensure_image_available(image)
177
+ create_and_start_container(name, image, ports, environment)
178
+ end
179
+
171
180
  def ensure_image_available(image)
172
181
  reporter.checking_if_image_available(image)
173
182
  matching_images = Docker::Image.all(filter: image)
@@ -188,11 +197,11 @@ module RakeDocker
188
197
  def ensure_container_running(container)
189
198
  reporter.checking_if_container_running(container)
190
199
  container = find_container(name)
191
- if !container_running?(container)
200
+ if container_running?(container)
201
+ reporter.container_running(container)
202
+ else
192
203
  reporter.container_not_running(container)
193
204
  start_container(container)
194
- else
195
- reporter.container_running(container)
196
205
  end
197
206
  end
198
207
 
@@ -204,23 +213,32 @@ module RakeDocker
204
213
  exposed_ports, port_bindings = process_ports(ports)
205
214
  reporter.creating_container(name, image)
206
215
  container = Docker::Container.create(
207
- name: name,
208
- Image: image,
209
- ExposedPorts: exposed_ports,
210
- HostConfig: {
211
- PortBindings: port_bindings
212
- },
213
- Env: environment)
216
+ make_container_options(
217
+ name, image, exposed_ports, port_bindings, environment
218
+ )
219
+ )
214
220
  container = enhance_with_name(container, name)
215
221
  reporter.container_created(container)
216
222
  container
217
223
  end
218
224
 
225
+ def make_container_options(
226
+ name, image, exposed_ports, port_bindings, environment
227
+ )
228
+ {
229
+ name: name,
230
+ Image: image,
231
+ ExposedPorts: exposed_ports,
232
+ HostConfig: { PortBindings: port_bindings },
233
+ Env: environment
234
+ }
235
+ end
236
+
219
237
  def start_container(container)
220
238
  reporter.starting_container(container)
221
239
  container.start
222
240
  reporter.container_started(container)
223
- if ready && ready.respond_to?(:call)
241
+ if ready.respond_to?(:call)
224
242
  reporter.waiting_for_container_to_be_ready(container)
225
243
  ready.call(container)
226
244
  reporter.container_ready(container)
@@ -237,19 +255,18 @@ module RakeDocker
237
255
  end
238
256
 
239
257
  def process_ports(ports)
240
- port_config = ports.reduce({
241
- exposed_ports: {},
242
- port_bindings: {}
243
- }) do |accumulator, port|
258
+ port_config = ports.each_with_object(
259
+ { exposed_ports: {}, port_bindings: {} }
260
+ ) do |port, accumulator|
244
261
  host_port, container_port = port.split(':')
245
262
  accumulator[:exposed_ports]["#{container_port}/tcp"] = {}
246
263
  accumulator[:port_bindings]["#{container_port}/tcp"] =
247
- [{:'HostPort' => host_port}]
248
- accumulator
264
+ [{ HostPort: host_port }]
249
265
  end
250
266
  [port_config[:exposed_ports], port_config[:port_bindings]]
251
267
  end
252
268
  end
269
+ # rubocop:enable Metrics/ClassLength
253
270
 
254
271
  class Destroyer
255
272
  include Utilities
@@ -266,18 +283,24 @@ module RakeDocker
266
283
  container = find_container(name)
267
284
  if container
268
285
  reporter.container_exists(container)
269
- reporter.stopping_container(container)
270
- container.stop
271
- container.wait
272
- reporter.container_stopped(container)
273
- reporter.deleting_container(container)
274
- container.delete
275
- reporter.container_deleted(container)
286
+ destroy_container(container)
276
287
  else
277
288
  reporter.container_does_not_exist(name)
278
289
  end
279
290
  reporter.done
280
291
  end
292
+
293
+ private
294
+
295
+ def destroy_container(container)
296
+ reporter.stopping_container(container)
297
+ container.stop
298
+ container.wait
299
+ reporter.container_stopped(container)
300
+ reporter.deleting_container(container)
301
+ container.delete
302
+ reporter.container_deleted(container)
303
+ end
281
304
  end
282
305
  end
283
306
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeDocker
2
4
  class ImageNotFound < ::StandardError
3
5
  end
4
- end
6
+ end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake_factory/kernel_extensions'