Skip to content

Commit e2053b4

Browse files
authored
ci: publish multi-arch docker images via goreleaser (#62)
Adds dockers/docker_manifests to build and push linux/amd64+arm64 images to Docker Hub on each v* tag (tags <version>-alpine and latest for stable releases), replacing the manual 'make build-docker-image'. Runtime image is a minimal Alpine that wraps the prebuilt binary. Workflow gains QEMU, Buildx and a Docker Hub login. Verified locally with 'goreleaser release --snapshot': both arch images build and the container runs 'db-migrator --version'. Requires repo secrets DOCKERHUB_USERNAME and DOCKERHUB_TOKEN.
1 parent 6128311 commit e2053b4

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

.docker/goreleaser/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Runtime image used by GoReleaser (see `dockers` in .goreleaser.yaml).
2+
# GoReleaser places the prebuilt, statically-linked `db-migrator` binary into the
3+
# build context, so this image just wraps it in a minimal Alpine runtime — no
4+
# compilation happens here. Built per-arch and combined into a multi-arch manifest.
5+
FROM alpine:latest
6+
RUN apk add --no-cache tzdata ca-certificates
7+
ENV TZ=UTC
8+
COPY db-migrator /usr/bin/db-migrator
9+
ENTRYPOINT ["/usr/bin/db-migrator"]

.github/workflows/release.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ jobs:
2323
with:
2424
go-version: '1.26'
2525

26+
# QEMU + Buildx enable cross-arch (linux/arm64) Docker image builds.
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v3
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Login to Docker Hub
34+
uses: docker/login-action@v3
35+
with:
36+
username: ${{ secrets.DOCKERHUB_USERNAME }}
37+
password: ${{ secrets.DOCKERHUB_TOKEN }}
38+
2639
- name: Run GoReleaser
2740
uses: goreleaser/goreleaser-action@v6
2841
with:

.goreleaser.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,54 @@ nfpms:
6767
# (the legacy Makefile deb installed to /opt/bin).
6868
bindir: /usr/bin
6969

70+
# Multi-arch Docker images published to Docker Hub (raoptimus/db-migrator).
71+
# Replaces the manual `make build-docker-image`. Requires buildx + QEMU and a
72+
# Docker Hub login in the release workflow (DOCKERHUB_USERNAME / DOCKERHUB_TOKEN).
73+
# One image is built per architecture, then combined into a manifest below.
74+
dockers:
75+
- id: db-migrator-amd64
76+
goos: linux
77+
goarch: amd64
78+
dockerfile: .docker/goreleaser/Dockerfile
79+
use: buildx
80+
image_templates:
81+
- "raoptimus/db-migrator:{{ .Version }}-alpine-amd64"
82+
build_flag_templates:
83+
- "--platform=linux/amd64"
84+
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
85+
- "--label=org.opencontainers.image.version={{ .Version }}"
86+
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
87+
- "--label=org.opencontainers.image.source=https://github.com/raoptimus/db-migrator.go"
88+
- "--label=org.opencontainers.image.licenses=BSD-3-Clause"
89+
- id: db-migrator-arm64
90+
goos: linux
91+
goarch: arm64
92+
dockerfile: .docker/goreleaser/Dockerfile
93+
use: buildx
94+
image_templates:
95+
- "raoptimus/db-migrator:{{ .Version }}-alpine-arm64"
96+
build_flag_templates:
97+
- "--platform=linux/arm64"
98+
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
99+
- "--label=org.opencontainers.image.version={{ .Version }}"
100+
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
101+
- "--label=org.opencontainers.image.source=https://github.com/raoptimus/db-migrator.go"
102+
- "--label=org.opencontainers.image.licenses=BSD-3-Clause"
103+
104+
docker_manifests:
105+
# Versioned multi-arch tag, e.g. raoptimus/db-migrator:1.8.0-alpine
106+
- name_template: "raoptimus/db-migrator:{{ .Version }}-alpine"
107+
image_templates:
108+
- "raoptimus/db-migrator:{{ .Version }}-alpine-amd64"
109+
- "raoptimus/db-migrator:{{ .Version }}-alpine-arm64"
110+
# `latest` points at the same arch images, but only for stable releases so a
111+
# pre-release (e.g. v1.8.0-beta.1) never overwrites it.
112+
- name_template: "raoptimus/db-migrator:latest"
113+
skip_push: '{{ if .Prerelease }}true{{ else }}false{{ end }}'
114+
image_templates:
115+
- "raoptimus/db-migrator:{{ .Version }}-alpine-amd64"
116+
- "raoptimus/db-migrator:{{ .Version }}-alpine-arm64"
117+
70118
# Homebrew Cask published to the raoptimus/homebrew-tap repository on each release.
71119
# Requires:
72120
# 1. An existing repo github.com/raoptimus/homebrew-tap

0 commit comments

Comments
 (0)