capistrano-nomad 0.6.2 → 0.6.4

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: 25b29aaa6c532b6656df34b6ebc7ebc23359c4acb3ae2b8c5d7320a2e79c7f66
4
- data.tar.gz: 770838795fb494f1c4305168d6b60f51be7f1d33bec9c31e45b7d119ecd427f0
3
+ metadata.gz: 707ded6b01d5903708a362ef6e98f3c56d5e52fd1557bfad47f1844cb7d6c96e
4
+ data.tar.gz: 68ea61e7025400e99c97683b8f3390357a0f04cf5b173846bba378d8bdd5fa3d
5
5
  SHA512:
6
- metadata.gz: 24cd34d64db04c41e6b2e39ced4e84129e4fb3ff2d70a25e53d945e2bcdaf35e7a45f6783c1e5cd37d061053ba24b2717d939f6b3e0cd0939c14bc8f39def70d
7
- data.tar.gz: e978fbbf7205ed2d160e2702ae9109ba73722c695f9de2e0c8f51cc010a248da5ffbed583d452e1bcc7a6e0ee22989202afd183430256ae73cc7f0f4515d83fa
6
+ metadata.gz: 19a5ee3bcddf663ed3820245f10d0c35dee3cf2d1659b44f61947696c7ea24c263696c3c25d6dba032d14293706f0b9b68ee3e9cdbd41b66309e43eb92a0e297
7
+ data.tar.gz: b20019a85564cc4eee312bfaa17934becab4b73c2505c7a0b9511b1759b320c56fda3656b7f2b80b3cd090e347f05f5c0a2ef3e283a078850636c37ea58f20fb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-nomad (0.6.2)
4
+ capistrano-nomad (0.6.4)
5
5
  activesupport (<= 7.0.8)
6
6
  byebug
7
7
  capistrano (~> 3.0)
data/README.md CHANGED
@@ -90,6 +90,12 @@ cap production nomad:app:console TASK=custom-task-name
90
90
  cap production nomad:analytics:grafana:console
91
91
  ```
92
92
 
93
+ Create missing and delete unused namespaces
94
+
95
+ ```shell
96
+ cap production nomad:all:replace_namespaces
97
+ ```
98
+
93
99
  ## Development
94
100
 
95
101
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "capistrano-nomad"
5
- spec.version = "0.6.2"
5
+ spec.version = "0.6.4"
6
6
  spec.authors = ["James Hu"]
7
7
 
8
8
  spec.summary = "Capistrano plugin for deploying and managing Nomad jobs"
@@ -58,16 +58,6 @@ def nomad_job(name, attributes = {})
58
58
  capistrano_nomad_rerun_jobs([name], namespace: namespace)
59
59
  end
60
60
 
61
- desc "Purge #{description_name} job"
62
- task :purge do
63
- capistrano_nomad_purge_jobs([name], namespace: namespace, is_detached: false)
64
- end
65
-
66
- desc "Display status of #{description_name} job"
67
- task :status do
68
- capistrano_nomad_display_job_status(name, namespace: namespace)
69
- end
70
-
71
61
  desc "Upload and plan #{description_name} job"
72
62
  task :upload_plan do
73
63
  capistrano_nomad_upload_plan_jobs([name], namespace: namespace)
@@ -93,6 +83,21 @@ def nomad_job(name, attributes = {})
93
83
  capistrano_nomad_restart_jobs([name], namespace: namespace)
94
84
  end
95
85
 
86
+ desc "Stop #{description_name} job"
87
+ task :stop do
88
+ capistrano_nomad_stop_jobs([name], namespace: namespace)
89
+ end
90
+
91
+ desc "Purge #{description_name} job"
92
+ task :purge do
93
+ capistrano_nomad_purge_jobs([name], namespace: namespace, is_detached: false)
94
+ end
95
+
96
+ desc "Display status of #{description_name} job"
97
+ task :status do
98
+ capistrano_nomad_display_job_status(name, namespace: namespace)
99
+ end
100
+
96
101
  desc "Open console to #{description_name} job. Specify task by passing TASK environment variable"
97
102
  task :console do
98
103
  capistrano_nomad_exec_within_job(name, "/bin/bash", namespace: namespace, task: ENV["TASK"].presence)
@@ -116,7 +116,7 @@ end
116
116
  def capistrano_nomad_capture_nomad_command(*args)
117
117
  output = nil
118
118
 
119
- on(roles(:manager)) do |host|
119
+ on(roles(:manager)) do |_host|
120
120
  output = capistrano_nomad_run_nomad_command(:capture, *args)
121
121
  end
122
122
 
@@ -125,7 +125,7 @@ end
125
125
 
126
126
  def capistrano_nomad_exec_within_job(name, command, namespace: nil, task: nil)
127
127
  on(roles(:manager)) do
128
- task = name unless task
128
+ task ||= name
129
129
 
130
130
  # Find alloc id that contains task
131
131
  output = capistrano_nomad_capture_nomad_command(
@@ -321,6 +321,12 @@ def capistrano_nomad_deploy_jobs(names, *args)
321
321
  capistrano_nomad_upload_run_jobs(names, *args)
322
322
  end
323
323
 
324
+ def capistrano_nomad_stop_jobs(names, namespace: nil)
325
+ names.each do |name|
326
+ capistrano_nomad_execute_nomad_command(:job, :stop, { namespace: namespace }, name)
327
+ end
328
+ end
329
+
324
330
  def capistrano_nomad_restart_jobs(names, namespace: nil)
325
331
  names.each do |name|
326
332
  capistrano_nomad_execute_nomad_command(:job, :restart, { namespace: namespace }, name)
@@ -53,6 +53,25 @@ namespace :nomad do
53
53
  capistrano_nomad_purge_jobs(names, namespace: namespace)
54
54
  end
55
55
  end
56
+
57
+ desc "Create missing and remove unused namespaces"
58
+ task :replace_namespaces do
59
+ output = capistrano_nomad_capture_nomad_command(:namespace, :list, t: "'{{range .}}{{ .Name }}|{{end}}'")
60
+ current_namespaces = output.split("|").compact.map(&:to_sym)
61
+ desired_namespaces = fetch(:nomad_jobs).keys
62
+ missing_namespaces = desired_namespaces - current_namespaces
63
+ unused_namespaces = current_namespaces - desired_namespaces
64
+
65
+ # Remove unused namespaces
66
+ unused_namespaces.each do |namespace|
67
+ capistrano_nomad_execute_nomad_command(:namespace, :delete, namespace)
68
+ end
69
+
70
+ # Create missing namespaces
71
+ missing_namespaces.each do |namespace|
72
+ capistrano_nomad_execute_nomad_command(:namespace, :apply, namespace)
73
+ end
74
+ end
56
75
  end
57
76
 
58
77
  namespace :docker_images do
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.6.2
4
+ version: 0.6.4
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-31 00:00:00.000000000 Z
11
+ date: 2023-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport