capistrano-nomad 0.7.1 → 0.8.0

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: eac8deb55e886ac97912499380a208f03ef15f7f952123afda2d6f8910e30df0
4
- data.tar.gz: 730715ed63a01273775a7dccc403993866d73cb562de7cf70d0c22cf2754b493
3
+ metadata.gz: 3410efa72a3baf19cc0d7fa93f33af57c3e1c0c703685a7f21aa42ed41179d55
4
+ data.tar.gz: '0971e538df8c3fc79c633423f4db322ea4629d1ec22c2a457fa2404ae32035cb'
5
5
  SHA512:
6
- metadata.gz: 933da9e873b7d6ed030983f0a441a157a4b2bac6c8803076a6dbeebb2bf3afeb922e57d5d3f5ba1b437f9da371386c9a09676d4e3f8dc32e68e3bfa86e5ae4b8
7
- data.tar.gz: a87d69e22c6df4fcb9189a43279e399e27d9a625d1a86d728626fba63327daeed6a924113f019ed639d2782fae6db47367fbcd2568337faeafe9410ed3176b9f
6
+ metadata.gz: 624793f5e75a00ac9de53a25a1ffa38a226d95f84850e38f9c82917865f0c5de66d7ac1e02bdda2e3b9cf01f3771aa154d1398fd3a70371e2c7bdb0e84fade09
7
+ data.tar.gz: ec008b557f39991b002950cbbfecb1c11a038d9ef9a08e7d250a73201266a0c5c2503735ca7fe24fdc941b53a75f944edc5b6f80ab13a32675dea16bcb64a6f1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-nomad (0.7.1)
4
+ capistrano-nomad (0.8.0)
5
5
  activesupport (<= 7.0.8)
6
6
  byebug
7
7
  capistrano (~> 3.0)
data/README.md CHANGED
@@ -37,6 +37,9 @@ Within `deploy.rb`
37
37
  set :nomad_jobs_path, "nomad/jobs"
38
38
  set :nomad_var_files_path, "nomad/vars"
39
39
 
40
+ # Determines base URL to use when opening job in web UI
41
+ set :nomad_ui_url, "http://localhost:4646"
42
+
40
43
  # Make variables available to all template .erb files
