1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

fix: honouring ko bare option (#3743)

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 <batuhan.apaydin@trendyol.com>
This commit is contained in:
Kamesh Sampath 2023-02-02 04:16:38 +05:30 committed by GitHub
parent 599f9b4c6a
commit f22987a026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 33 deletions

View File

@ -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)

View File

@ -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])
}

View File

@ -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"`