nomadsl 0.2.0 → 0.2.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: 516890be1a6a0126435bc38bb940ddd4b42ed7bfdc449603eefc79c2836d76de
4
- data.tar.gz: 52df9fdd5da1dc4e3fde08f53648501d4df8ea56142ae01b9ebaa63b345fa476
3
+ metadata.gz: 7e373810efb5dc4ba6cb71d0788e6e114c6bb9db7f5eacd7aa45e5a3d5cf8903
4
+ data.tar.gz: 94270c72e2bf26c7c387c87ae9d612dbb5ce2de26decadec9559cd963d1440c1
5
5
  SHA512:
6
- metadata.gz: 9c84f1b38735ba993d61c58764c6d46c3c5a9b09fa04dcf448c5e773a7400e9de025203f028d2ef4ab280c35f126bc72e74de35f2fc87363ed9730331b5201b2
7
- data.tar.gz: 94ce12136ed7aa33ee243b42ca4afb7bcece3a5a96c28b0b550454249df5ced9cb642337a8e9d37b5713d076f4da7b49c2c4474b73e600770e2dbcbbc7542024
6
+ metadata.gz: 8f1d263ba2e882a691724734df548cd91fd948bbd15d6ed2a51d8b5a7a376548dd1e6faaab24067d4defb5f713f40731cf83d459193637a5f1d14a2bf845522d
7
+ data.tar.gz: 752afd8496be3adfbe72c38dc7890c85e3f724f64ab5515a59e41bbfb9f580cf7659a377241b03f72a6b41cd79781bf4d09a28bc1b1fbb73b91c7dfe5acd5ed7
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Nomadsl is a Ruby DSL for generating Nomad job specification files.
4
4
 
