Skip to content

Commit

Permalink
Fix "re-tagging bug" by abusing docker build to multi-tag a single-…
Browse files Browse the repository at this point in the history
…line synthetic `Dockerfile`
  • Loading branch information
tianon committed Dec 12, 2022
1 parent 87b6419 commit b2b8385
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cmd/bashbrew/cmd-build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strings"

"github.com/urfave/cli"
)
Expand Down Expand Up @@ -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)
}
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/bashbrew/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b2b8385

Please sign in to comment.