Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion mkctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type buildParams struct {
target string
verbose bool
annotations map[string]string // OCI image annotations
volumes map[string]struct{}
}

func main() {
Expand All @@ -94,6 +95,7 @@ func main() {
gopaths = flag.String("gopaths", "", "comma-separated list of go paths in src:dst form")
files = flag.String("files", "", "comma-separated list of static files in src:dst form")
repos = flag.String("repos", "", "comma-separated list of image registries")
volumes = flag.String("volumes", "", "comma-separated list of volumes to add")
tagArg = flag.String("tags", "", "comma-separated tags")
ldflagsArg = flag.String("ldflags", "", "the --ldflags value to pass to go")
gotags = flag.String("gotags", "", "the --tags value to pass to go")
Expand Down Expand Up @@ -136,6 +138,13 @@ func main() {
if len(paths) == 0 && len(staticFiles) == 0 {
log.Fatal("at least one of --files or --gopaths must be set")
}
var vols map[string]struct{}
for vol := range strings.SplitSeq(*volumes, ",") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this requires Go 1.24. But the go.mod still says 1.23.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed go.mod in #31

if vols == nil {
vols = make(map[string]struct{})
}
vols[strings.TrimSpace(vol)] = struct{}{}
Comment on lines +143 to +146
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The volume parsing logic doesn't handle empty strings correctly. When the volumes flag is empty (default value ""), strings.SplitSeq will still yield one iteration with an empty string, which will be added to the map after TrimSpace. This results in an empty volume key being added to the volumes map.

Consider adding a check to skip empty strings after trimming, or check if the volumes string is empty before attempting to parse it.

Suggested change
if vols == nil {
vols = make(map[string]struct{})
}
vols[strings.TrimSpace(vol)] = struct{}{}
vol = strings.TrimSpace(vol)
if vol == "" {
continue
}
if vols == nil {
vols = make(map[string]struct{})
}
vols[vol] = struct{}{}

Copilot uses AI. Check for mistakes.
}

bp := &buildParams{
baseImage: *baseImage,
Expand All @@ -149,6 +158,7 @@ func main() {
verbose: *verbose,
goarch: strings.Split(*goarch, ","),
annotations: parseAnnotations(*annotations),
volumes: vols,
}

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

if args := flag.Args(); len(args) > 0 {
img, err = mutate.Config(img, v1.Config{
Cmd: args,
Cmd: args,
Volumes: bp.volumes,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part shouldn't be conditional on len(args) > 0 (setting an entrypoint)

I noted this in my upcoming PR to add env var support too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll handle this fix in my upcoming PR.

})
if err != nil {
return err
Expand Down