Skip to content

Commit b2b8385

Browse files
committed
Fix "re-tagging bug" by abusing docker build to multi-tag a single-line synthetic Dockerfile
1 parent 87b6419 commit b2b8385

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cmd/bashbrew/cmd-build.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/urfave/cli"
78
)
@@ -132,6 +133,15 @@ func cmdBuild(c *cli.Context) error {
132133
}
133134
} else {
134135
fmt.Printf("Using %s (%s)\n", cacheTag, r.EntryIdentifier(entry))
136+
137+
if !dryRun {
138+
// https://github.com/docker-library/bashbrew/pull/61/files#r1044926620
139+
// abusing "docker build" for "tag something a lot of times, but efficiently" 👀
140+
err := dockerBuild(imageTags, "", strings.NewReader("FROM "+cacheTag), "")
141+
if err != nil {
142+
return cli.NewMultiError(fmt.Errorf(`failed tagging %q: %q`, cacheTag, strings.Join(imageTags, ", ")), err)
143+
}
144+
}
135145
}
136146
}
137147
}

cmd/bashbrew/docker.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ func dockerBuild(tags []string, file string, context io.Reader, platform string)
255255
for _, tag := range tags {
256256
args = append(args, "--tag", tag)
257257
}
258-
args = append(args, "--file", file, "--rm", "--force-rm", "-")
258+
if file != "" {
259+
args = append(args, "--file", file)
260+
}
261+
args = append(args, "--rm", "--force-rm", "-")
259262

260263
cmd := exec.Command("docker", args...)
261264
cmd.Env = append(os.Environ(), "DOCKER_BUILDKIT=0")

0 commit comments

Comments
 (0)