Skip to content

Commit

Permalink
fix: Initialize nil maps in image config
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Dec 9, 2024
1 parent 1398335 commit 99ec471
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions imgconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ func MergeSpecImage(spec *Spec, targetKey string) *ImageConfig {

cfg.Env = append(cfg.Env, i.Env...)

for k, v := range i.Volumes {
cfg.Volumes[k] = v
if len(i.Volumes) > 0 {
if cfg.Volumes == nil {
cfg.Volumes = make(map[string]struct{}, len(i.Volumes))
}
for k, v := range i.Volumes {
cfg.Volumes[k] = v
}
}

for k, v := range i.Labels {
cfg.Labels[k] = v
if len(i.Labels) > 0 {
if cfg.Labels == nil {
cfg.Labels = make(map[string]string, len(i.Labels))
}
for k, v := range i.Labels {
cfg.Labels[k] = v
}
}

if i.WorkingDir != "" {
Expand Down

0 comments on commit 99ec471

Please sign in to comment.