capistrano-nomad 0.7.2 → 0.8.1

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: '02685bbf3f2ad3d0bc5dbc45b33f31622ddbe9a465671381645bd665266cf4aa'
4
- data.tar.gz: 6f386d0642e4cd00f66e5dc0ddefdb3815d537d254525e130717251d7407a56d
3
+ metadata.gz: 9ab89a48a26fb135563d9685083c2ec1ae913dba51baf289b2a232407a26b01e
4
+ data.tar.gz: 85ee06cb6f05413ff54c67f0306818394f5e071a1b07fc1e2eef50016226f129
5
5
  SHA512:
6
- metadata.gz: 5c7a4c7173a08c5ef7bc7207a5e3500864a1f85171a4a324342bf0ed6bdfda3b7bce2ba3db147440476db96513f1ab0b9af7458c59fee7bd8c4f6996686acc69
7
- data.tar.gz: f6d8b9affa00bea01d56a6ef3c067d80a6596c7881b8f4893c4b16e17fd5f2d0030128dfa0f0de4dce6cd908e29013ca088d61a26df5897fe97bebf6aa215d7d
6
+ metadata.gz: bf2f8c90f6f9768f055afaed469cb1d692fa15bce243b5219ead74e9f0bc076498e2c89ed4a451ca34b46318ee6405a8bf06da342ab384013ff5466aa027b977
7
+ data.tar.gz: 6551a3d5ca81af0be6f8876ca27278592c76ecc5ecbe78494d70fa3d025a57c064e930b61876f58abaf6014c20438b6362a853ae3723a51a366272010d925b38
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-nomad (0.7.2)
4
+ capistrano-nomad (0.8.1)
5
5
  activesupport (<= 7.0.8)
6
6
  byebug
7
7
  capistrano (~> 3.0)
data/README.md CHANGED
@@ -101,12 +101,6 @@ nomad_namespace :maintenance, path: "maintenance-stuff" do
101
101
  end
102
102
  ```
103
103
 
104
- Deploy all jobs
105
-
106
- ```shell
107
- cap production nomad:all:deploy
108
- ```
109
-
110
104
  Deploy individual jobs
111
105
 
112
106
  ```shell
@@ -123,6 +117,15 @@ cap production nomad:analytics:grafana:restart
123
117
  cap production nomad:postgres:status
124
118
  ```
125
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
+
126
129
  Open console
127
130
 
128
131
  ```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.2"
5
+ spec.version = "0.8.1"
6
6
  spec.authors = ["James Hu"]
7
7
 
8
8
  spec.summary = "Capistrano plugin for deploying and managing Nomad jobs"
@@ -27,6 +27,11 @@ def nomad_namespace(namespace, **options, &block)
27
27
 
28
28
  @nomad_namespace = nil
29
29
 
30
+ # Define tasks for namespace jobs
31
+ namespace(:nomad) do
32
+ capistrano_nomad_define_group_tasks(namespace: namespace)
33
+ end
34
+
30
35
  true
31
36
  end
32
37
 
@@ -254,14 +254,86 @@ 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
258
- 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
259
264
  end
260
265
 
261
266
  def capistrano_nomad_fetch_jobs_docker_image_types(names, namespace: nil)
262
267
  names.map { |n| fetch(:nomad_jobs).dig(namespace, n.to_sym, :docker_image_types) }.flatten.compact.uniq
263
268
  end
264
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
+
265
337
  def capistrano_nomad_build_jobs_docker_images(names, *args)
266
338
  image_types = capistrano_nomad_fetch_jobs_docker_image_types(names, *args)
267
339
 
@@ -4,61 +4,18 @@ 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}}'")
60
14
  current_namespaces = output.split("|").compact.map(&:to_sym)
61
- desired_namespaces = fetch(:nomad_jobs).keys
15
+
16
+ # If key is nil then it actually belongs to the default namespace
17
+ desired_namespaces = fetch(:nomad_jobs).keys.map { |n| n.nil? ? :default : n.to_sym }
18
+
62
19
  missing_namespaces = desired_namespaces - current_namespaces
63
20
  unused_namespaces = current_namespaces - desired_namespaces
64
21
 
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.2
4
+ version: 0.8.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-12-15 00:00:00.000000000 Z
11
+ date: 2024-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport