1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-27 01:33:39 +02:00

feat: allow to use nfpm packages in the docker pipe (#2003)

* feat: copy nfpms to docker image too

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: wip

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: logs

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fixes

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: improving

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* docs: deprecations and docker improvements

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: revert .goreleaser.yml changes

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fix

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* docs: fix syntax

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* docs: fixed deprecation warnings

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fix

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: coverage

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: add one more test case

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fix

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fix

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2021-01-07 16:21:12 -03:00 committed by GitHub
parent f934314be3
commit e8ea231122
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 206 additions and 201 deletions

View File

@ -39,8 +39,6 @@ dockers:
- 'ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64'
dockerfile: Dockerfile
use_buildx: true
binaries:
- goreleaser
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
@ -56,8 +54,6 @@ dockers:
- 'ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64'
dockerfile: Dockerfile
use_buildx: true
binaries:
- goreleaser
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"

View File

@ -14,4 +14,5 @@ CMD [ "-h" ]
COPY scripts/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY goreleaser /bin/goreleaser
COPY goreleaser_*.apk /tmp/
RUN apk add --allow-untrusted /tmp/goreleaser_*.apk

View File

@ -274,3 +274,12 @@ func (artifacts *Artifacts) Filter(filter Filter) Artifacts {
}
return result
}
// Paths returns the artifact.Path of the current artifact list.
func (artifacts Artifacts) Paths() []string {
var result []string
for _, artifact := range artifacts.List() {
result = append(result, artifact.Path)
}
return result
}

View File

@ -313,3 +313,14 @@ func TestTypeToString(t *testing.T) {
require.Equal(t, "unknown", Type(9999).String())
})
}
func TestPaths(t *testing.T) {
var paths = []string{"a/b", "b/c", "d/e", "f/g"}
var artifacts = New()
for _, a := range paths {
artifacts.Add(&Artifact{
Path: a,
})
}
require.ElementsMatch(t, paths, artifacts.Paths())
}

View File

