Skip to content

Commit

Permalink
Remove mentions of BASE_IMAGE in Goreleaser config and processing. (a…
Browse files Browse the repository at this point in the history
…rmadaproject#3349)

This is intended to be a more robust fix for Goreleaser issuing `docker
buildx` commands with a faulty `--build-args= ` option.

Revert "Filter out docker build-arg option if no BASE_IMAGE (armadaproject#3259) (armadaproject#3261)"

This reverts commit a468449.

Signed-off-by: Rich Scott <[email protected]>
  • Loading branch information
richscott authored Jan 30, 2024
1 parent c0952a6 commit f572a0c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 28 deletions.
3 changes: 0 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ snapshot:
env:
- GOPROXY={{ if index .Env "GOPROXY" }}{{ .Env.GOPROXY }}{{ else }}https://proxy.golang.org,direct{{ end }}
- GOSUMDB={{ if index .Env "GOSUMDB" }}{{ .Env.GOSUMDB }}{{ else }}sum.golang.org{{ end }}
# If set, BASE_IMAGE determines the base image used for all containers.
- BASE_IMAGE_ARG={{ if index .Env "BASE_IMAGE" }}BASE_IMAGE={{ .Env.BASE_IMAGE }}{{ else }}{{ end }}
- DOCKER_REPO={{ if index .Env "DOCKER_REPO" }}{{ .Env.DOCKER_REPO }}/{{ else }}gresearch/{{ end }}
# Goreleaser always uses the docker buildx builder with name "default"; see
# https://github.com/goreleaser/goreleaser/pull/3199
Expand Down Expand Up @@ -206,7 +204,6 @@ dockers:
- "{{ .Env.DOCKER_REPO }}armada-bundle:latest"
- "{{ .Env.DOCKER_REPO }}armada-bundle:{{ .Version }}"
build_flag_templates: &BUILD_FLAG_TEMPLATES
- --build-arg={{ .Env.BASE_IMAGE_ARG }}
- --builder={{ .Env.DOCKER_BUILDX_BUILDER }}
- --cache-to={{ .Env.DOCKER_BUILDX_CACHE_TO }}
- --cache-from={{ .Env.DOCKER_BUILDX_CACHE_FROM }}
Expand Down
25 changes: 0 additions & 25 deletions magefiles/goreleaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package main
import (
"fmt"
"os"
"regexp"
"time"

"golang.org/x/exp/slices"

goreleaserConfig "github.com/goreleaser/goreleaser/pkg/config"
"github.com/magefile/mage/sh"
"github.com/pkg/errors"
Expand Down Expand Up @@ -54,30 +51,8 @@ func goreleaserWriteMinimalReleaseConfig(dockerIds ...string) error {
dockerIdsToBuild := set(dockerIds)
dockersById := make(map[string]goreleaserConfig.Docker)
buildIds := make(map[string]bool)

// BASE_IMAGE_ARG is derived from BASE_IMAGE - see .goreleaser.yml
buildArgBaseRE := regexp.MustCompile("--build-arg=.*BASE_IMAGE_ARG")

for _, docker := range config.Dockers {
if dockerIdsToBuild[docker.ID] {
// Goreleaser constructs a faulty `docker build` command if the environment
// variable BASE_IMAGE is not defined - it constructs a `--build-arg= ` option
// (no value given) and `docker build` immediately errors. As a work-around
// we filter out that whole template option entry if BASE_IMAGE is not defined;
// see .goreleaser.yml for how it's used. Goreleaser does not support conditional
// templating of YAML in its 'dockers' section, so we filter it out here.
if os.Getenv("BASE_IMAGE") == "" {
deleteIdx := -1
for idx, tpl := range docker.BuildFlagTemplates {
if buildArgBaseRE.MatchString(tpl) {
deleteIdx = idx
break
}
}

docker.BuildFlagTemplates = slices.Delete(docker.BuildFlagTemplates, deleteIdx, deleteIdx+1)
}

dockersById[docker.ID] = docker
for _, id := range docker.IDs {
buildIds[id] = true
Expand Down

0 comments on commit f572a0c

Please sign in to comment.