2023-01-16 22:34:49 -03:00
|
|
|
# Docker Images with Ko
|
|
|
|
|
2023-04-02 17:16:21 -03:00
|
|
|
> Since v1.15
|
2023-01-16 22:34:49 -03:00
|
|
|
|
|
|
|
You can also use [ko][] to build and publish Docker container images.
|
|
|
|
|
|
|
|
Please notice that ko will build your binary again.
|
|
|
|
That shouldn't increase the release times too much, as it'll use the same build
|
2023-01-16 23:48:34 -03:00
|
|
|
options as the [build][] pipe when possible, so the results will probably be
|
|
|
|
cached.
|
2023-01-16 22:34:49 -03:00
|
|
|
|
|
|
|
!!! warning
|
2023-03-01 01:45:52 -03:00
|
|
|
Ko only runs on the publishing phase, so it might be a bit hard to test —
|
|
|
|
you might need to push to a fake repository (or a fake tag) when playing
|
|
|
|
around with its configuration.
|
2023-01-16 22:34:49 -03:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
# .goreleaser.yaml
|
|
|
|
kos:
|
|
|
|
-
|
|
|
|
# ID of this image.
|
|
|
|
id: foo
|
|
|
|
|
|
|
|
# Build ID that should be used to import the build settings.
|
|
|
|
build: build-id
|
|
|
|
|
|
|
|
# Main path to build.
|
2023-11-19 14:54:18 -03:00
|
|
|
# It must be a relative path
|
2023-01-16 22:34:49 -03:00
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: build.main
|
2023-01-16 22:34:49 -03:00
|
|
|
main: ./cmd/...
|
|
|
|
|
|
|
|
# Working directory used to build.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: build.dir
|
2023-01-16 22:34:49 -03:00
|
|
|
working_dir: .
|
|
|
|
|
|
|
|
# Base image to publish to use.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: 'cgr.dev/chainguard/static'
|
2023-01-16 22:34:49 -03:00
|
|
|
base_image: alpine
|
|
|
|
|
2023-03-20 12:05:44 -07:00
|
|
|
# Labels for the image.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Since: v1.17
|
2023-03-20 12:05:44 -07:00
|
|
|
labels:
|
|
|
|
foo: bar
|
|
|
|
|
2023-01-16 22:34:49 -03:00
|
|
|
# Repository to push to.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: $KO_DOCKER_REPO
|
2023-01-16 22:34:49 -03:00
|
|
|
repository: ghcr.io/foo/bar
|
|
|
|
|
|
|
|
# Platforms to build and publish.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: 'linux/amd64'
|
2023-01-16 22:34:49 -03:00
|
|
|
platforms:
|
|
|
|
- linux/amd64
|
|
|
|
- linux/arm64
|
|
|
|
|
2023-04-02 17:16:21 -03:00
|
|
|
# Tag to build and push.
|
2023-05-27 00:14:02 -03:00
|
|
|
# Empty tags are ignored.
|
2023-01-16 22:34:49 -03:00
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: 'latest'
|
|
|
|
# Templates: allowed
|
2023-01-16 22:34:49 -03:00
|
|
|
tags:
|
|
|
|
- latest
|
|
|
|
- '{{.Tag}}'
|
2023-05-27 00:14:02 -03:00
|
|
|
- '{{if not .Prerelease}}stable{{end}}'
|
2023-01-16 22:34:49 -03:00
|
|
|
|
2023-03-20 12:05:44 -07:00
|
|
|
# Creation time given to the image
|
|
|
|
# in seconds since the Unix epoch as a string.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Since: v1.17
|
|
|
|
# Templates: allowed
|
2023-03-20 12:05:44 -07:00
|
|
|
creation_time: '{{.CommitTimestamp}}'
|
|
|
|
|
|
|
|
# Creation time given to the files in the kodata directory
|
|
|
|
# in seconds since the Unix epoch as a string.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Since: v1.17
|
|
|
|
# Templates: allowed
|
2023-03-20 12:05:44 -07:00
|
|
|
ko_data_creation_time: '{{.CommitTimestamp}}'
|
|
|
|
|
2023-01-16 22:34:49 -03:00
|
|
|
# SBOM format to use.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: 'spdx'
|
2023-01-16 22:34:49 -03:00
|
|
|
# Valid options are: spdx, cyclonedx, go.version-m and none.
|
|
|
|
sbom: none
|
|
|
|
|
|
|
|
# Ldflags to use on build.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: build.ldflags
|
2023-01-16 22:34:49 -03:00
|
|
|
ldflags:
|
|
|
|
- foo
|
|
|
|
- bar
|
|
|
|
|
|
|
|
# Flags to use on build.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: build.flags
|
2023-01-16 22:34:49 -03:00
|
|
|
flags:
|
|
|
|
- foo
|
|
|
|
- bar
|
|
|
|
|
|
|
|
# Env to use on build.
|
|
|
|
#
|
2023-04-02 17:16:21 -03:00
|
|
|
# Default: build.env
|
2023-01-16 22:34:49 -03:00
|
|
|
env:
|
|
|
|
- FOO=bar
|
|
|
|
- SOMETHING=value
|
|
|
|
|
|
|
|
|
2023-04-02 17:16:21 -03:00
|
|
|
# Bare uses a tag on the $KO_DOCKER_REPO without anything additional.
|
2023-01-16 22:34:49 -03:00
|
|
|
bare: true
|
|
|
|
|
|
|
|
# Whether to preserve the full import path after the repository name.
|
|
|
|
preserve_import_paths: true
|
|
|
|
|
|
|
|
# Whether to use the base path without the MD5 hash after the repository name.
|
|
|
|
base_import_paths: true
|
|
|
|
```
|
|
|
|
|
|
|
|
Refer to [ko's project page][ko] for more information.
|
|
|
|
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
Here's a minimal example:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# .goreleaser.yml
|
|
|
|
before:
|
|
|
|
hooks:
|
|
|
|
- go mod tidy
|
|
|
|
|
|
|
|
builds:
|
|
|
|
- env: [ "CGO_ENABLED=1" ]
|
|
|
|
binary: test
|
|
|
|
goos:
|
|
|
|
- darwin
|
|
|
|
- linux
|
|
|
|
goarch:
|
|
|
|
- amd64
|
|
|
|
- arch64
|
|
|
|
|
|
|
|
kos:
|
|
|
|
- repository: ghcr.io/caarlos0/test-ko
|
|
|
|
tags:
|
2023-01-16 23:48:34 -03:00
|
|
|
- '{{.Version}}'
|
|
|
|
- latest
|
2023-01-16 22:34:49 -03:00
|
|
|
bare: true
|
|
|
|
preserve_import_paths: false
|
|
|
|
platforms:
|
2023-01-16 23:48:34 -03:00
|
|
|
- linux/amd64
|
|
|
|
- linux/arm64
|
2023-01-16 22:34:49 -03:00
|
|
|
```
|
|
|
|
|
|
|
|
This will build the binaries for `linux/arm64`, `linux/amd64`, `darwin/amd64`
|
|
|
|
and `darwin/arm64`, as well as the Docker images and manifest for Linux.
|
|
|
|
|
2023-05-27 00:16:07 -03:00
|
|
|
# Signing KO manifests
|
|
|
|
|
|
|
|
KO will add the built manifest to the artifact list, so you can sign them with
|
|
|
|
`docker_signs`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# .goreleaser.yml
|
|
|
|
docker_signs:
|
|
|
|
-
|
|
|
|
artifacts: manifests
|
|
|
|
```
|
|
|
|
|
2023-01-16 22:34:49 -03:00
|
|
|
[ko]: https://ko.build
|
|
|
|
[build]: /customization/build/
|