rake_docker 2.18.0.pre.3 → 2.18.0.pre.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +55 -26
- data/Rakefile +67 -45
- data/bin/console +4 -3
- data/lib/rake_docker/authentication/ecr.rb +43 -18
- data/lib/rake_docker/authentication.rb +3 -1
- data/lib/rake_docker/container.rb +79 -56
- data/lib/rake_docker/exceptions.rb +3 -1
- data/lib/rake_docker/kernel_extensions.rb +2 -0
- data/lib/rake_docker/output.rb +82 -25
- data/lib/rake_docker/task_sets/container.rb +3 -1
- data/lib/rake_docker/task_sets/image.rb +2 -0
- data/lib/rake_docker/task_sets.rb +2 -0
- data/lib/rake_docker/tasks/build.rb +23 -16
- data/lib/rake_docker/tasks/clean.rb +6 -4
- data/lib/rake_docker/tasks/destroy.rb +9 -6
- data/lib/rake_docker/tasks/prepare.rb +22 -10
- data/lib/rake_docker/tasks/provision.rb +14 -11
- data/lib/rake_docker/tasks/publish.rb +4 -2
- data/lib/rake_docker/tasks/push.rb +8 -6
- data/lib/rake_docker/tasks/tag.rb +11 -9
- data/lib/rake_docker/tasks.rb +2 -0
- data/lib/rake_docker/version.rb +3 -1
- data/lib/rake_docker.rb +2 -0
- data/rake_docker.gemspec +61 -0
- metadata +65 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74b2917e89df4b6d6935df48eb991e0b9a456dc0aa83466086ff0177b59e8759
|
4
|
+
data.tar.gz: 8cd3b2032e20f52ca7eb851b93c5c9a0666e91b7cab8ea283b4f075fb620341c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c7063d0194b5df4b8d0ee5a186ebb3a3599792f04893a21512c6db4a8d2a0b90ec1492dfeb072f6b053302e275b6a4b0100e6ec88c2fcd66029a070667041d0
|
7
|
+
data.tar.gz: 62e598adda11d1e1adfb569cdcd5000bb9d3bf6f27c602121bdddd72f5693e6f0e1f9e9c94d03024c15f7363ca262538419020e4facfed31d7d965040c54890a
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rake_docker (2.18.0.pre.
|
4
|
+
rake_docker (2.18.0.pre.5)
|
5
5
|
aws-sdk-ecr (~> 1.2)
|
6
6
|
colored2 (~> 3.1)
|
7
7
|
docker-api (>= 1.34, < 3.0)
|
@@ -10,27 +10,28 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (7.0.
|
13
|
+
activesupport (7.0.4)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 1.6, < 2)
|
16
16
|
minitest (>= 5.1)
|
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.
|
22
|
-
aws-sdk-core (3.
|
22
|
+
aws-partitions (1.651.0)
|
23
|
+
aws-sdk-core (3.165.1)
|
23
24
|
aws-eventstream (~> 1, >= 1.0.2)
|
24
|
-
aws-partitions (~> 1, >= 1.
|
25
|
+
aws-partitions (~> 1, >= 1.651.0)
|
26
|
+
aws-sigv4 (~> 1.5)
|
27
|
+
jmespath (~> 1, >= 1.6.1)
|
28
|
+
aws-sdk-ecr (1.57.0)
|
29
|
+
aws-sdk-core (~> 3, >= 3.165.0)
|
25
30
|
aws-sigv4 (~> 1.1)
|
26
|
-
|
27
|
-
aws-sdk-ecr (1.55.0)
|
28
|
-
aws-sdk-core (~> 3, >= 3.127.0)
|
29
|
-
aws-sigv4 (~> 1.1)
|
30
|
-
aws-sigv4 (1.4.0)
|
31
|
+
aws-sigv4 (1.5.2)
|
31
32
|
aws-eventstream (~> 1, >= 1.0.2)
|
32
33
|
colored2 (3.1.2)
|
33
|
-
concurrent-ruby (1.1.
|
34
|
+
concurrent-ruby (1.1.10)
|
34
35
|
diff-lcs (1.5.0)
|
35
36
|
docile (1.4.0)
|
36
37
|
docker-api (2.2.0)
|
@@ -63,21 +64,26 @@ GEM
|
|
63
64
|
gem-release (2.2.2)
|
64
65
|
hamster (3.0.0)
|
65
66
|
concurrent-ruby (~> 1.0)
|
66
|
-
i18n (1.
|
67
|
+
i18n (1.12.0)
|
67
68
|
concurrent-ruby (~> 1.0)
|
68
69
|
jmespath (1.6.1)
|
70
|
+
json (2.6.2)
|
69
71
|
lino (3.0.0)
|
70
72
|
hamster (~> 3.0)
|
71
73
|
open4 (~> 1.3)
|
72
74
|
memfs (1.0.0)
|
73
|
-
minitest (5.
|
75
|
+
minitest (5.16.3)
|
74
76
|
multi_json (1.15.0)
|
75
77
|
multipart-post (2.1.1)
|
76
78
|
octokit (4.22.0)
|
77
79
|
faraday (>= 0.9)
|
78
80
|
sawyer (~> 0.8.0, >= 0.5.3)
|
79
81
|
open4 (1.3.4)
|
82
|
+
parallel (1.22.1)
|
83
|
+
parser (3.1.2.1)
|
84
|
+
ast (~> 2.4.1)
|
80
85
|
public_suffix (4.0.6)
|
86
|
+
rainbow (3.1.1)
|
81
87
|
rake (13.0.6)
|
82
88
|
rake_circle_ci (0.9.0)
|
83
89
|
colored2 (~> 3.1)
|
@@ -99,19 +105,38 @@ GEM
|
|
99
105
|
colored2 (~> 3.1)
|
100
106
|
rake_factory (~> 0.23)
|
101
107
|
sshkey (~> 2.0)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
rspec-
|
106
|
-
|
107
|
-
rspec-
|
108
|
-
rspec-
|
108
|
+
regexp_parser (2.6.0)
|
109
|
+
rexml (3.2.5)
|
110
|
+
rspec (3.12.0)
|
111
|
+
rspec-core (~> 3.12.0)
|
112
|
+
rspec-expectations (~> 3.12.0)
|
113
|
+
rspec-mocks (~> 3.12.0)
|
114
|
+
rspec-core (3.12.0)
|
115
|
+
rspec-support (~> 3.12.0)
|
116
|
+
rspec-expectations (3.12.0)
|
109
117
|
diff-lcs (>= 1.2.0, < 2.0)
|
110
|
-
rspec-support (~> 3.
|
111
|
-
rspec-mocks (3.
|
118
|
+
rspec-support (~> 3.12.0)
|
119
|
+
rspec-mocks (3.12.0)
|
112
120
|
diff-lcs (>= 1.2.0, < 2.0)
|
113
|
-
rspec-support (~> 3.
|
114
|
-
rspec-support (3.
|
121
|
+
rspec-support (~> 3.12.0)
|
122
|
+
rspec-support (3.12.0)
|
123
|
+
rubocop (1.36.0)
|
124
|
+
json (~> 2.3)
|
125
|
+
parallel (~> 1.10)
|
126
|
+
parser (>= 3.1.2.1)
|
127
|
+
rainbow (>= 2.2.2, < 4.0)
|
128
|
+
regexp_parser (>= 1.8, < 3.0)
|
129
|
+
rexml (>= 3.2.5, < 4.0)
|
130
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
131
|
+
ruby-progressbar (~> 1.7)
|
132
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
133
|
+
rubocop-ast (1.23.0)
|
134
|
+
parser (>= 3.1.1.0)
|
135
|
+
rubocop-rake (0.6.0)
|
136
|
+
rubocop (~> 1.0)
|
137
|
+
rubocop-rspec (2.14.2)
|
138
|
+
rubocop (~> 1.33)
|
139
|
+
ruby-progressbar (1.11.0)
|
115
140
|
ruby2_keywords (0.0.5)
|
116
141
|
ruby_gpg2 (0.8.0)
|
117
142
|
lino (>= 1.5)
|
@@ -125,8 +150,9 @@ GEM
|
|
125
150
|
simplecov-html (0.12.3)
|
126
151
|
simplecov_json_formatter (0.1.4)
|
127
152
|
sshkey (2.0.0)
|
128
|
-
tzinfo (2.0.
|
153
|
+
tzinfo (2.0.5)
|
129
154
|
concurrent-ruby (~> 1.0)
|
155
|
+
unicode-display_width (2.3.0)
|
130
156
|
|
131
157
|
PLATFORMS
|
132
158
|
ruby
|
@@ -143,7 +169,10 @@ DEPENDENCIES
|
|
143
169
|
rake_gpg
|
144
170
|
rake_ssh
|
145
171
|
rspec
|
172
|
+
rubocop
|
173
|
+
rubocop-rake
|
174
|
+
rubocop-rspec
|
146
175
|
simplecov
|
147
176
|
|
148
177
|
BUNDLED WITH
|
149
|
-
2.3.
|
178
|
+
2.3.24
|
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 :
|
10
|
-
|
11
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
27
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
42
|
-
|
62
|
+
namespace: :circle_ci,
|
63
|
+
project_slug: 'github/infrablocks/rake_docker'
|
43
64
|
) do |t|
|
44
65
|
circle_ci_config =
|
45
|
-
|
66
|
+
YAML.load_file('config/secrets/circle_ci/config.yaml')
|
46
67
|
|
47
|
-
t.api_token = circle_ci_config[
|
68
|
+
t.api_token = circle_ci_config['circle_ci_api_token']
|
48
69
|
t.environment_variables = {
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
57
|
-
|
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
|
-
|
64
|
-
|
84
|
+
namespace: :github,
|
85
|
+
repository: 'infrablocks/rake_docker'
|
65
86
|
) do |t, args|
|
66
87
|
github_config =
|
67
|
-
|
88
|
+
YAML.load_file('config/secrets/github/config.yaml')
|
68
89
|
|
69
|
-
t.access_token = github_config[
|
90
|
+
t.access_token = github_config['github_personal_access_token']
|
70
91
|
t.deploy_keys = [
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
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
|
119
|
+
desc 'Release gem'
|
98
120
|
task :release do
|
99
|
-
sh
|
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
|
-
|
105
|
-
|
106
|
-
|
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
|
4
|
-
require
|
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
|
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
|
8
|
-
@config =
|
9
|
-
|
10
|
-
|
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
|
-
|
31
|
-
|
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
|
-
|
35
|
-
|
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,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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
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
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
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
|
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
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
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.
|
241
|
-
|
242
|
-
|
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
|
-
|
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
|
-
|
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
|