capistrano-nomad 0.9.2 → 0.10.1
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 +53 -45
- 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: 76af53f1a2764deb4b91363674b6627d7b6017a30609e067d42b66cdbd5c9fc0
|
4
|
+
data.tar.gz: 64825bb8a9bdccf833f23cb36aeb10cba6f516bbac8e6690193eb1674339fb94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d359a15febd84d1303360f8d9c51faf026fa6388cf6a8b97edc7fa99cee59007c4999d040935bad0351ad1fa3bc1aca5908819b1cd1fc302d711b09a7d3a42e6
|
7
|
+
data.tar.gz: 5bf77756a9d1dc2bc28ded978f0523fff65059932154c1930545dd4b06930012d45ed646108f593802e606559b2aa4c2cae867f2012bef83245308b30d1a52dd
|
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
|
@@ -29,7 +29,7 @@ def capistrano_nomad_ensure_absolute_path(path)
|
|
29
29
|
path[0] == "/" ? path : "/#{path}"
|
30
30
|
end
|
31
31
|
|
32
|
-
def capistrano_nomad_build_file_path(parent_path, basename, kind: nil, namespace:
|
32
|
+
def capistrano_nomad_build_file_path(parent_path, basename, kind: nil, namespace: :default)
|
33
33
|
segments = [parent_path]
|
34
34
|
|
35
35
|
if namespace
|
@@ -132,7 +132,7 @@ def capistrano_nomad_capture_nomad_command(*args)
|
|
132
132
|
output
|
133
133
|
end
|
134
134
|
|
135
|
-
def capistrano_nomad_find_job_task_details(name, namespace:
|
135
|
+
def capistrano_nomad_find_job_task_details(name, namespace: :default, task: nil)
|
136
136
|
task = task.presence || name
|
137
137
|
|
138
138
|
# Find alloc id that contains task
|
@@ -170,7 +170,7 @@ def capistrano_nomad_find_job_task_details(name, namespace: nil, task: nil)
|
|
170
170
|
}
|
171
171
|
end
|
172
172
|
|
173
|
-
def capistrano_nomad_exec_within_job(name, command, namespace:
|
173
|
+
def capistrano_nomad_exec_within_job(name, command, namespace: :default, task: nil)
|
174
174
|
capistrano_nomad_run_remotely do
|
175
175
|
if (task_details = capistrano_nomad_find_job_task_details(name, namespace: namespace, task: task))
|
176
176
|
capistrano_nomad_execute_nomad_command(
|
@@ -246,7 +246,7 @@ def capistrano_nomad_fetch_namespace_options(namespace)
|
|
246
246
|
fetch(:nomad_namespaces)&.dig(namespace)
|
247
247
|
end
|
248
248
|
|
249
|
-
def capistrano_nomad_fetch_job_options(name, *args, namespace:
|
249
|
+
def capistrano_nomad_fetch_job_options(name, *args, namespace: :default)
|
250
250
|
fetch(:nomad_jobs).dig(namespace, name.to_sym, *args)
|
251
251
|
end
|
252
252
|
|
@@ -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: :default)
|
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
|
@@ -277,89 +277,97 @@ def capistrano_nomad_fetch_jobs_names_by_namespace(namespace: :all)
|
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
280
|
-
def capistrano_nomad_fetch_jobs_docker_image_types(names, namespace:
|
280
|
+
def capistrano_nomad_fetch_jobs_docker_image_types(names, namespace: :default)
|
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
284
|
def capistrano_nomad_define_group_tasks(namespace:)
|
285
|
-
|
286
|
-
desc "Build #{
|
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)
|
@@ -421,7 +429,7 @@ def capistrano_nomad_plan_jobs(names, *args)
|
|
421
429
|
end
|
422
430
|
end
|
423
431
|
|
424
|
-
def capistrano_nomad_run_jobs(names, namespace:
|
432
|
+
def capistrano_nomad_run_jobs(names, namespace: :default, is_detached: true)
|
425
433
|
names.each do |name|
|
426
434
|
run_options = {
|
427
435
|
namespace: namespace,
|
@@ -493,7 +501,7 @@ def capistrano_nomad_stop_jobs(names, **options)
|
|
493
501
|
end
|
494
502
|
end
|
495
503
|
|
496
|
-
def capistrano_nomad_purge_jobs(names, namespace:
|
504
|
+
def capistrano_nomad_purge_jobs(names, namespace: :default, is_detached: true)
|
497
505
|
names.each do |name|
|
498
506
|
capistrano_nomad_execute_nomad_command(:stop, { namespace: namespace, purge: true, detach: is_detached }, name)
|
499
507
|
end
|
@@ -503,7 +511,7 @@ def capistrano_nomad_display_job_status(name, **options)
|
|
503
511
|
capistrano_nomad_execute_nomad_command(:status, options, name)
|
504
512
|
end
|
505
513
|
|
506
|
-
def capistrano_nomad_display_job_logs(name, namespace:
|
514
|
+
def capistrano_nomad_display_job_logs(name, namespace: :default, **options)
|
507
515
|
if (task_details = capistrano_nomad_find_job_task_details(name, namespace: namespace, task: ENV["TASK"]))
|
508
516
|
capistrano_nomad_execute_nomad_command(
|
509
517
|
:alloc,
|
@@ -526,7 +534,7 @@ def capistrano_nomad_tail_job_logs(*args, **options)
|
|
526
534
|
capistrano_nomad_display_job_logs(*args, **options.merge(tail: true, n: 50))
|
527
535
|
end
|
528
536
|
|
529
|
-
def capistrano_nomad_open_job_ui(name, namespace:
|
537
|
+
def capistrano_nomad_open_job_ui(name, namespace: :default)
|
530
538
|
run_locally do
|
531
539
|
url = "#{fetch(:nomad_ui_url)}/ui/jobs/#{name}"
|
532
540
|
url += "@#{namespace}" if namespace
|
@@ -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(namespace:
|
3
|
+
capistrano_nomad_define_group_tasks(namespace: nil)
|
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
|