41
44
  set :nomad_template_vars, (lambda do
42
45
  {
@@ -92,12 +95,10 @@ nomad_job :"traefik-secondary", template: :traefik, erb_vars: { role: :secondary
92
95
  nomad_namespace :analytics do
93
96
  nomad_job :grafana
94
97
  end
95
- ```
96
98
 
97
- Deploy all jobs
98
-
99
- ```shell
100
- cap production nomad:all:deploy
99
+ nomad_namespace :maintenance, path: "maintenance-stuff" do
100
+ nomad_job :garbage_collection
101
+ end
101
102
  ```
102
103
 
103
104
  Deploy individual jobs
@@ -116,6 +117,15 @@ cap production nomad:analytics:grafana:restart
116
117
  cap production nomad:postgres:status
117
118
  ```
118
119
 
120
+ Most tasks are also available for namespace or all
121
+
122
+ ```shell
123
+ cap production nomad:analytics:deploy
124
+ cap production nomad:analytics:upload_run
125
+ cap production nomad:all:deploy
126
+ cap production nomad:all:upload_run
127
+ ```
128
+
119
129
  Open console
120
130
 
121
131
  ```shell
@@ -133,6 +143,12 @@ cap production nomad:app:stderr
133
143
  cap production nomad:analytics:grafana:follow
134
144
  ```
135
145
 
146
+ Open job in web UI
147
+
148
+ ```shell
149
+ cap production nomad:app:ui
150
+ ```
151
+
136
152
  Create missing and delete unused namespaces
137
153
 
138
154
  ```shell
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "capistrano-nomad"
5
- spec.version = "0.7.1"
5
+ spec.version = "0.8.0"
6
6
  spec.authors = ["James Hu"]
7
7
 
8
8
  spec.summary = "Capistrano plugin for deploying and managing Nomad jobs"
@@ -23,8 +23,8 @@ def capistrano_nomad_read_docker_image_types_manifest
23
23
 
24
24
  capistrano_nomad_run_remotely do
25
25
  # Ensure file exists
26
- execute("mkdir -p #{shared_path}")
27
- execute("touch #{capistrano_nomad_docker_image_types_manifest_path}")
26
+ execute("mkdir", "-p", shared_path)
27
+ execute("touch", capistrano_nomad_docker_image_types_manifest_path)
28
28
 
29
29
  output = capture("cat #{capistrano_nomad_docker_image_types_manifest_path}")
30
30
 
@@ -15,13 +15,23 @@ def nomad_docker_image_type(image_type, attributes = {})
15
15
  set(:nomad_docker_image_types, docker_image_types)
16
16
  end
17
17
 
18
- def nomad_namespace(namespace, &block)
18
+ def nomad_namespace(namespace, **options, &block)
19
+ nomad_namespaces = fetch(:nomad_namespaces) || {}
20
+ nomad_namespaces[namespace] = options
21
+ set(:nomad_namespaces, nomad_namespaces)
22
+
23
+ # Make namespace active for block
19
24
  @nomad_namespace = namespace
20
25
 
21
26
  instance_eval(&block)
22
27
 
23
28
  @nomad_namespace = nil
24
29
 
30
+ # Define tasks for namespace jobs
31
+ namespace(:nomad) do
32
+ capistrano_nomad_define_group_tasks(namespace: namespace)
33
+ end
34
+
25
35
  true
26
36
  end
27
37
 
@@ -135,6 +145,11 @@ def nomad_job(name, attributes = {})
135
145
  task :follow do
136
146
  capistrano_nomad_display_job_logs(name, namespace: namespace, f: true)
137
147
  end
148
+
149
+ desc "Open job in web UI"
150
+ task :ui do
151
+ capistrano_nomad_open_job_ui(name, namespace: namespace)
152
+ end
138
153
  end
139
154
  end
140
155
 
@@ -29,9 +29,24 @@ 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, namespace: nil)
32
+ def capistrano_nomad_build_file_path(parent_path, basename, kind: nil, namespace: nil)
33
33
  segments = [parent_path]
34
- segments << namespace if namespace
34
+
35
+ if namespace
36
+ case kind
37
+
38
+ # Always upload to namespace folder on remote
39
+ when :release
40
+ segments << namespace
41
+
42
+ # Otherwise path can be overriden of where files belonging to namespace are stored locally
43
+ else
44
+ namespace_options = capistrano_nomad_fetch_namespace_options(namespace)
45
+
46
+ segments << (namespace_options[:path] || namespace)
47
+ end
48
+ end
49
+
35
50
  segments << "#{basename}.hcl"
36
51
 
37
52
  segments.join("/")
@@ -64,12 +79,16 @@ def capistrano_nomad_build_local_var_file_path(name, *args)
64
79
  capistrano_nomad_build_local_path(capistrano_nomad_build_base_var_file_path(name, *args))
65
80
  end
66
81
 
67
- def capistrano_nomad_build_release_job_path(*args)
68
- "#{release_path}#{capistrano_nomad_ensure_absolute_path(capistrano_nomad_build_base_job_path(*args))}"
82
+ def capistrano_nomad_build_release_job_path(name, **options)
83
+ options[:kind] = :release
84
+
85
+ "#{release_path}#{capistrano_nomad_ensure_absolute_path(capistrano_nomad_build_base_job_path(name, **options))}"
69
86
  end
70
87
 
71
- def capistrano_nomad_build_release_var_file_path(*args)
72
- "#{release_path}#{capistrano_nomad_ensure_absolute_path(capistrano_nomad_build_base_var_file_path(*args))}"
88
+ def capistrano_nomad_build_release_var_file_path(name, **options)
89
+ options[:kind] = :release
90
+
91
+ "#{release_path}#{capistrano_nomad_ensure_absolute_path(capistrano_nomad_build_base_var_file_path(name, **options))}"
73
92
  end
74
93
 
75
94
  def capistrano_nomad_run_nomad_command(kind, *args)
@@ -223,6 +242,10 @@ def capistrano_nomad_upload(local_path:, remote_path:, erb_vars: {})
223
242
  end
224
243
  end
225
244
 
245
+ def capistrano_nomad_fetch_namespace_options(namespace)
246
+ fetch(:nomad_namespaces).dig(namespace)
247
+ end
248
+
226
249
  def capistrano_nomad_fetch_job_options(name, *args, namespace: nil)
227
250
  fetch(:nomad_jobs).dig(namespace, name.to_sym, *args)
228
251
  end
@@ -231,14 +254,86 @@ def capistrano_nomad_fetch_job_var_files(name, *args)
231
254
  capistrano_nomad_fetch_job_options(name, :var_files, *args) || []
232
255
  end
233
256
 
234
- def capistrano_nomad_fetch_jobs_names_by_namespace
235
- fetch(:nomad_jobs).transform_values(&:keys)
257
+ def capistrano_nomad_fetch_jobs_names_by_namespace(namespace: :all)
258
+ jobs_names_by_namespace = fetch(:nomad_jobs).transform_values(&:keys)
259
+
260
+ # Filter by namespace unless it's all
261
+ jobs_names_by_namespace = jobs_names_by_namespace.slice(namespace) unless namespace == :all
262
+
263
+ jobs_names_by_namespace
236
264
  end
237
265
 
238
266
  def capistrano_nomad_fetch_jobs_docker_image_types(names, namespace: nil)
239
267
  names.map { |n| fetch(:nomad_jobs).dig(namespace, n.to_sym, :docker_image_types) }.flatten.compact.uniq
240
268
  end
241
269
 
270
+ def capistrano_nomad_define_group_tasks(namespace:)
271
+ namespace(namespace) do
272
+ desc "Build #{namespace} job Docker images"
273
+ task :build do
274
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
275
+ capistrano_nomad_push_jobs_docker_images(names, namespace: namespace_by)
276
+ end
277
+ end
278
+
279
+ desc "Push #{namespace} job Docker images"
280
+ task :push do
281
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
282
+ capistrano_nomad_push_jobs_docker_images(names, namespace: namespace_by)
283
+ end
284
+ end
285
+
286
+ desc "Build and push #{namespace} job Docker images"
287
+ task :assemble do
288
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
289
+ capistrano_nomad_assemble_jobs_docker_images(names, namespace: namespace_by)
290
+ end
291
+ end
292
+
293
+ desc "Upload #{namespace} jobs"
294
+ task :upload do
295
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
296
+ capistrano_nomad_upload_jobs(names, namespace: namespace_by)
297
+ end
298
+ end
299
+
300
+ desc "Run #{namespace} jobs"
301
+ task :run do
302
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
303
+ capistrano_nomad_run_jobs(names, namespace: namespace_by)
304
+ end
305
+ end
306
+
307
+ desc "Upload and run #{namespace} jobs"
308
+ task :upload_run do
309
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
310
+ capistrano_nomad_upload_run_jobs(names, namespace: namespace_by)
311
+ end
312
+ end
313
+
314
+ desc "Deploy #{namespace} jobs"
315
+ task :deploy do
316
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
317
+ capistrano_nomad_deploy_jobs(names, namespace: namespace_by)
318
+ end
319
+ end
320
+
321
+ desc "Rerun #{namespace} jobs"
322
+ task :rerun do
323
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
324
+ capistrano_nomad_rerun_jobs(names, namespace: namespace_by)
325
+ end
326
+ end
327
+
328
+ desc "Purge #{namespace} jobs"
329
+ task :purge do
330
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: namespace).each do |namespace_by, names|
331
+ capistrano_nomad_purge_jobs(names, namespace: namespace_by)
332
+ end
333
+ end
334
+ end
335
+ end
336
+
242
337
  def capistrano_nomad_build_jobs_docker_images(names, *args)
243
338
  image_types = capistrano_nomad_fetch_jobs_docker_image_types(names, *args)
244
339
 
@@ -402,3 +497,13 @@ end
402
497
  def capistrano_nomad_tail_job_logs(*args, **options)
403
498
  capistrano_nomad_display_job_logs(*args, **options.merge(tail: true, n: 50))
404
499
  end
500
+
501
+ def capistrano_nomad_open_job_ui(name, namespace: nil)
502
+ run_locally do
503
+ url = "#{fetch(:nomad_ui_url)}/ui/jobs/#{name}"
504
+ url += "@#{namespace}" if namespace
505
+
506
+ # Only macOS supported for now
507
+ execute(:open, url)
508
+ end
509
+ end
@@ -4,56 +4,10 @@ namespace :nomad do
4
4
  capistrano_nomad_execute_nomad_command(:version)
5
5
  end
6
6
 
7
- namespace :all do
8
- desc "Build all job Docker images"
9
- task :build do
10
- capistrano_nomad_fetch_jobs_names_by_namespace.each do |namespace, names|
11
- capistrano_nomad_push_jobs_docker_images(names, namespace: namespace)
12
- end
13
- end
14
-
15
- desc "Push all job Docker images"
16
- task :push do
17
- capistrano_nomad_fetch_jobs_names_by_namespace.each do |namespace, names|
18
- capistrano_nomad_push_jobs_docker_images(names, namespace: namespace)
19
- end
20
- end
21
-
22
- desc "Build and push all job Docker images"
23
- task :assemble do
24
- capistrano_nomad_fetch_jobs_names_by_namespace.each do |namespace, names|
25
- capistrano_nomad_assemble_jobs_docker_images(names, namespace: namespace)
26
- end
27
- end
28
-
29
- desc "Upload and run all jobs"
30
- task :upload_run do
31
- capistrano_nomad_fetch_jobs_names_by_namespace.each do |namespace, names|
32
- capistrano_nomad_upload_run_jobs(names, namespace: namespace)
33
- end
34
- end
35
-
36
- desc "Deploy all jobs"
37
- task :deploy do
38
- capistrano_nomad_fetch_jobs_names_by_namespace.each do |namespace, names|
39
- capistrano_nomad_deploy_jobs(names, namespace: namespace)
40
- end
41
- end
42
-
43
- desc "Rerun all jobs"
44
- task :rerun do
45
- capistrano_nomad_fetch_jobs_names_by_namespace.each do |namespace, names|
46
- capistrano_nomad_rerun_jobs(names, namespace: namespace)
47
- end
48
- end
49
-
50
- desc "Purge all jobs"
51
- task :purge do
52
- capistrano_nomad_fetch_jobs_names_by_namespace.each do |namespace, names|
53
- capistrano_nomad_purge_jobs(names, namespace: namespace)
54
- end
55
- end
7
+ # Define tasks for all jobs
8
+ capistrano_nomad_define_group_tasks(namespace: :all)
56
9
 
10
+ namespace :all do
57
11
  desc "Create missing and remove unused namespaces"
58
12
  task :modify_namespaces do
59
13
  output = capistrano_nomad_capture_nomad_command(:namespace, :list, t: "'{{range .}}{{ .Name }}|{{end}}'")
@@ -11,6 +11,7 @@ module Capistrano
11
11
  def set_defaults
12
12
  set_if_empty(:nomad_jobs_path, "nomad/jobs")
13
13
  set_if_empty(:nomad_var_files_path, "nomad/var_files")
14
+ set_if_empty(:nomad_ui_url, "http://localhost:4646")
14
15
  set_if_empty(:nomad_docker_image_alias, ->(**) {})
15
16
  end
16
17
 
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.7.1
4
+ version: 0.8.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-11-20 00:00:00.000000000 Z
11
+ date: 2024-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport