capistrano-docker_cluster 1.0.5 → 1.0.6

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: ebbb1defa7363b3977d59a8086513972c4a0258a4e3766b4de6c306f5beee4ed
4
- data.tar.gz: 49e0318d6ef793cbe74351bfcce166e456aabd28347c430917b44bd836fca518
3
+ metadata.gz: ec723926c7aa3eff8fd1881623c844c3dc9227861233a0d06165aa6e67027e00
4
+ data.tar.gz: 071c150e5e27d974f8382d37468dad6ef13161ee23bb848512ca3d582213776d
5
5
  SHA512:
6
- metadata.gz: 44497d8dd8ab30ac78b15362e7ecf8e5081a238804034273e183d5811a6ba4e5189a93f9db486672bd1708ce7b325ad6ec5e1894bddda4d5e6d6b6a117789e43
7
- data.tar.gz: 7cdd4315f6a9cface2ee10216f7e7376a9d1dbbd21efd20b6a6b104b21c72ca4635e3bd0829bdf77e3f1dae6dc9117b5bb340f75d4e7f14e4755032e9dd3f8f0
6
+ metadata.gz: 186ffdb3cd72c0f0710fb99b329bf6cf003df5e75c25d2f1c9a97f062df10c9cbe5c937b499a934c18b65200b96d58d000a84d676f72886e6312061c78388c75
7
+ data.tar.gz: e9b5246df144de6550eab34bc11df997cda612af7e375b7fa7808b14a2378da160885f7dfb2b9ddb908658b679a6d3660225e10ccb6ba3d75f32b486527ff747
@@ -1,3 +1,9 @@
1
+ # 1.0.6
2
+
3
+ * Store docker image url in release directory.
4
+ * Add support to pull the docker image on rollback.
5
+ * Use docker tags in scripts instead of image ids.
6
+
1
7
  # 1.0.5
2
8
 
3
9
  * Add "--no-" prefix on arguments to remove them.
@@ -15,7 +15,7 @@ module Capistrano
15
15
  def start_script(host)
16
16
  apps = Array(fetch_for_host(host, :docker_apps))
17
17
  cmd = "exec bin/docker-cluster"
18
- image_id = fetch(:docker_image_id)
18
+ image_id = "#{fetch(:docker_repository)}:#{fetch(:docker_tag)}"
19
19
  prefix = fetch(:docker_prefix)
20
20
 
21
21
  cases = []
@@ -28,7 +28,7 @@ module Capistrano
28
28
  #!/usr/bin/env bash
29
29
 
30
30
  # Generated: #{Time.now.utc.iso8601}
31
- # Docker image tag: #{fetch(:docker_repository)}/#{fetch(:docker_tag)}
31
+ # Docker image tag: #{fetch(:docker_repository)}:#{fetch(:docker_tag)}
32
32
 
33
33
  set -o errexit
34
34
 
@@ -59,7 +59,7 @@ module Capistrano
59
59
  apps = apps.collect(&:to_s).uniq
60
60
 
61
61
  cmd = "exec bin/docker-cluster"
62
- image_id = fetch(:docker_image_id)
62
+ image_id = "#{fetch(:docker_repository)}:#{fetch(:docker_tag)}"
63
63
 
64
64
  cases = []
65
65
  apps.each do |app|
@@ -71,7 +71,7 @@ module Capistrano
71
71
  #!/usr/bin/env bash
72
72
 
73
73
  # Generated: #{Time.now.utc.iso8601}
74
- # Docker image tag: #{fetch(:docker_repository)}/#{fetch(:docker_tag)}
74
+ # Docker image tag: #{fetch(:docker_repository)}:#{fetch(:docker_tag)}
75
75
 
76
76
  set -o errexit
77
77
 
@@ -104,7 +104,7 @@ module Capistrano
104
104
  #!/usr/bin/env bash
105
105
 
106
106
  # Generated: #{Time.now.utc.iso8601}
107
- # Docker image tag: #{fetch(:docker_repository)}/#{fetch(:docker_tag)}
107
+ # Docker image tag: #{fetch(:docker_repository)}:#{fetch(:docker_tag)}
108
108
 
109
109
  set -o errexit
110
110
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capistrano
4
4
  module DockerCluster
5
- VERSION = "1.0.5"
5
+ VERSION = "1.0.6"
6
6
  end
7
7
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "shellwords"
4
+
3
5
  set :docker_roles, [:docker]
4
6
 
5
7
  def as_docker_user
@@ -17,9 +19,14 @@ end
17
19
 
18
20
  namespace :deploy do
19
21
  after :new_release_path, "docker:create_release"
22
+
20
23
  after :updating, "docker:update"
24
+
21
25
  after :published, "docker:restart"
22
26
 
27
+ after :reverted, "docker:revert_image"
28
+
29
+ # Required to be defined
23
30
  task :upload do
24
31
  end
25
32
  end