@ -95,7 +95,6 @@ func TestFillPartial(t *testing.T) {
require.NoError(t, Pipe{}.Run(ctx))
require.Len(t, ctx.Config.Archives[0].Files, 1)
require.Equal(t, `bin.install "testreleaser"`, ctx.Config.Brews[0].Install)
require.NotEmpty(t, ctx.Config.Dockers[0].Binaries)
require.NotEmpty(t, ctx.Config.Dockers[0].Goos)
require.NotEmpty(t, ctx.Config.Dockers[0].Goarch)
require.NotEmpty(t, ctx.Config.Dockers[0].Dockerfile)

View File

@ -11,6 +11,7 @@ import (
"github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/deprecate"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/tmpl"
@ -42,21 +43,19 @@ func (Pipe) Default(ctx *context.Context) error {
if docker.Dockerfile == "" {
docker.Dockerfile = "Dockerfile"
}
if len(docker.Binaries) > 0 {
deprecate.Notice(ctx, "docker.binaries")
}
if len(docker.Builds) > 0 {
deprecate.Notice(ctx, "docker.builds")
docker.IDs = append(docker.IDs, docker.Builds...)
}
for _, f := range docker.Files {
if f == "." || strings.HasPrefix(f, ctx.Config.Dist) {
return fmt.Errorf("invalid docker.files: can't be . or inside dist folder: %s", f)
}
}
}
// only set defaults if there is exactly 1 docker setup in the config file.
if len(ctx.Config.Dockers) != 1 {
return nil
}
if len(ctx.Config.Dockers[0].Binaries) == 0 {
ctx.Config.Dockers[0].Binaries = []string{
ctx.Config.Builds[0].Binary,
}
}
return nil
}
@ -91,51 +90,28 @@ func doRun(ctx *context.Context) error {
for _, docker := range ctx.Config.Dockers {
docker := docker
g.Go(func() error {
log.WithField("docker", docker).Debug("looking for binaries matching")
var binaryNames = make([]string, len(docker.Binaries))
for i := range docker.Binaries {
bin, err := tmpl.New(ctx).Apply(docker.Binaries[i])
if err != nil {
return fmt.Errorf("failed to execute binary template '%s': %w", docker.Binaries[i], err)
}
binaryNames[i] = bin
}
log.WithField("docker", docker).Debug("looking for artifacts matching")
var filters = []artifact.Filter{
artifact.ByGoos(docker.Goos),
artifact.ByGoarch(docker.Goarch),
artifact.ByGoarm(docker.Goarm),
artifact.ByType(artifact.Binary),
func(a *artifact.Artifact) bool {
for _, bin := range binaryNames {
if a.ExtraOr("Binary", "").(string) == bin {
return true
}
}
return false
},
artifact.Or(
artifact.ByType(artifact.Binary),
artifact.ByType(artifact.LinuxPackage),
),
}
if len(docker.Builds) > 0 {
filters = append(filters, artifact.ByIDs(docker.Builds...))
if len(docker.IDs) > 0 {
filters = append(filters, artifact.ByIDs(docker.IDs...))
}
var binaries = ctx.Artifacts.Filter(artifact.And(filters...)).List()
// TODO: not so good of a check, if one binary match multiple
// binaries and the other match none, this will still pass...
log.WithField("binaries", binaries).Debug("found binaries")
if len(binaries) != len(docker.Binaries) {
return fmt.Errorf(
"%d binaries match docker definition: %v: %s_%s_%s, should be %d",
len(binaries),
binaryNames, docker.Goos, docker.Goarch, docker.Goarm,
len(docker.Binaries),
)
}
return process(ctx, docker, binaries)
var artifacts = ctx.Artifacts.Filter(artifact.And(filters...))
log.WithField("artifacts", artifacts.Paths()).Debug("found artifacts")
return process(ctx, docker, artifacts.List())
})
}
return g.Wait()
}
func process(ctx *context.Context, docker config.Docker, bins []*artifact.Artifact) error {
func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.Artifact) error {
tmp, err := ioutil.TempDir(ctx.Config.Dist, "goreleaserdocker")
if err != nil {
return fmt.Errorf("failed to create temporary dir: %w", err)
@ -158,9 +134,9 @@ func process(ctx *context.Context, docker config.Docker, bins []*artifact.Artifa
return fmt.Errorf("failed to link extra file '%s': %w", file, err)
}
}
for _, bin := range bins {
if err := os.Link(bin.Path, filepath.Join(tmp, filepath.Base(bin.Path))); err != nil {
return fmt.Errorf("failed to link binary: %w", err)
for _, art := range artifacts {
if err := os.Link(art.Path, filepath.Join(tmp, filepath.Base(art.Path))); err != nil {
return fmt.Errorf("failed to link artifact: %w", err)
}
}

View File

@ -100,6 +100,7 @@ func TestRunPipe(t *testing.T) {
assertError errChecker
pubAssertError errChecker
manifestAssertError errChecker
extraPrepare func(ctx *context.Context)
}{
"multiarch": {
dockers: []config.Docker{
@ -108,7 +109,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile.arch",
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{"--build-arg", "ARCH=amd64"},
},
{
@ -116,7 +116,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "arm64",
Dockerfile: "testdata/Dockerfile.arch",
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{"--build-arg", "ARCH=arm64v8"},
},
},
@ -149,7 +148,6 @@ func TestRunPipe(t *testing.T) {
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Buildx: true,
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{"--platform=linux/amd64"},
},
{
@ -158,7 +156,6 @@ func TestRunPipe(t *testing.T) {
Goarch: "arm64",
Dockerfile: "testdata/Dockerfile",
Buildx: true,
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{"--platform=linux/arm64"},
},
},
@ -189,7 +186,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "arm64",
Dockerfile: "testdata/Dockerfile.arch",
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{"--build-arg", "ARCH=arm64v8"},
},
},
@ -214,7 +210,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "arm64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
manifests: []config.DockerManifest{
@ -236,7 +231,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "arm64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
manifests: []config.DockerManifest{
@ -254,20 +248,19 @@ func TestRunPipe(t *testing.T) {
"multiarch missing manifest name": {
dockers: []config.Docker{
{
ImageTemplates: []string{registry + "goreleaser/test_multiarch_no_mainifest_name"},
ImageTemplates: []string{registry + "goreleaser/test_multiarch_no_manifest_name"},
Goos: "linux",
Goarch: "arm64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
manifests: []config.DockerManifest{
{
NameTemplate: " ",
ImageTemplates: []string{registry + "goreleaser/test_multiarch_no_mainifest_name"},
ImageTemplates: []string{registry + "goreleaser/test_multiarch_no_manifest_name"},
},
},
expect: []string{registry + "goreleaser/test_multiarch_no_mainifest_name"},
expect: []string{registry + "goreleaser/test_multiarch_no_manifest_name"},
assertError: shouldNotErr,
pubAssertError: shouldNotErr,
manifestAssertError: testlib.AssertSkipped,
@ -276,11 +269,10 @@ func TestRunPipe(t *testing.T) {
"multiarch missing images": {
dockers: []config.Docker{
{
ImageTemplates: []string{registry + "goreleaser/test_multiarch_no_mainifest_images"},
ImageTemplates: []string{registry + "goreleaser/test_multiarch_no_manifest_images"},
Dockerfile: "testdata/Dockerfile",
Goos: "linux",
Goarch: "arm64",
Binaries: []string{"mybin"},
},
},
manifests: []config.DockerManifest{
@ -289,7 +281,7 @@ func TestRunPipe(t *testing.T) {
ImageTemplates: []string{" ", " ", ""},
},
},
expect: []string{registry + "goreleaser/test_multiarch_no_mainifest_images"},
expect: []string{registry + "goreleaser/test_multiarch_no_manifest_images"},
assertError: shouldNotErr,
pubAssertError: shouldNotErr,
manifestAssertError: testlib.AssertSkipped,
@ -316,7 +308,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{
"--label=org.label-schema.schema-version=1.0",
"--label=org.label-schema.version={{.Version}}",
@ -362,7 +353,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
expect: []string{
@ -382,7 +372,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
expect: []string{},
@ -391,7 +380,7 @@ func TestRunPipe(t *testing.T) {
pubAssertError: shouldNotErr,
manifestAssertError: shouldNotErr,
},
"valid-with-builds": {
"valid with ids": {
dockers: []config.Docker{
{
ImageTemplates: []string{
@ -400,8 +389,7 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
Builds: []string{"mybin"},
IDs: []string{"mybin"},
},
},
expect: []string{
@ -421,7 +409,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
Files: []string{"testdata/extra_file.txt"},
},
{
@ -431,7 +418,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
Files: []string{"testdata/extra_file.txt"},
},
},
@ -453,7 +439,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
{
ImageTemplates: []string{
@ -462,7 +447,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
assertImageLabels: noLabels,
@ -483,7 +467,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
SkipPush: "true",
},
},
@ -502,7 +485,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile.true",
Binaries: []string{"mybin"},
SkipPush: "true",
},
{
@ -512,7 +494,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile.false",
Binaries: []string{"mybin"},
SkipPush: "true",
},
},
@ -531,7 +512,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
expect: []string{
@ -551,7 +531,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{
"--label=foo=bar",
},
@ -574,7 +553,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{
"--bad-flag",
},
@ -592,7 +570,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile.bad",
Binaries: []string{"mybin"},
},
},
assertImageLabels: noLabels,
@ -607,7 +584,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
assertImageLabels: noLabels,
@ -622,7 +598,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{
"--label=tag={{.Tag}",
},
@ -640,7 +615,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
},
},
assertImageLabels: noLabels,
@ -655,7 +629,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
BuildFlagTemplates: []string{
"--label=nope={{.Env.NOPE}}",
},
@ -674,7 +647,6 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"mybin"},
SkipPush: "true",
},
},
@ -694,7 +666,6 @@ func TestRunPipe(t *testing.T) {
ImageTemplates: []string{"docker.io/nope:latest"},
Goos: "linux",
Goarch: "amd64",
Binaries: []string{"mybin"},
Dockerfile: "testdata/Dockerfile",
},
},
@ -712,7 +683,6 @@ func TestRunPipe(t *testing.T) {
ImageTemplates: []string{"whatever:latest"},
Goos: "linux",
Goarch: "amd64",
Binaries: []string{"mybin"},
Dockerfile: "testdata/Dockerfilezzz",
},
},
@ -725,7 +695,6 @@ func TestRunPipe(t *testing.T) {
ImageTemplates: []string{"whatever:latest"},
Goos: "linux",
Goarch: "amd64",
Binaries: []string{"mybin"},
Dockerfile: "testdata/Dockerfile",
Files: []string{
"testdata/nope.txt",
@ -735,26 +704,38 @@ func TestRunPipe(t *testing.T) {
assertImageLabels: noLabels,
assertError: shouldErr(`failed to link extra file 'testdata/nope.txt'`),
},
"no_matching_binaries": {
"binary doesnt exist": {
dockers: []config.Docker{
{
ImageTemplates: []string{"whatever:latest"},
Goos: "darwin",
Goos: "linux",
Goarch: "amd64",
Binaries: []string{"mybinnnn"},
Dockerfile: "testdata/Dockerfile",
IDs: []string{"nope"},
},
},
assertImageLabels: noLabels,
assertError: shouldErr(`0 binaries match docker definition: [mybinnnn]: darwin_amd64_, should be 1`),
assertError: shouldErr(`/wont-exist: no such file or directory`),
extraPrepare: func(ctx *context.Context) {
ctx.Artifacts.Add(&artifact.Artifact{
Name: "wont-exist",
Path: "wont-exist",
Goarch: "amd64",
Goos: "linux",
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "nope",
},
})
},
},
"multiple_binaries": {
"multiple_ids": {
dockers: []config.Docker{
{
ImageTemplates: []string{registry + "goreleaser/multiple:latest"},
Goos: "darwin",
Goarch: "amd64",
Binaries: []string{"mybin", "anotherbin"},
IDs: []string{"mybin", "anotherbin"},
Dockerfile: "testdata/Dockerfile.multiple",
},
},
@ -766,18 +747,14 @@ func TestRunPipe(t *testing.T) {
registry + "goreleaser/multiple:latest",
},
},
// TODO: add a test case for multiple matching binaries for the same name
"templated_binaries": {
env: map[string]string{
"BIN_NAME": "mybin",
},
"nfpm and multiple binaries": {
dockers: []config.Docker{
{
ImageTemplates: []string{registry + "goreleaser/templatedbins:latest"},
Goos: "darwin",
ImageTemplates: []string{registry + "goreleaser/nfpm:latest"},
Goos: "linux",
Goarch: "amd64",
Binaries: []string{"{{.Env.BIN_NAME}}"},
Dockerfile: "testdata/Dockerfile",
IDs: []string{"mybin", "anotherbin"},
Dockerfile: "testdata/Dockerfile.nfpm",
},
},
assertImageLabels: noLabels,
@ -785,23 +762,26 @@ func TestRunPipe(t *testing.T) {
pubAssertError: shouldNotErr,
manifestAssertError: shouldNotErr,
expect: []string{
registry + "goreleaser/templatedbins:latest",
registry + "goreleaser/nfpm:latest",
},
},
"binaries_template_error": {
"nfpm and multiple binaries on arm64": {
dockers: []config.Docker{
{
ImageTemplates: []string{
registry + "goreleaser/binaries_template_error:latest",
},
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binaries: []string{"{{.Env.BAR}"},
ImageTemplates: []string{registry + "goreleaser/nfpm_arm:latest"},
Goos: "linux",
Goarch: "arm64",
IDs: []string{"mybin", "anotherbin"},
Dockerfile: "testdata/Dockerfile.nfpm",
},
},
assertImageLabels: noLabels,
assertError: shouldErr(`template: tmpl:1: unexpected "}" in operand`),
assertImageLabels: noLabels,
assertError: shouldNotErr,
pubAssertError: shouldNotErr,
manifestAssertError: shouldNotErr,
expect: []string{
registry + "goreleaser/nfpm_arm:latest",
},
},
}
@ -819,6 +799,12 @@ func TestRunPipe(t *testing.T) {
require.NoError(t, err)
_, err = os.Create(filepath.Join(dist, "mybin", "anotherbin"))
require.NoError(t, err)
_, err = os.Create(filepath.Join(dist, "mynfpm.apk"))
require.NoError(t, err)
for _, arch := range []string{"amd64", "386", "arm64"} {
_, err = os.Create(filepath.Join(dist, fmt.Sprintf("mybin_%s.apk", arch)))
require.NoError(t, err)
}
var ctx = context.New(config.Project{
ProjectName: "mybin",
@ -848,13 +834,29 @@ func TestRunPipe(t *testing.T) {
Goos: os,
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": bin,
"ID": bin,
"ID": bin,
},
})
}
}
}
for _, arch := range []string{"amd64", "386", "arm64"} {
var name = fmt.Sprintf("mybin_%s.apk", arch)
ctx.Artifacts.Add(&artifact.Artifact{
Name: name,
Path: filepath.Join(dist, name),
Goarch: arch,
Goos: "linux",
Type: artifact.LinuxPackage,
Extra: map[string]interface{}{
"ID": "mybin",
},
})
}
if docker.extraPrepare != nil {
docker.extraPrepare(ctx)
}
// this might fail as the image doesnt exist yet, so lets ignore the error
for _, img := range docker.expect {
@ -960,13 +962,12 @@ func TestDockerNotInPath(t *testing.T) {
func TestDefault(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{
Builds: []config.Build{
{
Binary: "foo",
},
},
Dockers: []config.Docker{
{},
{
IDs: []string{"aa"},
Builds: []string{"foo"},
Binaries: []string{"aaa"},
},
},
},
}
@ -975,8 +976,7 @@ func TestDefault(t *testing.T) {
var docker = ctx.Config.Dockers[0]
require.Equal(t, "linux", docker.Goos)
require.Equal(t, "amd64", docker.Goarch)
require.Equal(t, []string{ctx.Config.Builds[0].Binary}, docker.Binaries)
require.Empty(t, docker.Builds)
require.Equal(t, []string{"aa", "foo"}, docker.IDs)
}
func TestDefaultDockerfile(t *testing.T) {
@ -997,29 +997,6 @@ func TestDefaultDockerfile(t *testing.T) {
require.Equal(t, "Dockerfile", ctx.Config.Dockers[1].Dockerfile)
}
func TestDefaultBinaries(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{
Builds: []config.Build{
{
ID: "foo",
},
},
Dockers: []config.Docker{
{
Binaries: []string{"foo"},
},
},
},
}
require.NoError(t, Pipe{}.Default(ctx))
require.Len(t, ctx.Config.Dockers, 1)
var docker = ctx.Config.Dockers[0]
require.Equal(t, "linux", docker.Goos)
require.Equal(t, "amd64", docker.Goarch)
require.Equal(t, []string{"foo"}, docker.Binaries)
}
func TestDefaultNoDockers(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{
@ -1063,10 +1040,9 @@ func TestDefaultSet(t *testing.T) {
Config: config.Project{
Dockers: []config.Docker{
{
Builds: []string{"foo"},
IDs: []string{"foo"},
Goos: "windows",
Goarch: "i386",
Binaries: []string{"bar"},
Dockerfile: "Dockerfile.foo",
},
},
@ -1077,8 +1053,7 @@ func TestDefaultSet(t *testing.T) {
var docker = ctx.Config.Dockers[0]
require.Equal(t, "windows", docker.Goos)
require.Equal(t, "i386", docker.Goarch)
require.Equal(t, "bar", docker.Binaries[0])
require.Equal(t, "foo", docker.Builds[0])
require.Equal(t, []string{"foo"}, docker.IDs)
require.Equal(t, "Dockerfile.foo", docker.Dockerfile)
}
@ -1092,7 +1067,6 @@ func Test_processImageTemplates(t *testing.T) {
},
Dockers: []config.Docker{
{
Binaries: []string{"foo"},
Dockerfile: "Dockerfile.foo",
ImageTemplates: []string{
"user/image:{{.Tag}}",

View File

@ -0,0 +1,4 @@
FROM alpine
ADD mybin_*.apk /
ADD mybin /
ADD anotherbin /

View File

@ -482,8 +482,9 @@ type Checksum struct {
// Docker image config.
type Docker struct {
Binaries []string `yaml:",omitempty"`
Builds []string `yaml:",omitempty"`
Binaries []string `yaml:",omitempty"` // deprecated: no need to use this anymore
Builds []string `yaml:",omitempty"` // deprecated: use IDs instead
IDs []string `yaml:"ids,omitempty"`
Goos string `yaml:",omitempty"`
Goarch string `yaml:",omitempty"`
Goarm string `yaml:",omitempty"`

View File

@ -8,26 +8,28 @@ GoReleaser supports building and pushing Docker images.
## How it works
You can declare multiple Docker images. They will be matched against
the binaries generated by your `builds` section.
the binaries generated by your `builds` section and packages generated
by your `nfpms` section.
If you have only one `build` setup,
the configuration is as easy as adding the
name of your image to your `.goreleaser.yml` file:
The docker image declaration supports templating. Learn more about the [name template engine](/customization/templates/).
```yaml
dockers:
- image_templates:
- user/repo
```
!!! tip
The `image_templates` attribute supports templating. Learn more about the [name template engine](/customization/templates/).
You also need to create a `Dockerfile` in your project's root folder:
```dockerfile
FROM scratch
COPY mybin /
ENTRYPOINT ["/mybin"]
COPY mybin /
```
This configuration will build and push a Docker image named `user/repo:tagname`.
@ -46,22 +48,19 @@ Of course, you can customize a lot of things:
dockers:
# You can have multiple Docker images.
-
# GOOS of the built binary that should be used.
# GOOS of the built binaries/packages that should be used.
goos: linux
# GOARCH of the built binary that should be used.
# GOARCH of the built binaries/packages that should be used.
goarch: amd64
# GOARM of the built binary that should be used.
# GOARM of the built binaries/packages that should be used.
goarm: ''
# Name templates of the built binaries that should be used.
binaries:
- mybinary
# Build IDs to gather the binaries from.
builds:
# IDs to filter the binaries/packages.
ids:
- mybuild
- mynfpm
# Templates of the Docker image names.
image_templates:
@ -80,7 +79,7 @@ dockers:
# Path to the Dockerfile (from the project root).
dockerfile: Dockerfile
# Wether to use `docker buildx build` instead of `docker build`.
# Whether to use `docker buildx build` instead of `docker build`.
# You probably want to set it to true when using flags like `--platform`.
# If true, will also add `--load` to the build flags.
# Defaults to false.
@ -96,13 +95,13 @@ dockers:
- "--build-arg=FOO={{.Env.Bar}}"
- "--platform=linux/arm64"
# If your Dockerfile copies files other than the binary itself,
# If your Dockerfile copies files other than binaries and packages,
# you should list them here as well.
# Note that goreleaser will create the same structure inside the temporary
# Note that GoReleaser will create the same structure inside a temporary
# folder, so if you add `foo/bar.json` here, on your Dockerfile you can
# `COPY foo/bar.json /whatever.json`.
# Also note that the paths here are relative to the folder in which
# goreleaser is being run.
# GoReleaser is being run (usually the repository root folder).
# This field does not support wildcards, you can add an entire folder here
# and use wildcards when you `COPY`/`ADD` in your Dockerfile.
extra_files:
@ -117,7 +116,8 @@ dockers:
These settings should allow you to generate multiple Docker images,
for example, using multiple `FROM` statements,
as well as generate one image for each binary in your project.
as well as generate one image for each binary in your project or one image with multiple binaries, as well as
install the generated packages instead of copying the binary and configs manually.
## Generic Image Names
@ -129,8 +129,6 @@ That can be accomplished simply by adding template language in the definition:
project: foo
dockers:
-
binaries:
- mybinary
image_templates:
- "myuser/{{.ProjectName}}"
```
@ -152,8 +150,6 @@ accomplished by using multiple `image_templates`:
# .goreleaser.yml
dockers:
-
binaries:
- mybinary
image_templates:
- "myuser/myimage:{{ .Tag }}"
- "myuser/myimage:v{{ .Major }}"
@ -168,7 +164,7 @@ This will build and publish the following images:
- `myuser/myimage:v1.6`
- `myuser/myimage:latest`
With these settings you can hopefully push several different docker images
With these settings you can hopefully push several Docker images
with multiple tags.
!!! tip
@ -183,8 +179,6 @@ accomplished by using multiple `image_templates`:
# .goreleaser.yml
dockers:
-
binaries:
- mybinary
image_templates:
- "docker.io/myuser/myimage:{{ .Tag }}"
- "docker.io/myuser/myimage:latest"
@ -196,6 +190,8 @@ This will build and publish the following images to `docker.io` and `gcr.io`:
- `myuser/myimage:v1.6.4`
- `myuser/myimage:latest`
- `gcr.io/myuser/myimage:v1.6.4`
- `gcr.io/myuser/myimage:latest`
## Applying docker build flags
@ -206,8 +202,6 @@ valid docker build flags.
# .goreleaser.yml
dockers:
-
binaries:
- mybinary
image_templates:
- "myuser/myimage"
build_flag_templates:

View File

@ -72,8 +72,8 @@ images (and possibly others):
```dockerfile
# Dockerfile
FROM alpine
COPY mybin /usr/bin/mybin
ENTRYPOINT ["/usr/bin/mybin"]
COPY mybin /usr/bin/mybin
```
Then, on our GoReleaser config file, we need to define both the `dockers` and
@ -94,16 +94,12 @@ dockers:
- image_templates:
- "foo/bar:{{ .Version }}-amd64"
use_buildx: true
binaries:
- mybin
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- image_templates:
- "foo/bar:{{ .Version }}-arm64v8"
use_buildx: true
binaries:
- mybin
goarch: arm64
dockerfile: Dockerfile
build_flag_templates:

View File

@ -15,6 +15,51 @@ goreleaser check
## Active deprecation notices
### docker.builds
> since 2021-01-07 (v0.154.0)
`builds` is deprecated in favor of `ids`, since now it also allows to copy nfpm packages:
Change this:
=== "Before"
```yaml
dockers:
-
builds: ['a', 'b']
```
=== "After"
```yaml
dockers:
-
ids: ['a', 'b']
```
### docker.binaries
> since 2021-01-07 (v0.154.0)
`binaries` is deprecated and now does nothing.
If you want to filter something out, use the `ids` property.
Change this:
=== "Before"
```yaml
dockers:
-
binaries: ['foo']
```
=== "After"
```yaml
dockers:
-
ids: ['foo']
```
### nfpms.files
> since 2020-12-21 (v0.149.0)
@ -92,7 +137,6 @@ Change this:
type: symlink
```
### nfpms.rpm.ghost_files
> since 2020-12-21 (v0.149.0)
@ -158,19 +202,19 @@ Change this:
Change this:
=== "Before"
```yaml
nfpms:
-
deb:
version_metadata: beta1
```
```yaml
nfpms:
-
deb:
version_metadata: beta1
```
=== "After"
```yaml
-
version_metadata: beta1
```
```yaml
nfpms:
-
version_metadata: beta1
```
<!--