capistrano-nomad 0.7.1 → 0.7.2

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: '02685bbf3f2ad3d0bc5dbc45b33f31622ddbe9a465671381645bd665266cf4aa'
4
+ data.tar.gz: 6f386d0642e4cd00f66e5dc0ddefdb3815d537d254525e130717251d7407a56d
5
5
  SHA512:
6
- metadata.gz: 933da9e873b7d6ed030983f0a441a157a4b2bac6c8803076a6dbeebb2bf3afeb922e57d5d3f5ba1b437f9da371386c9a09676d4e3f8dc32e68e3bfa86e5ae4b8
7
- data.tar.gz: a87d69e22c6df4fcb9189a43279e399e27d9a625d1a86d728626fba63327daeed6a924113f019ed639d2782fae6db47367fbcd2568337faeafe9410ed3176b9f
6
+ metadata.gz: 5c7a4c7173a08c5ef7bc7207a5e3500864a1f85171a4a324342bf0ed6bdfda3b7bce2ba3db147440476db96513f1ab0b9af7458c59fee7bd8c4f6996686acc69
7
+ data.tar.gz: f6d8b9affa00bea01d56a6ef3c067d80a6596c7881b8f4893c4b16e17fd5f2d0030128dfa0f0de4dce6cd908e29013ca088d61a26df5897fe97bebf6aa215d7d
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.7.2)
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,6 +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
98
+
99
+ nomad_namespace :maintenance, path: "maintenance-stuff" do
100
+ nomad_job :garbage_collection
101
+ end
95
102
  ```
96
103
 
97
104
  Deploy all jobs
@@ -133,6 +140,12 @@ cap production nomad:app:stderr
133
140
  cap production nomad:analytics:grafana:follow
134
141
  ```
135
142
 
143
+ Open job in web UI
144
+
145
+ ```shell
146
+ cap production nomad:app:ui
147
+ ```
148
+
136
149
  Create missing and delete unused namespaces
137
150
 
138
151
  ```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.7.2"
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,7 +15,12 @@ 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)
@@ -135,6 +140,11 @@ def nomad_job(name, attributes = {})
135
140
  task :follow do
136
141
  capistrano_nomad_display_job_logs(name, namespace: namespace, f: true)
137
142
  end
143
+
144
+ desc "Open job in web UI"
145
+ task :ui do
146
+ capistrano_nomad_open_job_ui(name, namespace: namespace)
147
+ end
138
148
  end
139
149
  end
140
150
 
@@ -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
@@ -402,3 +425,13 @@ end
402
425
  def capistrano_nomad_tail_job_logs(*args, **options)
403
426
  capistrano_nomad_display_job_logs(*args, **options.merge(tail: true, n: 50))
404
427
  end
428
+
429
+ def capistrano_nomad_open_job_ui(name, namespace: nil)
430
+ run_locally do
431
+ url = "#{fetch(:nomad_ui_url)}/ui/jobs/#{name}"
432
+ url += "@#{namespace}" if namespace
433
+
434
+ # Only macOS supported for now
435
+ execute(:open, url)
436
+ end
437
+ 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.7.2
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: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport