1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-11 14:39:28 +02:00

feat: allow to template dockerfile (#2797)

* feat: allow to template dockerfile

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

* test: added one more test

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2022-01-06 15:34:55 -03:00 committed by GitHub
parent 493be086a0
commit 8e1b6a1bbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 2 deletions

View File

@ -143,7 +143,11 @@ func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.A
log.Debug("tempdir: " + tmp)
if docker.Use != useBuildPacks {
if err := gio.Copy(docker.Dockerfile, filepath.Join(tmp, "Dockerfile")); err != nil {
dockerfile, err := tmpl.New(ctx).Apply(docker.Dockerfile)
if err != nil {
return err
}
if err := gio.Copy(dockerfile, filepath.Join(tmp, "Dockerfile")); err != nil {
return fmt.Errorf("failed to copy dockerfile: %w", err)
}
}

View File

@ -439,6 +439,48 @@ func TestRunPipe(t *testing.T) {
pubAssertError: shouldNotErr,
manifestAssertError: shouldNotErr,
},
"templated-dockerfile": {
env: map[string]string{
"Dockerfile": "testdata/Dockerfile",
},
dockers: []config.Docker{
{
ImageTemplates: []string{
registry + "goreleaser/templated_dockerfile:v1",
},
Goos: "linux",
Goarch: "amd64",
Dockerfile: "{{ .Env.Dockerfile }}",
Files: []string{
"testdata/extra_file.txt",
},
},
},
expect: []string{
registry + "goreleaser/templated_dockerfile:v1",
},
assertError: shouldNotErr,
assertImageLabels: noLabels,
pubAssertError: shouldNotErr,
manifestAssertError: shouldNotErr,
},
"templated-dockerfile-invalid": {
dockers: []config.Docker{
{
ImageTemplates: []string{
registry + "goreleaser/invalid-templated-dockerfile:v1",
},
Goos: "linux",
Goarch: "amd64",
Dockerfile: "{{ .Env.Dockerfile }}",
},
},
expect: []string{},
assertError: shouldErr(`template: tmpl:1:7: executing "tmpl" at <.Env.Dockerfile>: map has no entry for key "Dockerfile"`),
assertImageLabels: noLabels,
pubAssertError: shouldNotErr,
manifestAssertError: shouldNotErr,
},
"image template with env": {
env: map[string]string{
"FOO": "test_run_pipe_template",

View File

@ -81,7 +81,9 @@ dockers:
skip_push: false
# Path to the Dockerfile (from the project root).
dockerfile: Dockerfile
#
# Defaults to `Dockerfile`.
dockerfile: '{{ .Env.DOCKERFILE }}'
# Set the "backend" for the Docker pipe.
# Valid options are: docker, buildx, podman, buildpacks