-
Notifications
You must be signed in to change notification settings - Fork 85
/
spec.go
104 lines (95 loc) · 3.21 KB
/
spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package cliflags
import (
"github.com/spf13/pflag"
"github.com/bacalhau-project/bacalhau/cmd/util/opts"
"github.com/bacalhau-project/bacalhau/pkg/model"
)
const InputUsageMsg = `Mount URIs as inputs to the job. Can be specified multiple times. Format: src=URI,dst=PATH[,opt=key=value]
Examples:
# Mount IPFS CID to /inputs directory
-i ipfs://QmeZRGhe4PmjctYVSVHuEiA9oSXnqmYa4kQubSHgWbjv72
# Mount S3 object to a specific path
-i s3://bucket/key,dst=/my/input/path
# Mount S3 object with specific endpoint and region
-i src=s3://bucket/key,dst=/my/input/path,opt=endpoint=https://s3.example.com,opt=region=us-east-1
`
func NewSpecFlagDefaultSettings() *SpecFlagSettings {
return &SpecFlagSettings{
Publisher: opts.NewPublisherOpt(),
Inputs: opts.StorageOpt{},
OutputVolumes: []string{"outputs:/outputs"},
EnvVar: []string{},
Timeout: int64(model.DefaultJobTimeout.Seconds()),
Labels: []string{},
Selector: "",
DoNotTrack: false,
}
}
type SpecFlagSettings struct {
Publisher opts.PublisherOpt // Publisher - publisher.Publisher
Inputs opts.StorageOpt // Array of inputs
OutputVolumes []string // Array of output volumes in 'name:mount point' form
EnvVar []string // Array of environment variables
Timeout int64 // Job execution timeout in seconds
Labels []string // Labels for the job on the Bacalhau network (for searching)
Selector string // Selector (label query) to filter nodes on which this job can be executed
DoNotTrack bool
}
func SpecFlags(settings *SpecFlagSettings) *pflag.FlagSet {
flags := pflag.NewFlagSet("Spec settings", pflag.ContinueOnError)
flags.VarP(
&settings.Publisher,
"publisher",
"p",
"Where to publish the result of the job",
)
flags.VarP(
&settings.Inputs,
"input",
"i",
InputUsageMsg,
)
flags.StringSliceVarP(
&settings.OutputVolumes,
"output",
"o",
settings.OutputVolumes,
`name:path of the output data volumes. `+
`'outputs:/outputs' is always added unless '/outputs' is mapped to a different name.`,
)
flags.StringSliceVarP(
&settings.EnvVar,
"env",
"e",
settings.EnvVar,
`The environment variables to supply to the job (e.g. --env FOO=bar --env BAR=baz)`,
)
flags.Int64Var(
&settings.Timeout,
"timeout",
settings.Timeout,
`Job execution timeout in seconds (e.g. 300 for 5 minutes)`,
)
flags.StringSliceVarP(
&settings.Labels,
"labels",
"l",
settings.Labels,
`List of labels for the job. Enter multiple in the format '-l a -l 2'. All characters not matching /a-zA-Z0-9_:|-/ and all emojis will be stripped.`, //nolint:lll // Documentation, ok if long.
)
flags.StringVarP(
&settings.Selector,
"selector",
"s",
settings.Selector,
`Selector (label query) to filter nodes on which this job can be executed, supports '=', '==', and '!='.(e.g. -s key1=value1,key2=value2). Matching objects must satisfy all of the specified label constraints.`, //nolint:lll // Documentation, ok if long.
)
flags.BoolVar(
&settings.DoNotTrack,
"do-not-track",
settings.DoNotTrack,
// TODO(forrest): we need a better definition of this
`When true the job will not be tracked(?) TODO BETTER DEFINITION`,
)
return flags
}