Skip to content

Commit fe67446

Browse files
raggibradfitz
authored andcommitted
mkctr: add support for volumes
Volumes are the conventional way to specify state directories.
1 parent cdbf7c0 commit fe67446

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

mkctr.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type buildParams struct {
8686
target string
8787
verbose bool
8888
annotations map[string]string // OCI image annotations
89+
volumes map[string]struct{}
8990
}
9091

9192
func main() {
@@ -94,6 +95,7 @@ func main() {
9495
gopaths = flag.String("gopaths", "", "comma-separated list of go paths in src:dst form")
9596
files = flag.String("files", "", "comma-separated list of static files in src:dst form")
9697
repos = flag.String("repos", "", "comma-separated list of image registries")
98+
volumes = flag.String("volumes", "", "comma-separated list of volumes to add")
9799
tagArg = flag.String("tags", "", "comma-separated tags")
98100
ldflagsArg = flag.String("ldflags", "", "the --ldflags value to pass to go")
99101
gotags = flag.String("gotags", "", "the --tags value to pass to go")
@@ -136,6 +138,13 @@ func main() {
136138
if len(paths) == 0 && len(staticFiles) == 0 {
137139
log.Fatal("at least one of --files or --gopaths must be set")
138140
}
141+
var vols map[string]struct{}
142+
for vol := range strings.SplitSeq(*volumes, ",") {
143+
if vols == nil {
144+
vols = make(map[string]struct{})
145+
}
146+
vols[strings.TrimSpace(vol)] = struct{}{}
147+
}
139148

140149
bp := &buildParams{
141150
baseImage: *baseImage,
@@ -149,6 +158,7 @@ func main() {
149158
verbose: *verbose,
150159
goarch: strings.Split(*goarch, ","),
151160
annotations: parseAnnotations(*annotations),
161+
volumes: vols,
152162
}
153163

154164
if err := fetchAndBuild(bp); err != nil {
@@ -306,7 +316,8 @@ func fetchAndBuild(bp *buildParams) error {
306316

307317
if args := flag.Args(); len(args) > 0 {
308318
img, err = mutate.Config(img, v1.Config{
309-
Cmd: args,
319+
Cmd: args,
320+
Volumes: bp.volumes,
310321
})
311322
if err != nil {
312323
return err

0 commit comments

Comments
 (0)