-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-options.go
152 lines (129 loc) · 3.1 KB
/
build-options.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package nixpacks
import (
"errors"
)
type (
BuildOptions struct {
//Path to the directory to build
Path string
//Name for the built image
Name string
//Save output directory instead of building the image
Output string
//Specify an entire build plan in json used to build the image
JsonPlan string
//Tag for the built image
Tag string
//Command to install language dependencies.
InstallCommand string
//Add labels to the built image
Labels []Label
//Command to build the image,
//it will overwrite the default build command
BuildCommand string
//Target platform for built image
Platform string
//Unique identifier to key cache.
//defaults to the current directory
//TODO: CacheKey string
//Command to run when starting the container
StartCommand string
//Outputs nixpacks related files
//to the current directory
CurrentDirectory bool
//Additional nix packages to install in the environment
NixPackages []string
//Additional apt packages to install in the environment
AptPackages []string
//Disable caching
NoCache bool
//Additional nix libraries to install in the environment
NixLibraries []string
//Environment variables to set in the container
Envs []Env
//Path to config file
Config string
//Do not error when no start command is set
NoErrorWithoutStartCommand bool
}
Env struct {
Key string
Value string
}
Label struct {
Key string
Value string
}
)
func (o *BuildOptions) Validate() error {
if o.Path == "" {
return errors.New("path must be specified")
}
return nil
}
func (o *BuildOptions) ToArgs() []string {
var args []string
if o.Name != "" {
args = append(args, "--name", o.Name)
}
if o.Output != "" {
args = append(args, "--out", o.Output)
}
if o.JsonPlan != "" {
args = append(args, "--json-plan", o.JsonPlan)
}
if o.Tag != "" {
args = append(args, "--tag", o.Tag)
}
if o.InstallCommand != "" {
args = append(args, "--install-cmd", o.InstallCommand)
}
if len(o.Labels) != 0 {
for _, label := range o.Labels {
args = append(args, "--label", label.Key+"="+label.Value)
}
}
if o.BuildCommand != "" {
args = append(args, "--build-cmd", o.BuildCommand)
}
if o.Platform != "" {
args = append(args, "--platform", o.Platform)
}
if o.StartCommand != "" {
args = append(args, "--start-cmd", o.StartCommand)
}
if o.CurrentDirectory {
args = append(args, "--current-directory")
}
if len(o.NixPackages) != 0 {
for _, pkg := range o.NixPackages {
args = append(args, "--pkgs", pkg)
}
}
if len(o.AptPackages) != 0 {
for _, pkg := range o.AptPackages {
args = append(args, "--apt", pkg)
}
}
if o.NoCache {
args = append(args, "--no-cache")
}
if len(o.NixLibraries) != 0 {
for _, lib := range o.NixLibraries {
args = append(args, "--libs", lib)
}
}
if len(o.Envs) != 0 {
for _, env := range o.Envs {
args = append(args, "--env", env.Key+"="+env.Value)
}
}
if o.Config != "" {
args = append(args, "--config", o.Config)
}
if o.NoErrorWithoutStartCommand {
args = append(args, "--no-error-without-start-cmd")
}
args = append(args, "--verbose")
return args
}