capistrano-nomad 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/capistrano-nomad.gemspec +1 -1
- data/lib/capistrano/nomad/helpers/base.rb +1 -1
- data/lib/capistrano/nomad/helpers/docker.rb +50 -49
- data/lib/capistrano/nomad/helpers/nomad.rb +8 -4
- data/lib/capistrano/nomad.rb +1 -0
- metadata +2 -3
- data/sig/capistrano/nomad.rbs +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: decb45a7958cc1a3b2bc96d8d48e72ff6132d160eac93e81e995b59661dfc5ff
|
|
4
|
+
data.tar.gz: adaf5bb0a848328cfd830f861b1f8ff744e46bba6eab66f9180fdd21f1bad57b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cac6624d0caceedcd3ac833d87a3a498d0a023b74d604b626413df62f15e107324a538035d93e9a39800eba57dddca4b6a70a8bd4825fed99a002411634254a5
|
|
7
|
+
data.tar.gz: 3a622b2f506d8a3d98f5c97646fa6da662b8b6ea86e86c9e315c10a62ef4f88acd7befc7f22167f52b8de3b0d9ea9fc8dfccf5924da7da74a061f3b1ba450ea8
|
data/Gemfile.lock
CHANGED
data/capistrano-nomad.gemspec
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
class CapistranoNomadDockerPushImageInteractionHandler
|
|
2
|
+
def initialize(*args)
|
|
3
|
+
@last_digest = nil
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def on_data(_command, stream_name, data, channel)
|
|
7
|
+
if (match = data.match(/digest: ([^\s]+)/))
|
|
8
|
+
@last_digest = match[1]
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def last_digest
|
|
13
|
+
@last_digest
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
1
17
|
def capistrano_nomad_docker_image_types_manifest_path
|
|
2
18
|
shared_path.join("docker-image-types.json")
|
|
3
19
|
end
|
|
@@ -10,7 +26,7 @@ def capistrano_nomad_read_docker_image_types_manifest
|
|
|
10
26
|
execute("mkdir -p #{shared_path}")
|
|
11
27
|
execute("touch #{capistrano_nomad_docker_image_types_manifest_path}")
|
|
12
28
|
|
|
13
|
-
output = capture
|
|
29
|
+
output = capture("cat #{capistrano_nomad_docker_image_types_manifest_path}")
|
|
14
30
|
|
|
15
31
|
unless output.blank?
|
|
16
32
|
manifest = JSON.parse(output)
|
|
@@ -33,52 +49,23 @@ def capistrano_nomad_update_docker_image_types_manifest(image_type, properties =
|
|
|
33
49
|
end
|
|
34
50
|
end
|
|
35
51
|
|
|
36
|
-
def capistrano_nomad_build_docker_image_alias(image_type
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
end
|
|
52
|
+
def capistrano_nomad_build_docker_image_alias(image_type)
|
|
53
|
+
image_alias = fetch(:nomad_docker_image_types).dig(image_type, :alias)
|
|
54
|
+
image_alias = image_alias.call(image_type: image_type) if image_alias&.is_a?(Proc)
|
|
40
55
|
|
|
41
|
-
|
|
42
|
-
def current_docker_service_image_alias(image_type)
|
|
43
|
-
image_alias =
|
|
44
|
-
capistrano_nomad_read_docker_image_types_manifest
|
|
45
|
-
.try(:[], image_type.to_sym)
|
|
46
|
-
.try(:[], :image_alias)
|
|
56
|
+
raise StandardError, ":alias not defined for #{image_type}" unless image_alias
|
|
47
57
|
|
|
48
|
-
|
|
58
|
+
# Add :latest if there's no tag
|
|
59
|
+
image_alias << ":latest" if image_alias.split(":").count == 1
|
|
49
60
|
|
|
50
|
-
|
|
61
|
+
image_alias
|
|
51
62
|
end
|
|
52
63
|
|
|
53
64
|
# Builds docker image from image type
|
|
54
65
|
#
|
|
55
66
|
# @param image_type [String, Symbol]
|
|
56
|
-
def capistrano_nomad_build_docker_image(image_type, path, *args)
|
|
57
|
-
run_locally do
|
|
58
|
-
git_commit_id = capistrano_nomad_fetch_git_commit_id
|
|
59
|
-
|
|
60
|
-
[
|
|
61
|
-
capistrano_nomad_build_docker_image_alias(image_type, git_commit_id),
|
|
62
|
-
capistrano_nomad_build_docker_image_alias(image_type, "latest"),
|
|
63
|
-
"trunk/#{fetch(:stage)}/#{image_type}:latest",
|
|
64
|
-
]
|
|
65
|
-
.compact
|
|
66
|
-
.each do |tag|
|
|
67
|
-
args << "--tag #{tag}"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# If any of these files exist then we're in the middle of rebase so we should interrupt
|
|
71
|
-
if ["rebase-merge", "rebase-apply"].any? { |f| File.exist?("#{capistrano_nomad_git.dir.path}/.git/#{f}") }
|
|
72
|
-
raise StandardError, "still in the middle of git rebase, interrupting docker image build"
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
system "docker build #{args.join(' ')} .#{capistrano_nomad_root.join(path)}"
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
67
|
def capistrano_nomad_build_docker_image_for_type(image_type)
|
|
80
68
|
image_type = image_type.to_sym
|
|
81
|
-
|
|
82
69
|
attributes = fetch(:nomad_docker_image_types)[image_type]
|
|
83
70
|
|
|
84
71
|
return unless attributes
|
|
@@ -106,7 +93,22 @@ def capistrano_nomad_build_docker_image_for_type(image_type)
|
|
|
106
93
|
args << "--build-arg #{key}=#{value}"
|
|
107
94
|
end
|
|
108
95
|
|
|
109
|
-
|
|
96
|
+
run_locally do
|
|
97
|
+
# If any of these files exist then we're in the middle of rebase so we should interrupt
|
|
98
|
+
if ["rebase-merge", "rebase-apply"].any? { |f| File.exist?("#{capistrano_nomad_git.dir.path}/.git/#{f}") }
|
|
99
|
+
raise StandardError, "Still in the middle of git rebase, interrupting docker image build"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
image_alias_args = args.dup
|
|
103
|
+
|
|
104
|
+
[capistrano_nomad_build_docker_image_alias(image_type)]
|
|
105
|
+
.compact
|
|
106
|
+
.each do |tag|
|
|
107
|
+
image_alias_args << "--tag #{tag}"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
execute("docker build #{image_alias_args.join(' ')} .#{capistrano_nomad_root.join(attributes[:path])}")
|
|
111
|
+
end
|
|
110
112
|
end
|
|
111
113
|
|
|
112
114
|
def capistrano_nomad_push_docker_image_for_type(image_type, is_manifest_updated: true)
|
|
@@ -114,23 +116,22 @@ def capistrano_nomad_push_docker_image_for_type(image_type, is_manifest_updated:
|
|
|
114
116
|
invoke("nomad:docker_images:push")
|
|
115
117
|
|
|
116
118
|
run_locally do
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
unless system("docker push #{image_alias}")
|
|
124
|
-
raise StandardError, "Docker image push unsuccessful!"
|
|
125
|
-
end
|
|
119
|
+
interaction_handler = CapistranoNomadDockerPushImageInteractionHandler.new
|
|
120
|
+
image_alias = capistrano_nomad_build_docker_image_alias(image_type)
|
|
121
|
+
|
|
122
|
+
# We should not proceed if image cannot be pushed
|
|
123
|
+
unless execute("docker push #{image_alias}", interaction_handler: interaction_handler)
|
|
124
|
+
raise StandardError, "Docker image push unsuccessful!"
|
|
126
125
|
end
|
|
127
126
|
|
|
128
127
|
return unless is_manifest_updated
|
|
129
128
|
|
|
130
129
|
# Update image type manifest
|
|
131
130
|
capistrano_nomad_update_docker_image_types_manifest(image_type,
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
alias: image_alias,
|
|
132
|
+
|
|
133
|
+
# Has the @sha256:xxxx appended so we have the ability to also target by digest
|
|
134
|
+
alias_digest: "#{image_alias}@#{interaction_handler.last_digest}",
|
|
134
135
|
)
|
|
135
136
|
end
|
|
136
137
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require "active_support/core_ext/string"
|
|
2
2
|
require "sshkit/interactive"
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class CapistranoNomadErbNamespace
|
|
5
5
|
def initialize(context:, vars: {})
|
|
6
6
|
@context = context
|
|
7
7
|
|
|
@@ -55,7 +55,11 @@ def capistrano_nomad_build_local_path(path, *args)
|
|
|
55
55
|
local_path = ".#{capistrano_nomad_root.join(path)}"
|
|
56
56
|
|
|
57
57
|
# Determine if it has .erb appended or not
|
|
58
|
-
[local_path, "#{local_path}.erb"].find { |path| File.exist?(path) }
|
|
58
|
+
found_local_path = [local_path, "#{local_path}.erb"].find { |path| File.exist?(path) }
|
|
59
|
+
|
|
60
|
+
raise StandardError, "Could not find local path: #{path}" unless found_local_path
|
|
61
|
+
|
|
62
|
+
found_local_path
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
def capistrano_nomad_build_local_job_path(name, *args)
|
|
@@ -130,7 +134,7 @@ def capistrano_nomad_upload_file(local_path:, remote_path:, erb_vars: {})
|
|
|
130
134
|
|
|
131
135
|
# We use a custom namespace class so that we can include helper methods into the namespace to make them available for
|
|
132
136
|
# template to access
|
|
133
|
-
namespace =
|
|
137
|
+
namespace = CapistranoNomadErbNamespace.new(
|
|
134
138
|
context: self,
|
|
135
139
|
vars: final_erb_vars,
|
|
136
140
|
)
|
|
@@ -155,7 +159,7 @@ def capistrano_nomad_fetch_jobs_names_by_namespace
|
|
|
155
159
|
end
|
|
156
160
|
|
|
157
161
|
def capistrano_nomad_fetch_jobs_docker_image_types(names, namespace: nil)
|
|
158
|
-
names.map { |n| fetch(:nomad_jobs).dig(namespace, n.to_sym, :
|
|
162
|
+
names.map { |n| fetch(:nomad_jobs).dig(namespace, n.to_sym, :docker_image_types) }.flatten.compact.uniq
|
|
159
163
|
end
|
|
160
164
|
|
|
161
165
|
def capistrano_nomad_build_jobs_docker_images(names, *args)
|
data/lib/capistrano/nomad.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capistrano-nomad
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Hu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-10-
|
|
11
|
+
date: 2023-10-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -129,7 +129,6 @@ files:
|
|
|
129
129
|
- lib/capistrano/nomad/helpers/nomad.rb
|
|
130
130
|
- lib/capistrano/nomad/scm/git_local.rb
|
|
131
131
|
- lib/capistrano/nomad/tasks/nomad.rake
|
|
132
|
-
- sig/capistrano/nomad.rbs
|
|
133
132
|
homepage: https://github.com/axsuul/capistrano-nomad
|
|
134
133
|
licenses:
|
|
135
134
|
- MIT
|