capistrano-nomad 0.15.1 → 0.16.1

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: 137c81e55b24eb37ce7b3e39722c378d2addea5c5b331ceadeb6d5614f24402e
4
+ data.tar.gz: 24f1a3cd917263e2c9a34e2baad7968696f0fff7845b9a943a55c4b4742e09a7
5
5
  SHA512:
6
- metadata.gz: cd58ba32ba7b3a862243d87b76c63bc2966190046193c45eef7bcff7f7ccb3bc0335f1bbf959d3b2c1bdcf552a03ec37314461cc3204bfd88628d3a56f2aff31
7
- data.tar.gz: 48f9157c487e83d88c98910075894291da92f66244aa20467c71a53ed32c030f0019e91dce5f92aa72434054833cdef31edadafecb115c795ceb31a717467062
6
+ metadata.gz: 342ae22edc3a3a423ae62a92710ed7dec2445023cd7164f299406fc423bc8e5acbee77a4bd475c2fd82f3cfe26b18eb0c864e58023fb8af1928f00d47a32d89e
7
+ data.tar.gz: eff30623ea4be4debcdee3c2c31645ab928e4ef9eeef83dbd4c6a295131bffdd6c1d7c38a68c9dc97f29bfb2667791a5be3e55eb0090b4c901000e898cb55dbf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.16.1]
4
+
5
+ - Pass every configured variable file to `nomad plan` and `nomad run`
6
+
7
+ ## [0.16.0]
8
+
9
+ - Add `:redeploy` task that stops job before performing a full deploy to ensure fresh allocations
10
+ - Add `:agent_info` task for efficient command execution in containers via SSH + Nomad exec
11
+
3
12
  ## [0.15.1]
4
13
 
5
14
  - 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.1"
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)
@@ -328,6 +328,15 @@ def capistrano_nomad_fetch_job_var_files(name, **options)
328
328
  capistrano_nomad_fetch_job_options(name, :var_files, **options) || []
329
329
  end
330
330
 
331
+ # Build one command option per configured variable file so Nomad receives every file in order
332
+ def capistrano_nomad_build_job_var_file_options(name, **options)
333
+ capistrano_nomad_fetch_job_var_files(name, **options).map do |var_file|
334
+ {
335
+ var_file: capistrano_nomad_build_release_var_file_path(var_file, **options),
336
+ }
337
+ end
338
+ end
339
+
331
340
  def capistrano_nomad_fetch_jobs_names_by_namespace(**options)
332
341
  capistrano_nomad_ensure_options!(options)
333
342
  namespace = options[:namespace]
@@ -411,6 +420,13 @@ def capistrano_nomad_define_group_tasks(namespace:)
411
420
  end
412
421
  end
413
422
 
423
+ desc("Redeploy #{nomad_namespace} jobs")
424
+ task(:redeploy) do
425
+ capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
426
+ capistrano_nomad_redeploy_jobs(names, namespace: jobs_namespace)
427
+ end
428
+ end
429
+
414
430
  desc("Rerun #{nomad_namespace} jobs")
415
431
  task(:rerun) do
416
432
  capistrano_nomad_fetch_jobs_names_by_namespace(namespace: nomad_namespace).each do |jobs_namespace, names|
@@ -514,14 +530,19 @@ def capistrano_nomad_upload_jobs(names, **options)
514
530
  end
515
531
  end
516
532
 
533
+ # Plan each job with every configured variable file before the uploaded job path
517
534
  def capistrano_nomad_plan_jobs(names, **options)
518
535
  names.each do |name|
519
- args = [capistrano_nomad_build_release_job_path(name, **options)]
536
+ args = [
537
+ *capistrano_nomad_build_job_var_file_options(name, **options),
538
+ capistrano_nomad_build_release_job_path(name, **options),
539
+ ]
520
540
 
521
541
  capistrano_nomad_execute_nomad_command(:plan, *args)
522
542
  end
523
543
  end
524
544
 
545
+ # Run each job with all configured variable files while preserving the existing command options
525
546
  def capistrano_nomad_run_jobs(names, is_detached: true, **options)
526
547
  capistrano_nomad_ensure_options!(options)
527
548
 
@@ -534,13 +555,10 @@ def capistrano_nomad_run_jobs(names, is_detached: true, **options)
534
555
  preserve_counts: true,
535
556
  }
536
557
 
537
- capistrano_nomad_fetch_job_var_files(name, **options).each do |var_file|
538
- run_options[:var_file] = capistrano_nomad_build_release_var_file_path(var_file, **options)
539
- end
540
-
541
558
  capistrano_nomad_execute_nomad_command(
542
559
  :run,
543
560
  run_options,
561
+ *capistrano_nomad_build_job_var_file_options(name, **options),
544
562
  capistrano_nomad_build_release_job_path(name, **options),
545
563
  )
546
564
  end
@@ -584,6 +602,14 @@ def capistrano_nomad_deploy_jobs(names, **options)
584
602
  capistrano_nomad_upload_run_jobs(names, **general_options.merge(options))
585
603
  end
586
604
 
605
+ # Stop job and deploy again with fresh allocations
606
+ def capistrano_nomad_redeploy_jobs(names, **options)
607
+ general_options = options.slice!(:is_detached)
608
+
609
+ capistrano_nomad_stop_jobs(names, **general_options)
610
+ capistrano_nomad_deploy_jobs(names, **general_options.merge(options))
611
+ end
612
+
587
613
  def capistrano_nomad_restart_jobs(names, **options)
588
614
  capistrano_nomad_ensure_options!(options)
589
615
 
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.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: 2026-02-05 00:00:00.000000000 Z
11
+ date: 2026-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubygems_version: 3.3.27
155
+ rubygems_version: 3.4.20
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Capistrano plugin for deploying and managing Nomad jobs