capistrano-nomad 0.15.1 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11b2eb94db466697a68736ef69c6c6013ba7a945d4160f62f0fce472c29c95f8
4
- data.tar.gz: 2875316e762a87205dcf60e2adbe37d0585382912de0f364dae4d2d08fd309dc
3
+ metadata.gz: 40b9b44a616fbf4c542f561845ffb785aa73b476027f78ee227953b15ab326a4
4
+ data.tar.gz: 9ebe475b0c6af2aee4c098536e9453fe231fcb7e9c86ce0b30e940ebc0f8d7f1
5
5
  SHA512:
6
- metadata.gz: cd58ba32ba7b3a862243d87b76c63bc2966190046193c45eef7bcff7f7ccb3bc0335f1bbf959d3b2c1bdcf552a03ec37314461cc3204bfd88628d3a56f2aff31
7
- data.tar.gz: 48f9157c487e83d88c98910075894291da92f66244aa20467c71a53ed32c030f0019e91dce5f92aa72434054833cdef31edadafecb115c795ceb31a717467062
6
+ metadata.gz: 0e7c48930dbc272c34c48922a2b93bb67b78d4729f2e2ca4c4602e33ed9019834d0c65b2cffaafa5bcdd450aeef335a8df95628dceb385f322b36815d96ef0f9
7
+ data.tar.gz: ca780918d90383b5232ff2c1c27e5d6ed65085358e475e7cf132fed07fd527f15fb6013fe732f9dc8cbdd9ebd179faacb751c73b0aa723aa0f377211169cb64a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.16.0]
4
+
5
+ - Add `:redeploy` task that stops job before performing a full deploy to ensure fresh allocations
6
+ - Add `:agent_info` task for efficient command execution in containers via SSH + Nomad exec
7
+
3
8
  ## [0.15.1]
4
9
 
5
10
  - Fix console task to preserve TTY interactivity by using eval instead of piping into /bin/sh
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-nomad (0.15.1)
4
+ capistrano-nomad (0.16.0)
5
5
  activesupport (<= 7.0.8)
6
6
  byebug
7
7
  capistrano (~> 3.0)
data/README.md CHANGED
@@ -128,6 +128,13 @@ cap production nomad:app:deploy
128
128
  cap production nomad:analytics:grafana:deploy
129
129
  ```
130
130
 
131
+ Redeploy individual jobs (stop + deploy with fresh allocations)
132
+
133
+ ```shell
134
+ cap production nomad:app:redeploy
135
+ cap production nomad:analytics:grafana:redeploy
136
+ ```
137
+
131
138
  Manage jobs
132
139
 
133
140
  ```shell
@@ -142,6 +149,7 @@ Tasks can apply across all namespaces or be filtered by namespaces or tags
142
149
 
143
150
  ```shell
144
151
  cap production nomad:analytics:deploy
152
+ cap production nomad:analytics:redeploy
145
153
  cap production nomad:analytics:upload_run
146
154
  cap production nomad:deploy
147
155
  cap production nomad:deploy TAG=admin
@@ -178,6 +186,7 @@ Run jobs in detached mode (fire and forget)
178
186
 
179
187
  ```shell
180
188
  IS_DETACHED=true cap production nomad:app:deploy
189
+ IS_DETACHED=true cap production nomad:app:redeploy
181
190
  IS_DETACHED=true cap production nomad:app:run
182
191
  IS_DETACHED=true cap production nomad:analytics:grafana:upload_run
