@@ -2,17 +2,18 @@ package procfile
2
2
3
3
// ////////////////////////////////////////////////////////////////////////////////// //
4
4
// //
5
- // Copyright (c) 2006-2019 FB GROUP LLC //
5
+ // Copyright (c) 2006-2020 FB GROUP LLC //
6
6
// //
7
7
// ////////////////////////////////////////////////////////////////////////////////// //
8
8
9
9
import (
10
10
"fmt"
11
11
"strings"
12
12
13
- "pkg.re/essentialkaos/ek.v10/log"
13
+ "pkg.re/essentialkaos/ek.v12/log"
14
+ "pkg.re/essentialkaos/ek.v12/strutil"
14
15
15
- "pkg.re/essentialkaos/go-simpleyaml.v1 "
16
+ "pkg.re/essentialkaos/go-simpleyaml.v2 "
16
17
)
17
18
18
19
// ////////////////////////////////////////////////////////////////////////////////// //
@@ -53,11 +54,7 @@ func parseV2Procfile(data []byte, config *Config) (*Application, error) {
53
54
}
54
55
55
56
if yaml .IsExist ("working_directory" ) {
56
- app .WorkingDir , err = yamlGetSafe (yaml , "working_directory" )
57
-
58
- if err != nil {
59
- return nil , fmt .Errorf ("Can't parse working_directory value: %v" , err )
60
- }
57
+ app .WorkingDir = yamlGetSafe (yaml , "working_directory" )
61
58
}
62
59
63
60
if yaml .IsExist ("start_on_runlevel" ) {
@@ -77,13 +74,22 @@ func parseV2Procfile(data []byte, config *Config) (*Application, error) {
77
74
}
78
75
79
76
if yaml .IsExist ("start_on_device" ) {
80
- app .StartDevice , err = yamlGetSafe (yaml , "start_on_device" )
77
+ app .StartDevice = yamlGetSafe (yaml , "start_on_device" )
78
+ }
79
+
80
+ if yaml .IsExist ("strong_dependencies" ) {
81
+ app .StrongDependencies , err = yaml .Get ("strong_dependencies" ).Bool ()
81
82
82
83
if err != nil {
83
- return nil , fmt .Errorf ("Can't parse start_on_device value: %v" , err )
84
+ return nil , fmt .Errorf ("Can't parse strong_dependencies value: %v" , err )
84
85
}
85
86
}
86
87
88
+ if yaml .IsExist ("depends" ) {
89
+ deps := yamlGetSafe (yaml , "depends" )
90
+ app .Depends = strutil .Fields (deps )
91
+ }
92
+
87
93
addCrossLink (app )
88
94
89
95
return app , nil
@@ -131,15 +137,9 @@ func parseV2Services(yaml *simpleyaml.Yaml, commands map[interface{}]interface{}
131
137
132
138
// parseV2Commands parse service commands
133
139
func parseV2Commands (service * Service , yaml * simpleyaml.Yaml ) error {
134
- var err error
135
140
var cmd , log string
136
141
137
- cmd , err = yamlGetSafe (yaml , "command" )
138
-
139
- if err != nil {
140
- return fmt .Errorf ("Can't parse \" command\" value: %v" , err )
141
- }
142
-
142
+ cmd = yamlGetSafe (yaml , "command" )
143
143
cmd , log , _ = parseCommand (cmd )
144
144
145
145
if log != "" {
@@ -149,19 +149,11 @@ func parseV2Commands(service *Service, yaml *simpleyaml.Yaml) error {
149
149
service .Cmd = cmd
150
150
151
151
if yaml .IsExist ("pre" ) {
152
- service .PreCmd , err = yamlGetSafe (yaml , "pre" )
153
-
154
- if err != nil {
155
- return fmt .Errorf ("Can't parse \" pre\" value: %v" , err )
156
- }
152
+ service .PreCmd = yamlGetSafe (yaml , "pre" )
157
153
}
158
154
159
155
if yaml .IsExist ("post" ) {
160
- service .PostCmd , err = yamlGetSafe (yaml , "post" )
161
-
162
- if err != nil {
163
- return fmt .Errorf ("Can't parse \" post\" value: %v" , err )
164
- }
156
+ service .PostCmd = yamlGetSafe (yaml , "post" )
165
157
}
166
158
167
159
return nil
@@ -175,19 +167,11 @@ func parseV2Options(options *ServiceOptions, yaml *simpleyaml.Yaml) error {
175
167
options .IsRespawnEnabled = true
176
168
177
169
if yaml .IsExist ("working_directory" ) {
178
- options .WorkingDir , err = yamlGetSafe (yaml , "working_directory" )
179
-
180
- if err != nil {
181
- return formatPropError ("working_directory" , err )
182
- }
170
+ options .WorkingDir = yamlGetSafe (yaml , "working_directory" )
183
171
}
184
172
185
173
if yaml .IsExist ("log" ) {
186
- options .LogFile , err = yamlGetSafe (yaml , "log" )
187
-
188
- if err != nil {
189
- return formatPropError ("log" , err )
190
- }
174
+ options .LogFile = yamlGetSafe (yaml , "log" )
191
175
}
192
176
193
177
if yaml .IsExist ("kill_timeout" ) {
@@ -199,27 +183,15 @@ func parseV2Options(options *ServiceOptions, yaml *simpleyaml.Yaml) error {
199
183
}
200
184
201
185
if yaml .IsExist ("kill_signal" ) {
202
- options .KillSignal , err = yamlGetSafe (yaml , "kill_signal" )
203
-
204
- if err != nil {
205
- return formatPropError ("kill_signal" , err )
206
- }
186
+ options .KillSignal = yamlGetSafe (yaml , "kill_signal" )
207
187
}
208
188
209
189
if yaml .IsExist ("kill_mode" ) {
210
- options .KillMode , err = yamlGetSafe (yaml , "kill_mode" )
211
-
212
- if err != nil {
213
- return formatPropError ("kill_mode" , err )
214
- }
190
+ options .KillMode = yamlGetSafe (yaml , "kill_mode" )
215
191
}
216
192
217
193
if yaml .IsExist ("reload_signal" ) {
218
- options .ReloadSignal , err = yamlGetSafe (yaml , "reload_signal" )
219
-
220
- if err != nil {
221
- return formatPropError ("reload_signal" , err )
222
- }
194
+ options .ReloadSignal = yamlGetSafe (yaml , "reload_signal" )
223
195
}
224
196
225
197
if yaml .IsExist ("count" ) {
@@ -241,11 +213,7 @@ func parseV2Options(options *ServiceOptions, yaml *simpleyaml.Yaml) error {
241
213
}
242
214
243
215
if yaml .IsExist ("env_file" ) {
244
- options .EnvFile , err = yamlGetSafe (yaml , "env_file" )
245
-
246
- if err != nil {
247
- return formatPropError ("env_file" , err )
248
- }
216
+ options .EnvFile = yamlGetSafe (yaml , "env_file" )
249
217
}
250
218
251
219
if yaml .IsPathExist ("respawn" , "count" ) || yaml .IsPathExist ("respawn" , "interval" ) {
@@ -340,36 +308,24 @@ func parseV2Resources(yaml *simpleyaml.Yaml) (*Resources, error) {
340
308
}
341
309
}
342
310
343
- if yaml .IsExist ("memory_low" ) {
344
- resources .MemoryLow , err = yamlGetSafe (yaml , "memory_low" )
311
+ if yaml .IsExist ("cpu_affinity" ) {
312
+ resources .CPUAffinity = yamlGetSafe (yaml , "cpu_affinity" )
313
+ }
345
314
346
- if err != nil {
347
- return nil , formatPropError ("resources:memory_low" , err )
348
- }
315
+ if yaml .IsExist ("memory_low" ) {
316
+ resources .MemoryLow = yamlGetSafe (yaml , "memory_low" )
349
317
}
350
318
351
319
if yaml .IsExist ("memory_high" ) {
352
- resources .MemoryHigh , err = yamlGetSafe (yaml , "memory_high" )
353
-
354
- if err != nil {
355
- return nil , formatPropError ("resources:memory_high" , err )
356
- }
320
+ resources .MemoryHigh = yamlGetSafe (yaml , "memory_high" )
357
321
}
358
322
359
323
if yaml .IsExist ("memory_max" ) {
360
- resources .MemoryMax , err = yamlGetSafe (yaml , "memory_max" )
361
-
362
- if err != nil {
363
- return nil , formatPropError ("resources:memory_max" , err )
364
- }
324
+ resources .MemoryMax = yamlGetSafe (yaml , "memory_max" )
365
325
}
366
326
367
327
if yaml .IsExist ("memory_swap_max" ) {
368
- resources .MemorySwapMax , err = yamlGetSafe (yaml , "memory_swap_max" )
369
-
370
- if err != nil {
371
- return nil , formatPropError ("resources:memory_swap_max" , err )
372
- }
328
+ resources .MemorySwapMax = yamlGetSafe (yaml , "memory_swap_max" )
373
329
}
374
330
375
331
if yaml .IsExist ("task_max" ) {
@@ -397,73 +353,39 @@ func parseV2Resources(yaml *simpleyaml.Yaml) (*Resources, error) {
397
353
}
398
354
399
355
if yaml .IsExist ("io_device_weight" ) {
400
- resources .IODeviceWeight , err = yamlGetSafe (yaml , "io_device_weight" )
401
-
402
- if err != nil {
403
- return nil , formatPropError ("resources:io_device_weight" , err )
404
- }
356
+ resources .IODeviceWeight = yamlGetSafe (yaml , "io_device_weight" )
405
357
}
406
358
407
359
if yaml .IsExist ("io_read_bandwidth_max" ) {
408
- resources .IOReadBandwidthMax , err = yamlGetSafe (yaml , "io_read_bandwidth_max" )
409
-
410
- if err != nil {
411
- return nil , formatPropError ("resources:io_read_bandwidth_max" , err )
412
- }
360
+ resources .IOReadBandwidthMax = yamlGetSafe (yaml , "io_read_bandwidth_max" )
413
361
}
414
362
415
363
if yaml .IsExist ("io_write_bandwidth_max" ) {
416
- resources .IOWriteBandwidthMax , err = yamlGetSafe (yaml , "io_write_bandwidth_max" )
417
-
418
- if err != nil {
419
- return nil , formatPropError ("resources:io_write_bandwidth_max" , err )
420
- }
364
+ resources .IOWriteBandwidthMax = yamlGetSafe (yaml , "io_write_bandwidth_max" )
421
365
}
422
366
423
367
if yaml .IsExist ("io_read_iops_max" ) {
424
- resources .IOReadIOPSMax , err = yamlGetSafe (yaml , "io_read_iops_max" )
425
-
426
- if err != nil {
427
- return nil , formatPropError ("resources:io_read_iops_max" , err )
428
- }
368
+ resources .IOReadIOPSMax = yamlGetSafe (yaml , "io_read_iops_max" )
429
369
}
430
370
431
371
if yaml .IsExist ("io_write_iops_max" ) {
432
- resources .IOWriteIOPSMax , err = yamlGetSafe (yaml , "io_write_iops_max" )
433
-
434
- if err != nil {
435
- return nil , formatPropError ("resources:io_write_iops_max" , err )
436
- }
372
+ resources .IOWriteIOPSMax = yamlGetSafe (yaml , "io_write_iops_max" )
437
373
}
438
374
439
375
if yaml .IsExist ("ip_address_allow" ) {
440
- resources .IPAddressAllow , err = yamlGetSafe (yaml , "ip_address_allow" )
441
-
442
- if err != nil {
443
- return nil , formatPropError ("resources:ip_address_allow" , err )
444
- }
376
+ resources .IPAddressAllow = yamlGetSafe (yaml , "ip_address_allow" )
445
377
}
446
378
447
379
if yaml .IsExist ("ip_address_deny" ) {
448
- resources .IPAddressDeny , err = yamlGetSafe (yaml , "ip_address_deny" )
449
-
450
- if err != nil {
451
- return nil , formatPropError ("resources:ip_address_deny" , err )
452
- }
380
+ resources .IPAddressDeny = yamlGetSafe (yaml , "ip_address_deny" )
453
381
}
454
382
455
383
return resources , nil
456
384
}
457
385
458
386
// yamlGetSafe returns string from YAML without potentially unsafe symbols
459
- func yamlGetSafe (yaml * simpleyaml.Yaml , propName string ) (string , error ) {
460
- value , err := yaml .Get (propName ).String ()
461
-
462
- if err != nil {
463
- return "" , err
464
- }
465
-
466
- return strings .Trim (value , "\n \r " ), nil
387
+ func yamlGetSafe (yaml * simpleyaml.Yaml , propName string ) string {
388
+ return strings .Trim (yaml .Get (propName ).Dump (), "\n \r " )
467
389
}
468
390
469
391
// formatPropError format property parsing error
0 commit comments