2017-09-13 03:16:23 +02:00
|
|
|
---
|
2017-10-01 18:57:52 +02:00
|
|
|
title: Docker
|
2018-04-25 07:20:12 +02:00
|
|
|
series: customization
|
|
|
|
hideFromIndex: true
|
|
|
|
weight: 140
|
2017-09-13 03:16:23 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
Since [v0.31.0](https://github.com/goreleaser/goreleaser/releases/tag/v0.31.0),
|
2017-10-01 18:57:52 +02:00
|
|
|
GoReleaser supports building and pushing Docker images.
|
2017-09-13 03:16:23 +02:00
|
|
|
|
|
|
|
## How it works
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
You can declare multiple Docker images. They will be matched against
|
2017-09-13 03:16:23 +02:00
|
|
|
the binaries generated by your `builds` section.
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
If you have only one `build` setup,
|
|
|
|
the configuration is as easy as adding the
|
|
|
|
name of your image to your `.goreleaser.yml` file:
|
2017-09-13 03:16:23 +02:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
dockers:
|
|
|
|
- image: user/repo
|
|
|
|
```
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
You also need to create a `Dockerfile` in your project's root folder:
|
2017-09-13 03:16:23 +02:00
|
|
|
|
|
|
|
```dockerfile
|
|
|
|
FROM scratch
|
|
|
|
COPY mybin /
|
|
|
|
ENTRYPOINT ["/mybin"]
|
|
|
|
```
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
This configuration will build and push a Docker image named `user/repo:tagname`.
|
2017-09-13 03:16:23 +02:00
|
|
|
|
|
|
|
## Customization
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
Of course, you can customize a lot of things:
|
2017-09-13 03:16:23 +02:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
# .goreleaser.yml
|
|
|
|
dockers:
|
2017-10-01 18:57:52 +02:00
|
|
|
# You can have multiple Docker images.
|
2017-09-13 03:16:23 +02:00
|
|
|
-
|
2017-10-01 18:57:52 +02:00
|
|
|
# GOOS of the built binary that should be used.
|
2017-09-13 03:16:23 +02:00
|
|
|
goos: linux
|
2017-10-01 18:57:52 +02:00
|
|
|
# GOARCH of the built binary that should be used.
|
2017-09-13 03:16:23 +02:00
|
|
|
goarch: amd64
|
2017-10-01 18:57:52 +02:00
|
|
|
# GOARM of the built binary that should be used.
|
2017-09-13 03:16:23 +02:00
|
|
|
goarm: ''
|
2017-10-01 18:57:52 +02:00
|
|
|
# Name of the built binary that should be used.
|
2017-09-13 03:16:23 +02:00
|
|
|
binary: mybinary
|
2017-10-01 18:57:52 +02:00
|
|
|
# Docker image name.
|
2017-09-13 03:16:23 +02:00
|
|
|
image: myuser/myimage
|
2018-03-24 23:42:21 +02:00
|
|
|
# Skips the docker push. Could be useful if you also do draft releases.
|
|
|
|
# Defaults to false.
|
|
|
|
skip_push: false
|
2017-10-01 18:57:52 +02:00
|
|
|
# Path to the Dockerfile (from the project root).
|
2017-09-13 03:16:23 +02:00
|
|
|
dockerfile: Dockerfile
|
2018-05-01 05:32:48 +02:00
|
|
|
# Template of the docker tag. Defaults to `{{ .Version }}`.
|
|
|
|
# Other allowed fields are:
|
|
|
|
# - `.Commint`
|
|
|
|
# - `.Tag`
|
|
|
|
# - `.Major`
|
|
|
|
# - `.Minor`
|
|
|
|
# - `.Patch`
|
|
|
|
# - `.Env.VARIABLE_NAME`
|
2018-01-18 21:41:56 +02:00
|
|
|
tag_templates:
|
|
|
|
- "{{ .Tag }}"
|
|
|
|
- "{{ .Tag }}-{{ .Env.GO_VERSION }}"
|
2018-01-19 04:05:09 +02:00
|
|
|
- "v{{ .Major }}"
|
2018-01-18 21:41:56 +02:00
|
|
|
- latest
|
2017-10-01 18:57:52 +02:00
|
|
|
# If your Dockerfile copies files other than the binary itself,
|
2017-09-26 00:10:04 +02:00
|
|
|
# you should list them here as well.
|
|
|
|
extra_files:
|
|
|
|
- config.yml
|
2017-09-13 03:16:23 +02:00
|
|
|
```
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
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.
|
2017-12-06 01:13:16 +02:00
|
|
|
|
|
|
|
## Passing environment variables to tag_template
|
|
|
|
|
|
|
|
You can do that by using `{{ .Env.VARIABLE_NAME }}` in the template, for
|
|
|
|
example:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
dockers:
|
|
|
|
-
|
|
|
|
tag_template: "{{ .Tag }}-{{ .Env.GOVERSION_NR }}"
|
|
|
|
```
|
|
|
|
|
|
|
|
Then you can run:
|
|
|
|
|
|
|
|
```console
|
|
|
|
GOVERSION_NR=$(go version | awk '{print $3}') goreleaser
|
|
|
|
```
|
2018-01-19 04:05:09 +02:00
|
|
|
|
|
|
|
## 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
|
|
|
|
|
2018-02-19 01:37:59 +02:00
|
|
|
With these settings you can hopefully push several different docker images
|
|
|
|
with multiple tags.
|