5
- Methods mapping to keys and attributes described in the Nomad Job Specification
6
- (https://www.nomadproject.io/docs/job-specification/index.html) are defined in
7
- an includable module.
5
+ Methods mapping to keys and attributes described in the
6
+ [Nomad Job Specification](https://www.nomadproject.io/docs/job-specification/index.html)
7
+ are defined in an includable module.
8
8
 
9
- Nomadsl supports Nomad configuration syntax through version 0.9.0. The mapping
9
+ Nomadsl supports Nomad configuration syntax through version 0.12.0. The mapping
10
10
  of key and attribute names to method names is generally one-to-one, but you can
11
11
  specify arbitrary configuration values to be rendered if necessary.
12
12
 
@@ -89,9 +89,9 @@ Will generate this output:
89
89
 
90
90
  ## Using `nomadsl` as the interpreter
91
91
 
92
- As of 0.1.4, you can also set your shbang line to use `nomadsl` as the
93
- interpreter of the script. This will evaluate everything as Ruby, but with the
94
- necessary `nomadsl` boilerplate already built in:
92
+ You can also set your shbang line to use `nomadsl` as the interpreter of the
93
+ script. This will evaluate everything as Ruby, but with the necessary `nomadsl`
94
+ boilerplate already built in:
95
95
 
96
96
  #!/usr/bin/env nomadsl
97
97
 
data/lib/nomadsl.rb CHANGED
@@ -13,6 +13,10 @@ module Nomadsl
13
13
  @nomadsl_print = b
14
14
  end
15
15
 
16
+ def parent
17
+ @stack.last
18
+ end
19
+
16
20
  def only(*levels)
17
21
  unless levels.include? @stack.last
18
22
  loc = caller_locations(1,1)[0]
@@ -168,7 +172,7 @@ module Nomadsl
168
172
  end
169
173
 
170
174
  # https://www.nomadproject.io/docs/job-specification/service.html#check-parameters
171
- def check(address_mode: nil, args: nil, command: nil, grpc_service: nil, grpc_use_tls: nil, initial_status: nil, interval: nil, method: nil, name: nil, path: nil, port: nil, protocol: nil, timeout: nil, type: nil, tls_skip_verify: nil)
175
+ def check(address_mode: nil, args: nil, command: nil, grpc_service: nil, grpc_use_tls: nil, initial_status: nil, interval: nil, method: nil, name: nil, path: nil, expose: nil, port: nil, protocol: nil, task: nil, timeout: nil, type: nil, tls_skip_verify: nil)
172
176
  only :service
173
177
  block(:check) do
174
178
  str :address_mode, address_mode
@@ -177,14 +181,16 @@ module Nomadsl
177
181
  str :grpc_service, grpc_service
178
182
  bool :grpc_use_tls, grpc_use_tls
179
183
  str :initial_status, initial_status
180
- str :interval, interval
184
+ str! :interval, interval
181
185
  str :method, method
182
186
  str :name, name
183
187
  str :path, path
188
+ bool :expose, expose
184
189
  str :port, port
185
190
  str :protocol, protocol
186
- str :timeout, timeout
187
- str :type, type
191
+ str :task, task
192
+ str! :timeout, timeout
193
+ str! :type, type
188
194
  bool :tls_skip_verify, tls_skip_verify
189
195
  yield if block_given?
190
196
  end
@@ -202,7 +208,7 @@ module Nomadsl
202
208
 
203
209
  # https://www.nomadproject.io/docs/job-specification/task.html#config
204
210
  def config(**opts)
205
- only :task
211
+ only :task, :sidecar_task, :proxy
206
212
  config_method = "__config_#{@driver}".to_sym
207
213
  if private_methods.include?(config_method)
208
214
  send(config_method, **opts)
@@ -224,6 +230,14 @@ module Nomadsl
224
230
  end
225
231
  end
226
232
 
233
+ # https://www.nomadproject.io/docs/job-specification/connect
234
+ def connect(native: nil)
235
+ only :service
236
+ block(:connect) do
237
+ bool :native, native
238
+ yield if block_given?
239
+ end
240
+ end
227
241
 
228
242
  # https://www.nomadproject.io/docs/job-specification/constraint.html
229
243
  def constraint(attribute: nil, operator: nil, value: nil)
@@ -235,6 +249,16 @@ module Nomadsl
235
249
  end
236
250
  end
237
251
 
252
+ # https://www.nomadproject.io/docs/job-specification/csi_plugin
253
+ def csi_plugin(id: nil, type: nil, mount_dir: nil)
254
+ only :volume
255
+ block(:csi_plugin) do
256
+ str! :id, id
257
+ str! :type, type
258
+ str! :mount_dir, mount_dir
259
+ end
260
+ end
261
+
238
262
  # https://www.nomadproject.io/docs/job-specification/job.html#datacenters
239
263
  def datacenters(*d)
240
264
  only :job
@@ -258,9 +282,19 @@ module Nomadsl
258
282
  end
259
283
  end
260
284
 
285
+ # https://www.nomadproject.io/docs/job-specification/network#dns-parameters
286
+ def dns(servers: nil, searches: nil, options: nil)
287
+ only :network
288
+ block(:dns) do
289
+ list :servers, servers
290
+ list :searches, searches
291
+ list :options, options
292
+ end
293
+ end
294
+
261
295
  # https://www.nomadproject.io/docs/job-specification/env.html
262
296
  def env(**opts)
263
- only :task
297
+ only :task, :sidecar_task
264
298
  strmap :env, opts
265
299
  end
266
300
 
@@ -274,11 +308,21 @@ module Nomadsl
274
308
  end
275
309
  end
276
310
 
311
+ # https://www.nomadproject.io/docs/job-specification/expose
312
+ def expose
313
+ only :proxy
314
+ block(:expose) do
315
+ yield if block_given?
316
+ end
317
+ end
318
+
277
319
  # https://www.nomadproject.io/docs/job-specification/group.html
278
- def group(name, count: nil)
320
+ def group(name, count: nil, shutdown_delay: nil, stop_after_client_disconnect: nil)
279
321
  only :job
280
322
  block(:group, name) do
281
323
  int :count, count
324
+ str :shutdown_delay, shutdown_delay
325
+ str :stop_after_client_disconnect, stop_after_client_disconnect
282
326
  yield
283
327
  end
284
328
  end
@@ -291,6 +335,15 @@ module Nomadsl
291
335
  end
292
336
  end
293
337
 
338
+ # https://www.nomadproject.io/docs/job-specification/lifecycle
339
+ def lifecycle(hook: nil, sidecar: nil)
340
+ only :task
341
+ block(:lifecycle) do
342
+ str :hook, hook
343
+ bool :sidecar, sidecar
344
+ end
345
+ end
346
+
294
347
  # https://www.nomadproject.io/docs/job-specification/job.html
295
348
  def job(j)
296
349
  # initialize the variables since this is the actual root
@@ -309,7 +362,7 @@ module Nomadsl
309
362
 
310
363
  # https://www.nomadproject.io/docs/job-specification/logs.html
311
364
  def logs(max_files: nil, max_file_size: nil)
312
- only :task
365
+ only :task, :sidecar_task
313
366
  block(:logs) do
314
367
  int :max_files, max_files
315
368
  int :max_file_size, max_file_size
@@ -318,7 +371,7 @@ module Nomadsl
318
371
 
319
372
  # https://www.nomadproject.io/docs/job-specification/meta.html
320
373
  def meta(**opts)
321
- only :job, :group, :task
374
+ only :job, :group, :task, :sidecar_task, :region
322
375
  strmap :meta, opts
323
376
  end
324
377
 
@@ -333,6 +386,14 @@ module Nomadsl
333
386
  end
334
387
  end
335
388
 
389
+ # https://www.nomadproject.io/docs/job-specification/multiregion
390
+ def multiregion
391
+ only :job
392
+ block(:multiregion) do
393
+ yield if block_given?
394
+ end
395
+ end
396
+
336
397
  # https://www.nomadproject.io/docs/job-specification/job.html#namespace
337
398
  # Supported by Nomad Enterprise ONLY
338
399
  def namespace(n)
@@ -360,6 +421,17 @@ module Nomadsl
360
421
  end
361
422
  end
362
423
 
424
+ # https://www.nomadproject.io/docs/job-specification/expose#path-parameters
425
+ def path(path: nil, protocol: nil, local_path_port: nil)
426
+ only :expose
427
+ block(:path) do
428
+ str! :path, path
429
+ str! :protocol, protocol
430
+ int! :local_path_port, local_path_port
431
+ yield if block_given?
432
+ end
433
+ end
434
+
363
435
  # https://www.nomadproject.io/docs/job-specification/periodic.html
364
436
  def periodic(cron: nil, prohibit_overlap: nil, time_zone: nil)
365
437
  only :job
@@ -370,9 +442,15 @@ module Nomadsl
370
442
  end
371
443
  end
372
444
 
445
+ # https://www.nomadproject.io/docs/job-specification/scaling#policy
446
+ def policy(**args)
447
+ only :scaling
448
+ any :policy, args
449
+ end
450
+
373
451
  # https://www.nomadproject.io/docs/job-specification/network.html#port
374
452
  def port(n, static: nil)
375
- only :network
453
+ only :network, :path
376
454
  if static
377
455
  block(:port, n) do
378
456
  int :static, static
@@ -388,10 +466,29 @@ module Nomadsl
388
466
  int! :priority, p
389
467
  end
390
468
 
469
+ # https://www.nomadproject.io/docs/job-specification/proxy
470
+ def proxy(local_service_address: nil, local_service_port: nil)
471
+ only :sidecar_service
472
+ block(:proxy) do
473
+ str :local_service_address, local_service_address
474
+ int :local_service_port, local_service_port
475
+ yield if block_given?
476
+ end
477
+ end
478
+
391
479
  # https://www.nomadproject.io/docs/job-specification/job.html#region
392
- def region(r)
393
- only :job
394
- str! :region, r
480
+ # https://www.nomadproject.io/docs/job-specification/multiregion#region-parameters
481
+ def region(name, count: nil, datacenters: nil)
482
+ only :job, :multiregion
483
+ if parent == :job
484
+ str! :region, name
485
+ elsif parent == :multiregion
486
+ block(:region, name) do
487
+ int :count, count
488
+ list :datacenters, datacenters
489
+ yield if block_given?
490
+ end
491
+ end
395
492
  end
396
493
 
397
494
  # https://www.nomadproject.io/docs/job-specification/reschedule.html
@@ -409,10 +506,9 @@ module Nomadsl
409
506
 
410
507
  # https://www.nomadproject.io/docs/job-specification/resources.html
411
508
  def resources(cpu: nil, iops: nil, memory: nil)
412
- only :task
509
+ only :task, :sidecar_task
413
510
  block(:resources) do
414
511
  int :cpu, cpu
415
- int :iops, iops
416
512
  int :memory, memory
417
513
  yield if block_given?
418
514
  end
@@ -429,6 +525,17 @@ module Nomadsl
429
525
  end
430
526
  end
431
527
 
528
+ # https://www.nomadproject.io/docs/job-specification/scaling
529
+ def scaling(min: nil, max: nil, enabled: nil)
530
+ only :group
531
+ block(:scaling) do
532
+ int :min, min
533
+ int! :max, max
534
+ bool :enabled, enabled
535
+ yield if block_given?
536
+ end
537
+ end
538
+
432
539
  # https://www.nomadproject.io/docs/job-specification/service.html
433
540
  def service(address_mode: nil, canary_tags: nil, name: nil, port: nil, tags: nil)
434
541
  only :task
@@ -442,6 +549,30 @@ module Nomadsl
442
549
  end
443
550
  end
444
551
 
552
+ # https://www.nomadproject.io/docs/job-specification/sidecar_service
553
+ def sidecar_service(tags: nil, port: nil)
554
+ only :connect
555
+ block(:sidecar_service) do
556
+ list :tags, tags
557
+ int :port, port
558
+ yield if block_given?
559
+ end
560
+ end
561
+
562
+ # https://www.nomadproject.io/docs/job-specification/sidecar_task
563
+ def sidecar_task(name: nil, driver: nil, user: nil, logs: nil, kill_timeout: nil, shutdown_delay: nil, kill_signal: nil)
564
+ only :connect
565
+ block(:sidecar_task) do
566
+ str :name, name
567
+ str :driver, driver
568
+ str :user, user
569
+ str :kill_timeout, kill_timeout
570
+ str :shutdown_delay, shutdown_delay
571
+ str :kill_signal, kill_signal
572
+ yielf if block_given?
573
+ end
574
+ end
575
+
445
576
  # https://www.nomadproject.io/docs/job-specification/spread.html
446
577
  def spread(attribute: nil, weight: nil)
447
578
  only :job, :group, :task
@@ -452,6 +583,15 @@ module Nomadsl
452
583
  end
453
584
  end
454
585
 
586
+ # https://www.nomadproject.io/docs/job-specification/multiregion#strategy-parameters
587
+ def strategy(max_parallel: nil, on_failure: nil)
588
+ only :multiregion
589
+ block(:strategy) do
590
+ int :max_parallel, max_parallel
591
+ str :on_failure, on_failure
592
+ end
593
+ end
594
+
455
595
  # https://www.nomadproject.io/docs/job-specification/spread.html#target-parameters
456
596
  def target(name: nil, value: nil, percent: nil)
457
597
  only :spread
@@ -516,6 +656,15 @@ module Nomadsl
516
656
  end
517
657
  end
518
658
 
659
+ # https://www.nomadproject.io/docs/job-specification/upstreams
660
+ def upstreams(destination_name: nil, local_bind_port: nil)
661
+ only :proxy
662
+ block(:upstreams) do
663
+ str! :destination_name, destination_name
664
+ int! :local_bind_port, local_bind_port
665
+ end
666
+ end
667
+
519
668
  # https://www.nomadproject.io/docs/job-specification/vault.html
520
669
  def vault(change_mode: nil, change_token: nil, env: nil, policies: nil)
521
670
  only :job, :group, :task
@@ -527,6 +676,26 @@ module Nomadsl
527
676
  end
528
677
  end
529
678
 
679
+ # https://www.nomadproject.io/docs/job-specification/volume
680
+ def volume(name, type: nil, source: nil, read_only: nil)
681
+ only :group
682
+ block(:volume, name) do
683
+ str :type, type
684
+ str! :source, source
685
+ bool :read_only, read_only
686
+ end
687
+ end
688
+
689
+ # https://www.nomadproject.io/docs/job-specification/volume_mount
690
+ def volume_mount(volume: nil, destination: nil, read_only: nil)
691
+ only :task
692
+ block(:volume_mount) do
693
+ str! :volume, volume
694
+ str! :destination, destination
695
+ bool :read_only, read_only
696
+ end
697
+ end
698
+
530
699
  # https://www.nomadproject.io/docs/job-specification/job.html#vault_token
531
700
  # NOTE: explicitly unsupported, dangerous
532
701
 
@@ -544,8 +713,12 @@ module Nomadsl
544
713
 
545
714
  def _vault_aws_creds(path, export)
546
715
  prefix = export ? "export " : ""
716
+ path = path.is_a?(String) ? [path] : path
717
+ args = path.reduce("") do |concat, str|
718
+ concat = "#{concat} \"#{str}\""
719
+ end
547
720
  <<~DATA
548
- {{with secret "#{path}"}}
721
+ {{with secret #{args}}}
549
722
  #{prefix}AWS_ACCESS_KEY_ID={{.Data.access_key}}
550
723
  #{prefix}AWS_SECRET_ACCESS_KEY={{.Data.secret_key}}
551
724
  {{if .Data.security_token}}
@@ -565,8 +738,12 @@ module Nomadsl
565
738
 
566
739
  def _vault_consul_creds(path, export)
567
740
  prefix = export ? "export " : ""
741
+ path = path.is_a?(String) ? [path] : path
742
+ args = path.reduce("") do |concat, str|
743
+ concat = "#{concat} \"#{str}\""
744
+ end
568
745
  <<~DATA
569
- {{with secret "#{path}"}}
746
+ {{with secret #{args}}}
570
747
  #{prefix}CONSUL_HTTP_TOKEN={{.Data.token}}
571
748
  {{end}}
572
749
  DATA
@@ -1,3 +1,3 @@
1
1
  module Nomadsl
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nomadsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Adams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-22 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: daveadams@gmail.com
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  - !ruby/object:Gem::Version
44
44
  version: '0'
45
45
  requirements: []
46
- rubygems_version: 3.0.3
46
+ rubygems_version: 3.1.4
47
47
  signing_key:
48
48
  specification_version: 4
49
49
  summary: Ruby DSL for generating Nomad job specification files