From b2b83856ec9f3ac7a45c85388332d597c6da5fe3 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 9 Dec 2022 17:05:55 -0800 Subject: [PATCH] Fix "re-tagging bug" by abusing `docker build` to multi-tag a single-line synthetic `Dockerfile` --- cmd/bashbrew/cmd-build.go | 10 ++++++++++ cmd/bashbrew/docker.go | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/bashbrew/cmd-build.go b/cmd/bashbrew/cmd-build.go index 6a8a9bc8..5f6d0086 100644 --- a/cmd/bashbrew/cmd-build.go +++ b/cmd/bashbrew/cmd-build.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "github.com/urfave/cli" ) @@ -132,6 +133,15 @@ func cmdBuild(c *cli.Context) error { } } else { fmt.Printf("Using %s (%s)\n", cacheTag, r.EntryIdentifier(entry)) + + if !dryRun { + // https://github.com/docker-library/bashbrew/pull/61/files#r1044926620 + // abusing "docker build" for "tag something a lot of times, but efficiently" 👀 + err := dockerBuild(imageTags, "", strings.NewReader("FROM "+cacheTag), "") + if err != nil { + return cli.NewMultiError(fmt.Errorf(`failed tagging %q: %q`, cacheTag, strings.Join(imageTags, ", ")), err) + } + } } } } diff --git a/cmd/bashbrew/docker.go b/cmd/bashbrew/docker.go index 881a197a..dfb8308e 100644 --- a/cmd/bashbrew/docker.go +++ b/cmd/bashbrew/docker.go @@ -255,7 +255,10 @@ func dockerBuild(tags []string, file string, context io.Reader, platform string) for _, tag := range tags { args = append(args, "--tag", tag) } - args = append(args, "--file", file, "--rm", "--force-rm", "-") + if file != "" { + args = append(args, "--file", file) + } + args = append(args, "--rm", "--force-rm", "-") cmd := exec.Command("docker", args...) cmd.Env = append(os.Environ(), "DOCKER_BUILDKIT=0")