mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
109 lines
2.8 KiB
Markdown
109 lines
2.8 KiB
Markdown
---
|
|
title: Docker
|
|
series: customization
|
|
hideFromIndex: true
|
|
weight: 140
|
|
---
|
|
|
|
Since [v0.31.0](https://github.com/goreleaser/goreleaser/releases/tag/v0.31.0),
|
|
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.
|
|
|
|
If you have only one `build` setup,
|
|
the configuration is as easy as adding the
|
|
name of your image to your `.goreleaser.yml` file:
|
|
|
|
```yaml
|
|
dockers:
|
|
- image: user/repo
|
|
```
|
|
|
|
You also need to create a `Dockerfile` in your project's root folder:
|
|
|
|
```dockerfile
|
|
FROM scratch
|
|
COPY mybin /
|
|
ENTRYPOINT ["/mybin"]
|
|
```
|
|
|
|
This configuration will build and push a Docker image named `user/repo:tagname`.
|
|
|
|
> **Attention**: Note that were are not building any go files in the docker
|
|
> build phase, we are merely copying the binary to a `scratch` image and
|
|
> setting up the entrypoint.
|
|
|
|
## Customization
|
|
|
|
Of course, you can customize a lot of things:
|
|
|
|
```yaml
|
|
# .goreleaser.yml
|
|
dockers:
|
|
# You can have multiple Docker images.
|
|
-
|
|
# GOOS of the built binary that should be used.
|
|
goos: linux
|
|
# GOARCH of the built binary that should be used.
|
|
goarch: amd64
|
|
# GOARM of the built binary that should be used.
|
|
goarm: ''
|
|
# Name of the built binary that should be used.
|
|
binary: mybinary
|
|
# Docker image name.
|
|
image: myuser/myimage
|
|
# Skips the docker push. Could be useful if you also do draft releases.
|
|
# Defaults to false.
|
|
skip_push: false
|
|
# Path to the Dockerfile (from the project root).
|
|
dockerfile: Dockerfile
|
|
# Template of the docker tag. Defaults to `{{ .Version }}`.
|
|
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.
|
|
extra_files:
|
|
- config.yml
|
|
```
|
|
|
|
> Learn more about the [name template engine](/templates).
|
|
|
|
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.
|
|
|
|
## 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`
|
|
|
|
With these settings you can hopefully push several different docker images
|
|
with multiple tags.
|