Skip to content

Commit

Permalink
Merge pull request #291 from depot/fix-pull
Browse files Browse the repository at this point in the history
Only add `-target` suffix to user tags if pulling multiple targets
  • Loading branch information
jacobwgillespie authored Jul 1, 2024
2 parents 84871ac + d7df0c0 commit f339f5c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/cmd/pull/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,36 @@ func validateTargets(targets []string, msg *cliv1.GetPullInfoResponse) error {
// Preconditions: isBake(msg.Options) && isSavedBuild(msg.Options) && validateTargets(targets, msg) == nil
func bakePullOpts(msg *cliv1.GetPullInfoResponse, targets, userTags []string, platform, progress string) []*pull {
pulls := []*pull{}

filteredOptions := []*cliv1.BuildOptions{}
for _, opt := range msg.Options {
// Bake builds always have a target name.
targetName := *opt.TargetName
if len(targets) > 0 && !slices.Contains(targets, targetName) {
continue
}
filteredOptions = append(filteredOptions, opt)
}

isPullingMultipleTargets := len(filteredOptions) > 1

for _, opt := range filteredOptions {
// Bake builds always have a target name.
targetName := *opt.TargetName

imageName := fmt.Sprintf("%s-%s", msg.Reference, targetName)

// If a user specified tags, we override the tags in the bake file
// with <TAG>-<TARGET_NAME>.
// with <TAG>-<TARGET_NAME> if pulling multiple targets.
tags := opt.Tags
if len(userTags) > 0 {
tags = make([]string, len(userTags))
for i, tag := range userTags {
tags[i] = fmt.Sprintf("%s-%s", tag, targetName)
if isPullingMultipleTargets {
tags = make([]string, len(userTags))
for i, tag := range userTags {
tags[i] = fmt.Sprintf("%s-%s", tag, targetName)
}
} else {
tags = userTags
}
}

Expand Down

0 comments on commit f339f5c

Please sign in to comment.