mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat(ko): snapshot builds (#5116)
this makes ko run on snapshot builds, too. the image will be `goreleaser.ko.local:[your tags]`, not sure if we can change this, seems like we can't. also fixed a small doc error around it, as well as added a new test to cover this. closes #4683 --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
e8da87cecb
commit
708cd8904d
@ -138,6 +138,15 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
return ids.Validate()
|
||||
}
|
||||
|
||||
func (p Pipe) Run(ctx *context.Context) error {
|
||||
if ctx.Snapshot {
|
||||
// publish actually handles pushing to the local docker daemon when
|
||||
// snapshot is true.
|
||||
return p.Publish(ctx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Publish executes the Pipe.
|
||||
func (Pipe) Publish(ctx *context.Context) error {
|
||||
g := semerrgroup.New(ctx.Parallelism)
|
||||
@ -249,17 +258,32 @@ func doBuild(ctx *context.Context, ko config.Ko) func() error {
|
||||
return fmt.Errorf("build: %w", err)
|
||||
}
|
||||
|
||||
po := []publish.Option{publish.WithTags(opts.tags), publish.WithNamer(options.MakeNamer(&options.PublishOptions{
|
||||
po := &options.PublishOptions{
|
||||
DockerRepo: opts.imageRepo,
|
||||
Bare: opts.bare,
|
||||
PreserveImportPaths: opts.preserveImportPaths,
|
||||
BaseImportPaths: opts.baseImportPaths,
|
||||
Tags: opts.tags,
|
||||
})), publish.WithAuthFromKeychain(keychain)}
|
||||
|
||||
p, err := publish.NewDefault(opts.imageRepo, po...)
|
||||
Local: ctx.Snapshot,
|
||||
LocalDomain: "goreleaser.ko.local",
|
||||
}
|
||||
var p publish.Interface
|
||||
if ctx.Snapshot {
|
||||
p, err = publish.NewDaemon(
|
||||
options.MakeNamer(po),
|
||||
opts.tags,
|
||||
publish.WithLocalDomain(po.LocalDomain),
|
||||
)
|
||||
} else {
|
||||
p, err = publish.NewDefault(
|
||||
opts.imageRepo,
|
||||
publish.WithTags(opts.tags),
|
||||
publish.WithNamer(options.MakeNamer(po)),
|
||||
publish.WithAuthFromKeychain(keychain),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("newDefault: %w", err)
|
||||
return fmt.Errorf("newPublisher: %w", err)
|
||||
}
|
||||
defer func() { _ = p.Close() }()
|
||||
ref, err := p.Publish(ctx, r, opts.importPath)
|
||||
|
@ -377,6 +377,41 @@ func TestPublishPipeSuccess(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSnapshot(t *testing.T) {
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
ProjectName: "test",
|
||||
Builds: []config.Build{
|
||||
{
|
||||
ID: "foo",
|
||||
BuildDetails: config.BuildDetails{
|
||||
Ldflags: []string{"-s", "-w"},
|
||||
Flags: []string{"-tags", "netgo"},
|
||||
Env: []string{"GOCACHE=" + t.TempDir()},
|
||||
},
|
||||
},
|
||||
},
|
||||
Kos: []config.Ko{
|
||||
{
|
||||
ID: "default",
|
||||
Build: "foo",
|
||||
Repository: "testimage",
|
||||
WorkingDir: "./testdata/app/",
|
||||
Tags: []string{"latest"},
|
||||
},
|
||||
},
|
||||
}, testctx.WithVersion("1.2.0"), testctx.Snapshot)
|
||||
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
|
||||
manifests := ctx.Artifacts.Filter(artifact.ByType(artifact.DockerManifest)).List()
|
||||
require.Len(t, manifests, 1)
|
||||
require.NotEmpty(t, manifests[0].Name)
|
||||
require.Equal(t, manifests[0].Name, manifests[0].Path)
|
||||
require.NotEmpty(t, manifests[0].Extra[artifact.ExtraDigest])
|
||||
require.Equal(t, "default", manifests[0].Extra[artifact.ExtraID])
|
||||
}
|
||||
|
||||
func TestKoValidateMainPathIssue4382(t *testing.T) {
|
||||
// testing the validation of the main path directly to cover many cases
|
||||
require.NoError(t, validateMainPath(""))
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipe/env"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipe/git"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipe/gomod"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipe/ko"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipe/krew"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipe/metadata"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipe/nfpm"
|
||||
@ -146,6 +147,8 @@ var Pipeline = append(
|
||||
reportsizes.Pipe{},
|
||||
// create and push docker images
|
||||
docker.Pipe{},
|
||||
// create and push docker images using ko
|
||||
ko.Pipe{},
|
||||
// publishes artifacts
|
||||
publish.New(),
|
||||
// creates a artifacts.json files in the dist directory
|
||||
|
@ -133,7 +133,7 @@ builds:
|
||||
- linux
|
||||
goarch:
|
||||
- amd64
|
||||
- arch64
|
||||
- arm64
|
||||
|
||||
kos:
|
||||
- repository: ghcr.io/caarlos0/test-ko
|
||||
|
Loading…
x
Reference in New Issue
Block a user