capistrano-nomad 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +6 -6
- data/capistrano-nomad.gemspec +1 -1
- data/lib/capistrano/nomad/helpers/dsl.rb +3 -0
- data/lib/capistrano/nomad/helpers/nomad.rb +45 -37
- data/lib/capistrano/nomad/tasks/nomad.rake +23 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9993fb04b78b68b03c055faa66454360543c92108f2e410f7156bedf7158f763
|
4
|
+
data.tar.gz: 20b4708abc11215f259bc46b8b4c7f4f0606fb0d2ff7e3c862c799b850ead5ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86d6750e7e181d120db5b56da6c5b7b083310901939e452aee8e7a6de12db22544f2c1accfe8fb9790c75c188644ed0108446a8281875566b0d6243ae8db6191
|
7
|
+
data.tar.gz: f80d0003e093e3ed5e0fefc69b6b89db158064145c7c21573944b8fc88f8beb40a1cb0b40fbbbb956856bbc637f217a72001c5a1de10ed992ea46e6fd45b8809
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -134,15 +134,15 @@ cap production nomad:analytics:grafana:restart
|
|
134
134
|
cap production nomad:postgres:status
|
135
135
|
```
|
136
136
|
|
137
|
-
Tasks can
|
137
|
+
Tasks can apply across all namespaces or be filtered by namespaces or tags
|
138
138
|
|
139
139
|
```shell
|
140
140
|
cap production nomad:analytics:deploy
|
141
141
|
cap production nomad:analytics:upload_run
|
142
|
-
cap production nomad:
|
143
|
-
cap production nomad:
|
144
|
-
cap production nomad:
|
145
|
-
cap production nomad:
|
142
|
+
cap production nomad:deploy
|
143
|
+
cap production nomad:deploy TAG=admin
|
144
|
+
cap production nomad:upload_run
|
145
|
+
cap production nomad:upload_run TAGS=admin,redis
|
146
146
|
```
|
147
147
|
|
148
148
|
Open console
|
@@ -171,7 +171,7 @@ cap production nomad:app:ui
|
|
171
171
|
Create missing and delete unused namespaces
|
172
172
|
|
173
173
|
```shell
|
174
|
-
cap production nomad:
|
174
|
+
cap production nomad:modify_namespaces
|
175
175
|
```
|
176
176
|
|
177
177
|
## Development
|
data/capistrano-nomad.gemspec
CHANGED
@@ -36,6 +36,9 @@ def nomad_namespace(namespace, **options, &block)
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def nomad_job(name, attributes = {})
|
39
|
+
# This is the namespace when there's no namespace defined in Nomad too
|
40
|
+
@nomad_namespace ||= :default
|
41
|
+
|
39
42
|
attributes[:tags] ||= []
|
40
43
|
|
41
44
|
# Tags added to namespace should be added to all jobs within
|
@@ -254,7 +254,7 @@ def capistrano_nomad_fetch_job_var_files(name, *args)
|
|
254
254
|
capistrano_nomad_fetch_job_options(name, :var_files, *args) || []
|
255
255
|
end
|
256
256
|
|
257
|
-
def capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
257
|
+
def capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nil)
|
258
258
|
# Can pass tags via command line (e.g. TAG=foo or TAGS=foo,bar)
|
259
259
|
tags =
|
260
260
|
[ENV["TAG"], ENV["TAGS"]].map do |tag_args|
|
@@ -266,7 +266,7 @@ def capistrano_nomad_fetch_jobs_names_by_namespace(namespace: :all)
|
|
266
266
|
.compact
|
267
267
|
|
268
268
|
fetch(:nomad_jobs).each_with_object({}) do |(jobs_namespace, jobs_options), hash|
|
269
|
-
next if namespace
|
269
|
+
next if !namespace.nil? && namespace != jobs_namespace
|
270
270
|
|
271
271
|
hash[jobs_namespace] = jobs_options.each_with_object([]) do |(job_name, job_options), collection|
|
272
272
|
# Filter jobs by tags if specified
|
@@ -281,85 +281,93 @@ def capistrano_nomad_fetch_jobs_docker_image_types(names, namespace: nil)
|
|
281
281
|
names.map { |n| fetch(:nomad_jobs).dig(namespace, n.to_sym, :docker_image_types) }.flatten.compact.uniq
|
282
282
|
end
|
283
283
|
|
284
|
-
def capistrano_nomad_define_group_tasks(namespace:)
|
285
|
-
|
286
|
-
desc "Build #{
|
284
|
+
def capistrano_nomad_define_group_tasks(namespace: nil)
|
285
|
+
define_tasks = lambda do |nomad_namespace: nil|
|
286
|
+
desc "Build #{nomad_namespace} job Docker images"
|
287
287
|
task :build do
|
288
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
289
|
-
capistrano_nomad_push_jobs_docker_images(names, namespace:
|
288
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
289
|
+
capistrano_nomad_push_jobs_docker_images(names, namespace: jobs_namespace)
|
290
290
|
end
|
291
291
|
end
|
292
292
|
|
293
|
-
desc "Push #{
|
293
|
+
desc "Push #{nomad_namespace} job Docker images"
|
294
294
|
task :push do
|
295
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
296
|
-
capistrano_nomad_push_jobs_docker_images(names, namespace:
|
295
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
296
|
+
capistrano_nomad_push_jobs_docker_images(names, namespace: jobs_namespace)
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
|
-
desc "Build and push #{
|
300
|
+
desc "Build and push #{nomad_namespace} job Docker images"
|
301
301
|
task :assemble do
|
302
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
303
|
-
capistrano_nomad_assemble_jobs_docker_images(names, namespace:
|
302
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
303
|
+
capistrano_nomad_assemble_jobs_docker_images(names, namespace: jobs_namespace)
|
304
304
|
end
|
305
305
|
end
|
306
306
|
|
307
|
-
desc "Upload #{
|
307
|
+
desc "Upload #{nomad_namespace} jobs"
|
308
308
|
task :upload do
|
309
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
310
|
-
capistrano_nomad_upload_jobs(names, namespace:
|
309
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
310
|
+
capistrano_nomad_upload_jobs(names, namespace: jobs_namespace)
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
314
|
-
desc "Run #{
|
314
|
+
desc "Run #{nomad_namespace} jobs"
|
315
315
|
task :run do
|
316
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
317
|
-
capistrano_nomad_run_jobs(names, namespace:
|
316
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
317
|
+
capistrano_nomad_run_jobs(names, namespace: jobs_namespace)
|
318
318
|
end
|
319
319
|
end
|
320
320
|
|
321
|
-
desc "Upload and run #{
|
321
|
+
desc "Upload and run #{nomad_namespace} jobs"
|
322
322
|
task :upload_run do
|
323
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
324
|
-
capistrano_nomad_upload_run_jobs(names, namespace:
|
323
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
324
|
+
capistrano_nomad_upload_run_jobs(names, namespace: jobs_namespace)
|
325
325
|
end
|
326
326
|
end
|
327
327
|
|
328
|
-
desc "Deploy #{
|
328
|
+
desc "Deploy #{nomad_namespace} jobs"
|
329
329
|
task :deploy do
|
330
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
331
|
-
capistrano_nomad_deploy_jobs(names, namespace:
|
330
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
331
|
+
capistrano_nomad_deploy_jobs(names, namespace: jobs_namespace)
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
335
|
-
desc "Rerun #{
|
335
|
+
desc "Rerun #{nomad_namespace} jobs"
|
336
336
|
task :rerun do
|
337
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
338
|
-
capistrano_nomad_rerun_jobs(names, namespace:
|
337
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
338
|
+
capistrano_nomad_rerun_jobs(names, namespace: jobs_namespace)
|
339
339
|
end
|
340
340
|
end
|
341
341
|
|
342
|
-
desc "Restart #{
|
342
|
+
desc "Restart #{nomad_namespace} jobs"
|
343
343
|
task :restart do
|
344
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
345
|
-
capistrano_nomad_restart_jobs(names, namespace:
|
344
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
345
|
+
capistrano_nomad_restart_jobs(names, namespace: jobs_namespace)
|
346
346
|
end
|
347
347
|
end
|
348
348
|
|
349
|
-
desc "Stop #{
|
349
|
+
desc "Stop #{nomad_namespace} jobs"
|
350
350
|
task :stop do
|
351
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
352
|
-
capistrano_nomad_stop_jobs(names, namespace:
|
351
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
352
|
+
capistrano_nomad_stop_jobs(names, namespace: jobs_namespace)
|
353
353
|
end
|
354
354
|
end
|
355
355
|
|
356
|
-
desc "Purge #{
|
356
|
+
desc "Purge #{nomad_namespace} jobs"
|
357
357
|
task :purge do
|
358
|
-
capistrano_nomad_fetch_jobs_names_by_namespace(namespace:
|
359
|
-
capistrano_nomad_purge_jobs(names, namespace:
|
358
|
+
capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
|
359
|
+
capistrano_nomad_purge_jobs(names, namespace: jobs_namespace)
|
360
360
|
end
|
361
361
|
end
|
362
362
|
end
|
363
|
+
|
364
|
+
if namespace
|
365
|
+
namespace(namespace) do
|
366
|
+
define_tasks.call(nomad_namespace: namespace)
|
367
|
+
end
|
368
|
+
else
|
369
|
+
define_tasks.call
|
370
|
+
end
|
363
371
|
end
|
364
372
|
|
365
373
|
def capistrano_nomad_build_jobs_docker_images(names, *args)
|
@@ -1,46 +1,37 @@
|
|
1
1
|
namespace :nomad do
|
2
|
-
desc "Show version"
|
3
|
-
task :version do
|
4
|
-
capistrano_nomad_execute_nomad_command(:version)
|
5
|
-
end
|
6
|
-
|
7
2
|
# Define tasks for all jobs
|
8
|
-
capistrano_nomad_define_group_tasks
|
3
|
+
capistrano_nomad_define_group_tasks
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
current_namespaces = output.split("|").compact.map(&:to_sym)
|
5
|
+
desc "Create missing and remove unused namespaces"
|
6
|
+
task :modify_namespaces do
|
7
|
+
output = capistrano_nomad_capture_nomad_command(:namespace, :list, t: "'{{range .}}{{ .Name }}|{{end}}'")
|
8
|
+
current_namespaces = output.split("|").compact.map(&:to_sym)
|
15
9
|
|
16
|
-
|
17
|
-
|
10
|
+
# If key is nil then it actually belongs to the default namespace
|
11
|
+
desired_namespaces = fetch(:nomad_jobs).keys.map { |n| n.nil? ? :default : n.to_sym }
|
18
12
|
|
19
|
-
|
20
|
-
|
13
|
+
missing_namespaces = desired_namespaces - current_namespaces
|
14
|
+
unused_namespaces = current_namespaces - desired_namespaces
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
# Remove unused namespaces
|
17
|
+
unused_namespaces.each do |namespace|
|
18
|
+
capistrano_nomad_execute_nomad_command(:namespace, :delete, namespace)
|
19
|
+
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
21
|
+
# Create missing namespaces
|
22
|
+
missing_namespaces.each do |namespace|
|
23
|
+
capistrano_nomad_execute_nomad_command(:namespace, :apply, namespace)
|
31
24
|
end
|
32
25
|
end
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
desc "Run garbage collector tasks"
|
28
|
+
task :gc do
|
29
|
+
capistrano_nomad_execute_nomad_command(:system, :gc)
|
30
|
+
capistrano_nomad_execute_nomad_command(:system, :reconcile, :summaries)
|
37
31
|
end
|
38
32
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
capistrano_nomad_execute_nomad_command(:system, :gc)
|
43
|
-
capistrano_nomad_execute_nomad_command(:system, :reconcile, :summaries)
|
44
|
-
end
|
33
|
+
desc "Show version"
|
34
|
+
task :version do
|
35
|
+
capistrano_nomad_execute_nomad_command(:version)
|
45
36
|
end
|
46
37
|
end
|