capistrano-nomad 0.5.0 → 0.5.1
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/dsl.rb +9 -6
- data/lib/capistrano/nomad/helpers/nomad.rb +48 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b71f2fc4375d471be5284038182715e6a4673dfb047b24f94409d9249509706
|
4
|
+
data.tar.gz: 04d0c5906845f755b6c265b8f3ff943a3dcff1b2d4d4df66591f3e9aacb80063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3417e1276e5e377db5e52051c39f5955a3ba50cd83243e51d6f1a2919d2e4eda7a602ee55bab9a0c91f4e4d85fc4505c18886e8164608515bc681b663d641b60
|
7
|
+
data.tar.gz: 66fbf60d498d0b312256a6788292c9c5ad9e84384c34152e0d000c2045267bae57b96483cdd894f0f5a5f138ba3b89c179c2d265b8eebb4c29c3a496918ed19c
|
data/Gemfile.lock
CHANGED
data/capistrano-nomad.gemspec
CHANGED
@@ -90,15 +90,18 @@ def nomad_job(name, attributes = {})
|
|
90
90
|
|
91
91
|
desc "Restart #{description_name} job"
|
92
92
|
task :restart do
|
93
|
-
on
|
93
|
+
on(roles(:manager)) do
|
94
94
|
# We can't restart the job directly so we'll need to fetch all its running allocs and restart each of one
|
95
95
|
# individually instead
|
96
|
-
running_alloc_ids_output =
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
running_alloc_ids_output = capistrano_nomad_capture_nomad_command(
|
97
|
+
:job,
|
98
|
+
:allocs,
|
99
|
+
{
|
100
|
+
namespace: namespace,
|
101
|
+
t: "'{{range .}}{{if eq .ClientStatus \"running\"}}{{ println .ID}}{{end}}{{end}}'",
|
102
|
+
},
|
103
|
+
name,
|
100
104
|
)
|
101
|
-
|
102
105
|
running_alloc_ids = running_alloc_ids_output.strip.split("\n")
|
103
106
|
|
104
107
|
running_alloc_ids.each do |alloc_id|
|
@@ -78,7 +78,7 @@ def capistrano_nomad_build_release_var_file_path(*args)
|
|
78
78
|
"#{release_path}#{capistrano_nomad_build_base_var_file_path(*args)}"
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
81
|
+
def capistrano_nomad_run_nomad_command(kind, *args)
|
82
82
|
converted_args = args.each_with_object([]) do |arg, collection|
|
83
83
|
# If hash then convert it as options
|
84
84
|
if arg.is_a?(Hash)
|
@@ -97,22 +97,60 @@ def capistrano_nomad_execute_nomad_command(*args)
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
# Ignore errors
|
101
|
+
public_send(kind, :nomad, *converted_args, raise_on_non_zero_exit: false)
|
102
|
+
end
|
103
|
+
|
104
|
+
def capistrano_nomad_execute_nomad_command(*args)
|
100
105
|
on(roles(:manager)) do |host|
|
101
106
|
run_interactively(host) do
|
102
|
-
|
103
|
-
execute(:nomad, *converted_args, raise_on_non_zero_exit: false)
|
107
|
+
capistrano_nomad_run_nomad_command(:execute, *args)
|
104
108
|
end
|
105
109
|
end
|
106
110
|
end
|
107
111
|
|
112
|
+
def capistrano_nomad_capture_nomad_command(*args)
|
113
|
+
output = nil
|
114
|
+
|
115
|
+
on(roles(:manager)) do |host|
|
116
|
+
output = capistrano_nomad_run_nomad_command(:capture, *args)
|
117
|
+
end
|
118
|
+
|
119
|
+
output
|
120
|
+
end
|
121
|
+
|
108
122
|
def capistrano_nomad_exec_within_job(name, command, namespace: nil, task: nil)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
123
|
+
on(roles(:manager)) do
|
124
|
+
task = name unless task
|
125
|
+
|
126
|
+
# Find alloc id that contains task
|
127
|
+
output = capistrano_nomad_capture_nomad_command(
|
128
|
+
:job,
|
129
|
+
:allocs,
|
130
|
+
{ namespace: namespace, t: "'{{range .}}{{ .ID }},{{ .TaskGroup }}|{{end}}'" },
|
131
|
+
name,
|
132
|
+
)
|
133
|
+
alloc_id = output.split("|").map { |s| s.split(",") }.find { |_, t| t == task.to_s }&.first
|
134
|
+
|
135
|
+
if alloc_id
|
136
|
+
capistrano_nomad_execute_nomad_command(
|
137
|
+
:alloc,
|
138
|
+
:exec,
|
139
|
+
{ namespace: namespace, task: task },
|
140
|
+
alloc_id,
|
141
|
+
command,
|
142
|
+
)
|
143
|
+
else
|
144
|
+
# If alloc can't be determined then choose at random
|
145
|
+
capistrano_nomad_execute_nomad_command(
|
146
|
+
:alloc,
|
147
|
+
:exec,
|
148
|
+
{ namespace: namespace, job: true },
|
149
|
+
task,
|
150
|
+
command,
|
151
|
+
)
|
152
|
+
end
|
153
|
+
end
|
116
154
|
end
|
117
155
|
|
118
156
|
def capistrano_nomad_upload_file(local_path:, remote_path:, erb_vars: {})
|
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.5.
|
4
|
+
version: 0.5.1
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|