@@ -32,17 +39,7 @@ namespace :docker do
32
39
  end
33
40
 
34
41
  if fetch(:docker_repository).include?("/")
35
- invoke "docker:pull"
36
- end
37
- end
38
-
39
- task :set_image_id => :build do
40
- on release_roles(fetch(:docker_roles)).first do
41
- docker_tag_url = "#{fetch(:docker_repository)}:#{fetch(:docker_tag)}"
42
- as_docker_user do
43
- image_id = capture(:docker, "image", "ls", "--no-trunc", "--format", "'{{.ID}}'", docker_tag_url)
44
- set :docker_image_id, image_id[7, 12]
45
- end
42
+ invoke "docker:pull"
46
43
  end
47
44
  end
48
45
 
@@ -51,12 +48,13 @@ namespace :docker do
51
48
  end
52
49
 
53
50
  desc "Update the configuration and command line arguments for running a docker deployment."
54
- task :update => :set_image_id do
51
+ task :update do
55
52
  invoke("docker:copy_configs")
56
53
  invoke("docker:upload_commands")
54
+ invoke("docker:remove_revision")
57
55
  end
58
56
 
59
- desc "Prune the docker engine of all dangling images, containers, and volumes."
57
+ desc "Prune the docker engine of all dangling images, containers, and networks."
60
58
  task :prune do
61
59
  on release_roles(fetch(:docker_roles)) do |host|
62
60
  as_docker_user do
@@ -65,15 +63,51 @@ namespace :docker do
65
63
  end
66
64
  end
67
65
 
68
- desc "Pull a tag from a remote into the local docker engine. If the task docker:authenticate is defined, it will be invoked first."
69
- task :pull do
70
- docker_tag_url = "#{fetch(:docker_repository)}:#{fetch(:docker_tag)}"
71
- if Rake::Task.task_defined?('docker:authenticate')
72
- invoke "docker:authenticate"
66
+ desc "Pull the tagged docker image from a remote repository into the local docker engine."
67
+ task :pull => :authenticate do
68
+ docker_image_url = "#{fetch(:docker_repository)}:#{fetch(:docker_tag)}"
69
+ on release_roles(fetch(:docker_roles)) do |host|
70
+ within(release_path) do
71
+ as_docker_user do
72
+ docker_info = capture(:docker, "pull", docker_image_url)
73
+ digest = docker_info.match(/Digest: (sha256:[0-9a-f]+)/)
74
+ if digest
75
+ execute :echo, "'#{fetch(:docker_repository)}@#{digest[1]}' > DOCKER_IMAGE_URL"
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ desc "Pull the pinned docker image from the current release and tag it."
83
+ task :revert_image => :authenticate do
84
+ on release_roles(fetch(:docker_roles)) do |host|
85
+ within "#{fetch(:deploy_to)}/current" do
86
+ as_docker_user do
87
+ docker_image_url = capture(:cat, "DOCKER_IMAGE_URL")
88
+ if docker_image_url.include?("/")
89
+ execute :docker, "pull", docker_image_url
90
+ end
91
+ execute :docker, "tag", docker_image_url, "#{fetch(:docker_repository)}:#{fetch(:docker_tag)}"
92
+ end
93
+ end
73
94
  end
95
+ end
96
+
97
+ desc "You must implement the docker:authenticate task if your respository requires credentials."
98
+ task :authenticate do
99
+ end
100
+
101
+ desc "Remove the revision file if it contains placeholder text"
102
+ task :remove_revision do
74
103
  on release_roles(fetch(:docker_roles)) do |host|
75
- as_docker_user do
76
- execute :docker, "pull", docker_tag_url
104
+ within(release_path) do
105
+ if test("[ -f #{Shellwords.escape(release_path)}/REVISION ]")
106
+ revision = capture(:cat, "REVISION")
107
+ if revision.include?(" ")
108
+ execute :rm, "REVISION"
109
+ end
110
+ end
77
111
  end
78
112
  end
79
113
  end
@@ -130,13 +164,11 @@ namespace :docker do
130
164
  desc "Copy configuration files used to start the docker containers."
131
165
  task :copy_configs do
132
166
  on release_roles(fetch(:docker_roles)) do |host|
133
- configs = Capistrano::DockerCluster::Scripts.new(self).docker_config_map(host)
134
- unless configs.empty?
135
- within fetch(:release_path) do
136
- execute(:mkdir, "-p", "config")
137
- configs.each do |name, local_path|
138
- upload! local_path, "config/#{name}"
139
- end
167
+ within fetch(:release_path) do
168
+ configs = Capistrano::DockerCluster::Scripts.new(self).docker_config_map(host)
169
+ execute(:mkdir, "-p", "config")
170
+ configs.each do |name, local_path|
171
+ upload! local_path, "config/#{name}"
140
172
  end
141
173
  end
142
174
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-docker_cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-08 00:00:00.000000000 Z
11
+ date: 2020-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano