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

Merge pull request #515 from goreleaser/docker-major-minor-etc

Docker major minor etc
This commit is contained in:
Carlos Alexandro Becker 2018-01-19 08:33:20 -02:00 committed by GitHub
commit fcbdaf32c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 4 deletions

View File

@ -25,6 +25,7 @@ dockers:
- image: goreleaser/goreleaser
tag_templates:
- '{{ .Tag }}'
- 'v{{ .Major }}.{{ .Minor }}'
- 'latest'
archive:
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'

8
Gopkg.lock generated
View File

@ -56,6 +56,12 @@
revision = "caa5f3f5742eb0535631e94fa5e171c74c0144b7"
version = "v1.0.0"
[[projects]]
name = "github.com/masterminds/semver"
packages = ["."]
revision = "15d8430ab86497c5c0da827b748823945e1cf1e1"
version = "v1.4.0"
[[projects]]
name = "github.com/mattn/go-colorable"
packages = ["."]
@ -154,6 +160,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "bce4694edbb58fe9615c3e2eff7fe9e2f041a6fac7be441ee28988416413cdc0"
inputs-digest = "29cc5012bc98dd429a87d7a638a221b2d0f5b12eaf5bea67576ffd362d88105b"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -51,10 +51,12 @@ dockers:
# Path to the Dockerfile (from the project root).
dockerfile: Dockerfile
# Template of the docker tag. Defaults to `{{ .Version }}`. Other allowed
# fields are `.Tag` and `.Env.VARIABLE_NAME`.
# fields are `.Tag`, `.Major`, `.Minor` and `.Patch` and
# `.Env.VARIABLE_NAME`.
tag_templates:
- "{{ .Tag }}"
- "{{ .Tag }}-{{ .Env.GO_VERSION }}"
- "v{{ .Major }}"
- latest
# If your Dockerfile copies files other than the binary itself,
# you should list them here as well.
@ -82,3 +84,36 @@ Then you can run:
```console
GOVERSION_NR=$(go version | awk '{print $3}') goreleaser
```
## Keeping docker images updated for current major
Some users might want to when version to push docker tags `:v1`, `:v1.6`,
`:v1.6.4` and `:latest` when `v1.6.4` (for example) is built. That can be
accomplished by using multiple `tag_templates`:
```yaml
# .goreleaser.yml
dockers:
-
binary: mybinary
image: myuser/myimage
tag_templates:
- "{{ .Tag }}"
- "v{{ .Major }}"
- "v{{ .Major }}.{{ .Minor }}"
- latest
```
This will build and publish the following images:
* myuser/myimage:v1.6.4
* myuser/myimage:v1
* myuser/myimage:v1.6
* myuser/myimage:latest
Hope this feature serves you well!
More info:
* [#461](https://github.com/goreleaser/goreleaser/issues/461)
* [#505](https://github.com/goreleaser/goreleaser/issues/505)

View File

@ -13,6 +13,7 @@ import (
"github.com/apex/log"
"github.com/apex/log/handlers/cli"
"github.com/fatih/color"
"github.com/masterminds/semver"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
@ -129,13 +130,21 @@ func tagName(ctx *context.Context, tagTemplate string) (string, error) {
if err != nil {
return "", err
}
sv, err := semver.NewVersion(ctx.Git.CurrentTag)
if err != nil {
return "", err
}
data := struct {
Version, Tag string
Env map[string]string
Version, Tag string
Major, Minor, Patch int64
Env map[string]string
}{
Version: ctx.Version,
Tag: ctx.Git.CurrentTag,
Env: ctx.Env,
Major: sv.Major(),
Minor: sv.Minor(),
Patch: sv.Patch(),
}
err = t.Execute(&out, data)
return out.String(), err

View File

@ -65,6 +65,8 @@ func TestRunPipe(t *testing.T) {
Binary: "mybin",
TagTemplates: []string{
"{{.Tag}}-{{.Env.FOO}}",
"v{{.Major}}",
"v{{.Major}}.{{.Minor}}",
"latest",
},
Files: []string{
@ -73,6 +75,8 @@ func TestRunPipe(t *testing.T) {
},
expect: []string{
registry + "goreleaser/test_run_pipe:v1.0.0-123",
registry + "goreleaser/test_run_pipe:v1",
registry + "goreleaser/test_run_pipe:v1.0",
registry + "goreleaser/test_run_pipe:latest",
},
err: "",