183
192
  ```
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "capistrano-nomad"
5
- spec.version = "0.15.1"
5
+ spec.version = "0.16.0"
6
6
  spec.authors = ["James Hu"]
7
7
 
8
8
  spec.summary = "Capistrano plugin for deploying and managing Nomad jobs"
@@ -15,8 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
16
  spec.metadata["source_code_uri"] = "https://github.com/axsuul/capistrano-nomad"
17
17
 
18
- # Specify which files should be added to the gem when it is released.
19
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ # Specify which files should be added to the gem when it is released. The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
19
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
20
  %x(git ls-files -z).split("\x0").reject do |f|
22
21
  (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
@@ -35,6 +34,5 @@ Gem::Specification.new do |spec|
35
34
  spec.add_dependency("sshkit")
36
35
  spec.add_dependency("sshkit-interactive")
37
36
 
38
- # For more information and examples about making a new gem, check out our
39
- # guide at: https://bundler.io/guides/creating_gem.html
37
+ # For more information and examples about making a new gem, check out our guide at: https://bundler.io/guides/creating_gem.html
40
38
  end
@@ -116,6 +116,11 @@ def nomad_job(name, attributes = {})
116
116
  capistrano_nomad_deploy_jobs([name], namespace: namespace, is_detached: capistrano_nomad_job_detached_overridden?)
117
117
  end
118
118
 
119
+ desc("Redeploy #{description_name} job")
120
+ task(:redeploy) do
121
+ capistrano_nomad_redeploy_jobs([name], namespace: namespace, is_detached: capistrano_nomad_job_detached_overridden?)
122
+ end
123
+
119
124
  desc("Start #{description_name} job")
120
125
  task(:start) do
121
126
  capistrano_nomad_start_jobs([name], namespace: namespace)
@@ -150,6 +155,46 @@ def nomad_job(name, attributes = {})
150
155
  capistrano_nomad_display_job_status(name, namespace: namespace)
151
156
  end
152
157
 
158
+ desc("Display connection info for #{description_name} job as JSON for agent use. Specify task with TASK")
159
+ task(:agent_info) do
160
+ info = {}
161
+
162
+ capistrano_nomad_run_remotely do |host|
163
+ task_details = capistrano_nomad_find_job_task_details(name, task: ENV["TASK"], namespace: namespace)
164
+
165
+ unless task_details
166
+ $stderr.puts("No running allocation found")
167
+ next
168
+ end
169
+
170
+ # Build SSH command prefix using same source of truth as sshkit-interactive
171
+ netssh = host.netssh_options || {}
172
+ ssh_args = ["ssh"]
173
+ ssh_args << "-A" if netssh[:forward_agent]
174
+ ssh_args << "-p #{netssh[:port]}" if netssh[:port]
175
+ ssh_args << "-l #{host.user}" if host.user
176
+ ssh_args << %(-o "ProxyCommand #{netssh[:proxy].command_line_template}") if netssh[:proxy]
177
+ ssh_args << %(-o "HostName #{netssh[:host_name]}") if netssh[:host_name]
178
+ Array(netssh[:keys]).each { |key| ssh_args << "-i #{key}" }
179
+ Array(netssh[:auth_methods]).tap { |m| ssh_args << %(-o "PreferredAuthentications #{m.join(",")}") if m.any? }
180
+ ssh_args << host.hostname
181
+ info[:ssh_command] = ssh_args.join(" ")
182
+
183
+ # Build nomad alloc exec command prefix (non-interactive: no PTY, stdin open)
184
+ exec_parts = []
185
+ if (nomad_token = fetch(:nomad_token))
186
+ exec_parts << "NOMAD_TOKEN=#{nomad_token}"
187
+ end
188
+ exec_parts << "nomad alloc exec -i=true -t=false"
189
+ exec_parts << "-task=#{task_details[:name]}"
190
+ exec_parts << "-namespace=#{namespace}" if namespace && namespace != :default
191
+ exec_parts << task_details[:alloc_id]
192
+ info[:exec_command] = exec_parts.join(" ")
193
+ end
194
+
195
+ $stdout.puts(info.to_json) if info[:ssh_command]
196
+ end
197
+
153
198
  desc("Open console to #{description_name} job. Specify task with TASK, command with CMD")
154
199
  task(:console) do
155
200
  job_options = capistrano_nomad_fetch_job_options(name, namespace: namespace)
@@ -411,6 +411,13 @@ def capistrano_nomad_define_group_tasks(namespace:)
411
411
  end
412
412
  end
413
413
 
414
+ desc("Redeploy #{nomad_namespace} jobs")
415
+ task(:redeploy) do
416
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
417
+ capistrano_nomad_redeploy_jobs(names, namespace: jobs_namespace)
418
+ end
419
+ end
420
+
414
421
  desc("Rerun #{nomad_namespace} jobs")
415
422
  task(:rerun) do
416
423
  capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
@@ -584,6 +591,14 @@ def capistrano_nomad_deploy_jobs(names, **options)
584
591
  capistrano_nomad_upload_run_jobs(names, **general_options.merge(options))
585
592
  end
586
593
 
594
+ # Stop job and deploy again with fresh allocations
595
+ def capistrano_nomad_redeploy_jobs(names, **options)
596
+ general_options = options.slice!(:is_detached)
597
+
598
+ capistrano_nomad_stop_jobs(names, **general_options)
599
+ capistrano_nomad_deploy_jobs(names, **general_options.merge(options))
600
+ end
601
+
587
602
  def capistrano_nomad_restart_jobs(names, **options)
588
603
  capistrano_nomad_ensure_options!(options)
589
604
 
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.15.1
4
+ version: 0.16.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: 2026-02-05 00:00:00.000000000 Z
11
+ date: 2026-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport