nomadsl 0.1.5 → 0.2.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 +4 -4
- data/README.md +3 -2
- data/lib/nomadsl.rb +77 -43
- data/lib/nomadsl/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 516890be1a6a0126435bc38bb940ddd4b42ed7bfdc449603eefc79c2836d76de
|
4
|
+
data.tar.gz: 52df9fdd5da1dc4e3fde08f53648501d4df8ea56142ae01b9ebaa63b345fa476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c84f1b38735ba993d61c58764c6d46c3c5a9b09fa04dcf448c5e773a7400e9de025203f028d2ef4ab280c35f126bc72e74de35f2fc87363ed9730331b5201b2
|
7
|
+
data.tar.gz: 94ce12136ed7aa33ee243b42ca4afb7bcece3a5a96c28b0b550454249df5ced9cb642337a8e9d37b5713d076f4da7b49c2c4474b73e600770e2dbcbbc7542024
|
data/README.md
CHANGED
@@ -6,7 +6,9 @@ Methods mapping to keys and attributes described in the Nomad Job Specification
|
|
6
6
|
(https://www.nomadproject.io/docs/job-specification/index.html) are defined in
|
7
7
|
an includable module.
|
8
8
|
|
9
|
-
|
9
|
+
Nomadsl supports Nomad configuration syntax through version 0.9.0. The mapping
|
10
|
+
of key and attribute names to method names is generally one-to-one, but you can
|
11
|
+
specify arbitrary configuration values to be rendered if necessary.
|
10
12
|
|
11
13
|
## Example: DSL direct to stdout
|
12
14
|
|
@@ -122,7 +124,6 @@ By requiring only `nomadsl`, you can inject these methods into another class:
|
|
122
124
|
|
123
125
|
## Roadmap
|
124
126
|
|
125
|
-
* Make all attributes explicitly callable
|
126
127
|
* Make subkeys embeddable in arglists if sensible
|
127
128
|
* Allow injecting comments into the rendered file
|
128
129
|
* Finish custom config blocks for each task driver
|
data/lib/nomadsl.rb
CHANGED
@@ -69,6 +69,21 @@ module Nomadsl
|
|
69
69
|
@out << "#{v.chomp}\nBLOB\n"
|
70
70
|
end
|
71
71
|
|
72
|
+
def strmap!(k, v)
|
73
|
+
die "Value for '#{k}' is nil" if v.nil?
|
74
|
+
strmap(k, v)
|
75
|
+
end
|
76
|
+
|
77
|
+
def strmap(k, v)
|
78
|
+
if v
|
79
|
+
block(k) do
|
80
|
+
v.each do |k2,v2|
|
81
|
+
str k2, v2
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
72
87
|
# try really hard
|
73
88
|
def any(k, v)
|
74
89
|
if v.nil?
|
@@ -137,13 +152,18 @@ module Nomadsl
|
|
137
152
|
str! :source, source
|
138
153
|
str :destination, destination
|
139
154
|
str :mode, mode
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
155
|
+
strmap :options, options
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# https://www.nomadproject.io/docs/job-specification/affinity.html
|
160
|
+
def affinity(attribute: nil, operator: nil, value: nil, weight: nil)
|
161
|
+
only :job, :group, :task, :device
|
162
|
+
block(:affinity) do
|
163
|
+
str! :attribute, attribute
|
164
|
+
str :operator, operator
|
165
|
+
str! :value, value
|
166
|
+
int :weight, weight
|
147
167
|
end
|
148
168
|
end
|
149
169
|
|
@@ -207,7 +227,7 @@ module Nomadsl
|
|
207
227
|
|
208
228
|
# https://www.nomadproject.io/docs/job-specification/constraint.html
|
209
229
|
def constraint(attribute: nil, operator: nil, value: nil)
|
210
|
-
only :job, :group, :task
|
230
|
+
only :job, :group, :task, :device
|
211
231
|
block(:constraint) do
|
212
232
|
str :attribute, attribute
|
213
233
|
str :operator, operator
|
@@ -221,6 +241,15 @@ module Nomadsl
|
|
221
241
|
list! :datacenters, d
|
222
242
|
end
|
223
243
|
|
244
|
+
# https://www.nomadproject.io/docs/job-specification/device.html
|
245
|
+
def device(name: nil, count: nil)
|
246
|
+
only :resources
|
247
|
+
block(:device, name) do
|
248
|
+
int :count, count
|
249
|
+
yield if block_given?
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
224
253
|
# https://www.nomadproject.io/docs/job-specification/dispatch_payload.html
|
225
254
|
def dispatch_payload(file:)
|
226
255
|
only :task
|
@@ -232,11 +261,7 @@ module Nomadsl
|
|
232
261
|
# https://www.nomadproject.io/docs/job-specification/env.html
|
233
262
|
def env(**opts)
|
234
263
|
only :task
|
235
|
-
|
236
|
-
opts.each do |k,v|
|
237
|
-
str k, v
|
238
|
-
end
|
239
|
-
end
|
264
|
+
strmap :env, opts
|
240
265
|
end
|
241
266
|
|
242
267
|
# https://www.nomadproject.io/docs/job-specification/ephemeral_disk.html
|
@@ -294,11 +319,7 @@ module Nomadsl
|
|
294
319
|
# https://www.nomadproject.io/docs/job-specification/meta.html
|
295
320
|
def meta(**opts)
|
296
321
|
only :job, :group, :task
|
297
|
-
|
298
|
-
opts.each do |k,v|
|
299
|
-
str k, v
|
300
|
-
end
|
301
|
-
end
|
322
|
+
strmap :meta, opts
|
302
323
|
end
|
303
324
|
|
304
325
|
# https://www.nomadproject.io/docs/job-specification/migrate.html
|
@@ -421,6 +442,25 @@ module Nomadsl
|
|
421
442
|
end
|
422
443
|
end
|
423
444
|
|
445
|
+
# https://www.nomadproject.io/docs/job-specification/spread.html
|
446
|
+
def spread(attribute: nil, weight: nil)
|
447
|
+
only :job, :group, :task
|
448
|
+
block(:spread) do
|
449
|
+
str! :attribute, attribute
|
450
|
+
int :weight, weight
|
451
|
+
yield if block_given?
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
# https://www.nomadproject.io/docs/job-specification/spread.html#target-parameters
|
456
|
+
def target(name: nil, value: nil, percent: nil)
|
457
|
+
only :spread
|
458
|
+
block(:target, name) do
|
459
|
+
str :value, value
|
460
|
+
str :weight, weight
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
424
464
|
# https://www.nomadproject.io/docs/job-specification/task.html
|
425
465
|
def task(t, driver: "exec", kill_signal: nil, kill_timeout: nil, leader: nil, shutdown_delay: nil, user: nil)
|
426
466
|
only :group
|
@@ -502,47 +542,41 @@ module Nomadsl
|
|
502
542
|
end
|
503
543
|
end
|
504
544
|
|
505
|
-
def
|
506
|
-
|
545
|
+
def _vault_aws_creds(path, export)
|
546
|
+
prefix = export ? "export " : ""
|
547
|
+
<<~DATA
|
507
548
|
{{with secret "#{path}"}}
|
508
|
-
AWS_ACCESS_KEY_ID={{.Data.access_key}}
|
509
|
-
AWS_SECRET_ACCESS_KEY={{.Data.secret_key}}
|
549
|
+
#{prefix}AWS_ACCESS_KEY_ID={{.Data.access_key}}
|
550
|
+
#{prefix}AWS_SECRET_ACCESS_KEY={{.Data.secret_key}}
|
510
551
|
{{if .Data.security_token}}
|
511
|
-
AWS_SESSION_TOKEN={{.Data.security_token}}
|
552
|
+
#{prefix}AWS_SESSION_TOKEN={{.Data.security_token}}
|
512
553
|
{{end}}
|
513
554
|
{{end}}
|
514
555
|
DATA
|
515
|
-
|
556
|
+
end
|
557
|
+
|
558
|
+
def preloaded_vault_aws_creds(name, path)
|
559
|
+
template(data: _vault_aws_creds(path, false), destination: "secrets/#{name}.env", env: true)
|
516
560
|
end
|
517
561
|
|
518
562
|
def vault_aws_creds(name, path)
|
519
|
-
data
|
563
|
+
template(data: _vault_aws_creds(path, true), destination: "secrets/#{name}.env")
|
564
|
+
end
|
565
|
+
|
566
|
+
def _vault_consul_creds(path, export)
|
567
|
+
prefix = export ? "export " : ""
|
568
|
+
<<~DATA
|
520
569
|
{{with secret "#{path}"}}
|
521
|
-
|
522
|
-
export AWS_SECRET_ACCESS_KEY={{.Data.secret_key}}
|
523
|
-
{{if .Data.security_token}}
|
524
|
-
export AWS_SESSION_TOKEN={{.Data.security_token}}
|
525
|
-
{{end}}
|
570
|
+
#{prefix}CONSUL_HTTP_TOKEN={{.Data.token}}
|
526
571
|
{{end}}
|
527
572
|
DATA
|
528
|
-
template(data: data, destination: "secrets/#{name}.env")
|
529
573
|
end
|
530
574
|
|
531
575
|
def preloaded_vault_consul_creds(name, path)
|
532
|
-
data
|
533
|
-
{{with secret "#{path}"}}
|
534
|
-
CONSUL_HTTP_TOKEN={{.Data.token}}
|
535
|
-
{{end}}
|
536
|
-
DATA
|
537
|
-
template(data: data, destination: "secrets/#{name}.env", env: true)
|
576
|
+
template(data: _vault_consul_creds(path, false), destination: "secrets/#{name}.env", env: true)
|
538
577
|
end
|
539
578
|
|
540
579
|
def vault_consul_creds(name, path)
|
541
|
-
data
|
542
|
-
{{with secret "#{path}"}}
|
543
|
-
export CONSUL_HTTP_TOKEN={{.Data.token}}
|
544
|
-
{{end}}
|
545
|
-
DATA
|
546
|
-
template(data: data, destination: "secrets/#{name}.env")
|
580
|
+
template(data: _vault_consul_creds(path, true), destination: "secrets/#{name}.env")
|
547
581
|
end
|
548
582
|
end
|
data/lib/nomadsl/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: daveadams@gmail.com
|
@@ -43,8 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
|
-
|
47
|
-
rubygems_version: 2.7.6
|
46
|
+
rubygems_version: 3.0.3
|
48
47
|
signing_key:
|
49
48
|
specification_version: 4
|
50
49
|
summary: Ruby DSL for generating Nomad job specification files
|