From f22987a026228109c5f12bf50976c0b2c15cafe3 Mon Sep 17 00:00:00 2001 From: Kamesh Sampath Date: Thu, 2 Feb 2023 04:16:38 +0530 Subject: [PATCH] fix: honouring ko bare option (#3743) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The commit will add the `bare` option to ko publisher options when set/passed via config `.goreleaser.yaml`. Currently, even the `bare: true` is set via config, the option was never passed to `ko` PublisherOptions. #3742 --------- Co-authored-by: Batuhan Apaydın --- internal/pipe/ko/ko.go | 28 ++++++++-------------------- internal/pipe/ko/ko_test.go | 23 +++++++++++------------ pkg/config/config.go | 1 - 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/internal/pipe/ko/ko.go b/internal/pipe/ko/ko.go index 9488348b6..8b7670b94 100644 --- a/internal/pipe/ko/ko.go +++ b/internal/pipe/ko/ko.go @@ -109,7 +109,6 @@ func (Pipe) Default(ctx *context.Context) error { if repo := ctx.Env["KO_DOCKER_REPO"]; repo != "" { ko.Repository = repo - ko.RepositoryFromEnv = true } if ko.Repository == "" { @@ -136,7 +135,6 @@ type buildOptions struct { flags []string env []string imageRepo string - fromEnv bool workingDir string platforms []string baseImage string @@ -225,24 +223,15 @@ func doBuild(ctx *context.Context, ko config.Ko) func() error { return fmt.Errorf("build: %w", err) } - po := []publish.Option{publish.WithTags(opts.tags), publish.WithAuthFromKeychain(keychain)} + po := []publish.Option{publish.WithTags(opts.tags), publish.WithNamer(options.MakeNamer(&options.PublishOptions{ + DockerRepo: opts.imageRepo, + Bare: opts.bare, + PreserveImportPaths: opts.preserveImportPaths, + BaseImportPaths: opts.baseImportPaths, + Tags: opts.tags, + })), publish.WithAuthFromKeychain(keychain)} - var repo string - if opts.fromEnv { - repo = opts.imageRepo - } else { - // image resource's `repo` takes precedence if set, and selects the - // `--bare` namer so the image is named exactly `repo`. - repo = opts.imageRepo - po = append(po, publish.WithNamer(options.MakeNamer(&options.PublishOptions{ - DockerRepo: opts.imageRepo, - Bare: opts.bare, - PreserveImportPaths: opts.preserveImportPaths, - BaseImportPaths: opts.baseImportPaths, - }))) - } - - p, err := publish.NewDefault(repo, po...) + p, err := publish.NewDefault(opts.imageRepo, po...) if err != nil { return fmt.Errorf("newDefault: %w", err) } @@ -302,7 +291,6 @@ func buildBuildOptions(ctx *context.Context, cfg config.Ko) (*buildOptions, erro platforms: cfg.Platforms, sbom: cfg.SBOM, imageRepo: cfg.Repository, - fromEnv: cfg.RepositoryFromEnv, } tags, err := applyTemplate(ctx, cfg.Tags) diff --git a/internal/pipe/ko/ko_test.go b/internal/pipe/ko/ko_test.go index 3bef16f5d..c39825926 100644 --- a/internal/pipe/ko/ko_test.go +++ b/internal/pipe/ko/ko_test.go @@ -44,18 +44,17 @@ func TestDefault(t *testing.T) { }) require.NoError(t, Pipe{}.Default(ctx)) require.Equal(t, config.Ko{ - ID: "test", - Build: "test", - BaseImage: chainguardStatic, - Repository: registry, - RepositoryFromEnv: true, - Platforms: []string{"linux/amd64"}, - SBOM: "spdx", - Tags: []string{"latest"}, - WorkingDir: ".", - Ldflags: []string{"{{.Env.LDFLAGS}}"}, - Flags: []string{"{{.Env.FLAGS}}"}, - Env: []string{"SOME_ENV={{.Env.LE_ENV}}"}, + ID: "test", + Build: "test", + BaseImage: chainguardStatic, + Repository: registry, + Platforms: []string{"linux/amd64"}, + SBOM: "spdx", + Tags: []string{"latest"}, + WorkingDir: ".", + Ldflags: []string{"{{.Env.LDFLAGS}}"}, + Flags: []string{"{{.Env.FLAGS}}"}, + Env: []string{"SOME_ENV={{.Env.LE_ENV}}"}, }, ctx.Config.Kos[0]) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 13b2ff04b..aabbeb6fb 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -207,7 +207,6 @@ type Ko struct { WorkingDir string `yaml:"working_dir,omitempty" json:"working_dir,omitempty"` BaseImage string `yaml:"base_image,omitempty" json:"base_image,omitempty"` Repository string `yaml:"repository,omitempty" json:"repository,omitempty"` - RepositoryFromEnv bool `yaml:"-" json:"-"` Platforms []string `yaml:"platforms,omitempty" json:"platforms,omitempty"` Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"` SBOM string `yaml:"sbom,omitempty" json:"sbom,omitempty"`