1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-11-27 22:49:07 +02:00

feat: allow templates on docker tags

Allow to template docker tags.

Closes #433
This commit is contained in:
Carlos Alexandro Becker
2017-12-05 11:19:44 -02:00
committed by Carlos Alexandro Becker
parent 6dc31b53bd
commit 14d1347ed9
3 changed files with 105 additions and 37 deletions

View File

@@ -40,50 +40,88 @@ func TestRunPipe(t *testing.T) {
var binPath = filepath.Join(dist, "mybin", "mybin")
_, err = os.Create(binPath)
assert.NoError(t, err)
var table = map[string]struct {
docker config.Docker
err string
}{
"valid": {
docker: config.Docker{
Image: "localhost:5000/goreleaser/test_run_pipe",
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binary: "mybin",
Latest: true,
TagTemplate: "{{.Tag}}",
},
err: "",
},
"invalid": {
docker: config.Docker{
Image: "localhost:5000/goreleaser/test_run_pipe_nope",
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binary: "otherbin",
TagTemplate: "{{.Version}}",
},
err: "",
},
"template_error": {
docker: config.Docker{
Image: "localhost:5000/goreleaser/test_run_pipe_template_error",
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binary: "mybin",
Latest: true,
TagTemplate: "{{.Tag}",
},
err: `template: tag:1: unexpected "}" in operand; missing space?`,
},
}
var images = []string{
"localhost:5000/goreleaser/test_run_pipe:1.0.0",
"localhost:5000/goreleaser/test_run_pipe:v1.0.0",
"localhost:5000/goreleaser/test_run_pipe:latest",
}
// this might fail as the image doesnt exist yet, so lets ignore the error
for _, img := range images {
_ = exec.Command("docker", "rmi", img).Run()
}
var ctx = &context.Context{
Version: "1.0.0",
Publish: true,
Config: config.Project{
ProjectName: "mybin",
Dist: dist,
Dockers: []config.Docker{
{
Image: "localhost:5000/goreleaser/test_run_pipe",
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binary: "mybin",
Latest: true,
for name, docker := range table {
t.Run(name, func(t *testing.T) {
var ctx = &context.Context{
Version: "1.0.0",
Publish: true,
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
{
Image: "localhost:5000/goreleaser/test_run_pipe_nope",
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binary: "otherbin",
Config: config.Project{
ProjectName: "mybin",
Dist: dist,
Dockers: []config.Docker{
docker.docker,
},
},
},
},
}
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
ctx.AddBinary(plat, "mybin", "mybin", binPath)
}
if docker.err != "" {
assert.EqualError(t, Pipe{}.Run(ctx), docker.err)
} else {
assert.NoError(t, Pipe{}.Run(ctx))
}
})
}
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
ctx.AddBinary(plat, "mybin", "mybin", binPath)
}
assert.NoError(t, Pipe{}.Run(ctx))
// this might should not fail as the image should have been created when
// the step ran
for _, img := range images {
assert.NoError(t, exec.Command("docker", "rmi", img).Run())
}
// the test_run_pipe_nope image should not have been created, so deleting
// it should fail
assert.Error(t,
@@ -152,6 +190,7 @@ func TestDefault(t *testing.T) {
assert.Equal(t, "amd64", docker.Goarch)
assert.Equal(t, ctx.Config.Builds[0].Binary, docker.Binary)
assert.Equal(t, "Dockerfile", docker.Dockerfile)
assert.Equal(t, "{{ .Version }}", docker.TagTemplate)
}
func TestDefaultNoDockers(t *testing.T) {
@@ -183,5 +222,6 @@ func TestDefaultSet(t *testing.T) {
assert.Equal(t, "windows", docker.Goos)
assert.Equal(t, "i386", docker.Goarch)
assert.Equal(t, "bar", docker.Binary)
assert.Equal(t, "{{ .Version }}", docker.TagTemplate)
assert.Equal(t, "Dockerfile.foo", docker.Dockerfile)
}