Skip to content

Commit

Permalink
release: configure build of Docker images
Browse files Browse the repository at this point in the history
GoReleaser requires specifically crafted Dockerfiles as the build
context is dynamically constructed.

For more information, refer to https://goreleaser.com/errors/docker-build/#do
and other documentation around Docker image templates and manifests.

Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco committed Aug 14, 2023
1 parent 02de4a8 commit b5b3760
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 9 deletions.
100 changes: 91 additions & 9 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ builds:
- -v
- -trimpath
ldflags:
- -s
- -w
- -X "go.mozilla.org/sops/v3/version.Version={{ .Version }}"
- >
-extldflags "-static" -s -w
-X "go.mozilla.org/sops/v3/version.Version={{ .Version }}"
env:
- CGO_ENABLED=0
goos:
Expand All @@ -33,9 +33,9 @@ builds:
- -v
- -trimpath
ldflags:
- -s
- -w
- -X "go.mozilla.org/sops/v3/version.Version={{ .Version }}"
- >
-extldflags "-static" -s -w
-X "go.mozilla.org/sops/v3/version.Version={{ .Version }}"
env:
- CGO_ENABLED=0
goos:
Expand All @@ -54,9 +54,9 @@ builds:
- -v
- -trimpath
ldflags:
- -s
- -w
- -X "go.mozilla.org/sops/v3/version.Version={{ .Version }}"
- >
-extldflags "-static" -s -w
-X "go.mozilla.org/sops/v3/version.Version={{ .Version }}"
env:
- CGO_ENABLED=0
goos:
Expand Down Expand Up @@ -112,3 +112,85 @@ sboms:
artifacts: binary
documents:
- "${artifact}.spdx.sbom.json"

# xref: https://goreleaser.com/customization/docker/
dockers:
- image_templates:
- 'getsops/sops:{{ .Version }}-amd64'
use: buildx
goos: linux
goarch: amd64
ids:
- binary-linux
dockerfile: .release/Dockerfile
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{ .Date }}"
- "--label=org.opencontainers.image.name={{ .ProjectName }}"
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- "--label=org.opencontainers.image.source={{ .GitURL }}"

- image_templates:
- 'getsops/sops:{{ .Version }}-arm64'
use: buildx
goos: linux
goarch: arm64
ids:
- binary-linux
dockerfile: .release/Dockerfile
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{ .Date }}"
- "--label=org.opencontainers.image.name={{ .ProjectName }}"
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- "--label=org.opencontainers.image.source={{ .GitURL }}"

- image_templates:
- 'getsops/sops:{{ .Version }}-alpine-amd64'
use: buildx
goos: linux
goarch: amd64
ids:
- binary-linux
dockerfile: .release/alpine.Dockerfile
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{ .Date }}"
- "--label=org.opencontainers.image.name={{ .ProjectName }}"
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- "--label=org.opencontainers.image.source={{ .GitURL }}"

- image_templates:
- 'getsops/sops:{{ .Version }}-alpine-arm64'
use: buildx
goos: linux
goarch: arm64
ids:
- binary-linux
dockerfile: .release/alpine.Dockerfile
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{ .Date }}"
- "--label=org.opencontainers.image.name={{ .ProjectName }}"
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- "--label=org.opencontainers.image.source={{ .GitURL }}"

# xref: https://goreleaser.com/customization/docker_manifest/
docker_manifests:
- name_template: 'getsops/sops:{{ .Version }}'
image_templates:
- 'getsops/sops:{{ .Version }}-amd64'
- 'getsops/sops:{{ .Version }}-arm64'

- name_template: 'getsops/sops:{{ .Version }}-alpine'
image_templates:
- 'getsops/sops:{{ .Version }}-alpine-amd64'
- 'getsops/sops:{{ .Version }}-alpine-arm64'
16 changes: 16 additions & 0 deletions .release/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM debian:bookworm-slim

RUN apt-get update && apt-get install --no-install-recommends -y \
awscli \
azure-cli \
curl \
gnupg \
vim \
&& rm -rf /var/lib/apt/lists/*

ENV EDITOR vim

# Glob pattern to match the binary for the current architecture
COPY sops* /usr/local/bin/sops

ENTRYPOINT ["sops"]
13 changes: 13 additions & 0 deletions .release/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.18

RUN apk --no-cache add \
ca-certificates \
vim \
&& update-ca-certificates

ENV EDITOR vim

# Glob pattern to match the binary for the current architecture
COPY sops* /usr/local/bin/sops

ENTRYPOINT ["sops"]

0 comments on commit b5b3760

Please sign in to comment.