Skip to content

Commit e35007b

Browse files
authored
feat: Publish multi-arch docker image (amd64 and arm64) (#1862)
* add arm64 to goreleaser
1 parent 7c3e3a0 commit e35007b

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

.github/workflows/release.canary.yml

+13-10
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,30 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v3
11+
12+
- name: Set up QEMU
13+
uses: docker/setup-qemu-action@v2
14+
1115
- name: Set up Docker Buildx
1216
uses: docker/setup-buildx-action@v2
17+
with:
18+
platforms: linux/amd64,linux/arm64
19+
1320
- name: Login to Docker Hub
1421
uses: docker/login-action@v2
1522
with:
1623
username: ${{ secrets.DOCKER_USER }}
1724
password: ${{ secrets.DOCKER_PASSWORD }}
18-
- name: Build and push canary tag
19-
uses: docker/build-push-action@v4
20-
with:
21-
file: cmd/proxy/Dockerfile
22-
build-args: VERSION=${{github.sha}}
23-
tags: gomods/athens:canary
24-
push: true
25+
2526
- name: Set Short SHA
2627
id: vars
2728
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
28-
- name: Build and push commit tag
29+
30+
- name: Build and push images
2931
uses: docker/build-push-action@v4
3032
with:
3133
file: cmd/proxy/Dockerfile
32-
build-args: VERSION=${{github.sha}}
33-
tags: gomods/athens-dev:${{ steps.vars.outputs.sha_short }}
34+
build-args: VERSION=${{ github.sha }}
35+
tags: gomods/athens:canary,gomods/athens-dev:${{ steps.vars.outputs.sha_short }}
3436
push: true
37+
platforms: linux/amd64,linux/arm64

.github/workflows/release.latest.yml

+22-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,37 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v3
11+
12+
- name: Set up QEMU
13+
uses: docker/setup-qemu-action@v2
14+
1115
- name: Set up Docker Buildx
1216
uses: docker/setup-buildx-action@v2
17+
with:
18+
platforms: linux/amd64,linux/arm64
19+
1320
- name: Login to Docker Hub
1421
uses: docker/login-action@v2
1522
with:
1623
username: ${{ secrets.DOCKER_USER }}
1724
password: ${{ secrets.DOCKER_PASSWORD }}
18-
- name: Build and push latest tag
25+
26+
- name: Docker meta
27+
id: meta
28+
uses: docker/metadata-action@v4
29+
with:
30+
images: |
31+
gomods/athens
32+
tags: |
33+
type=raw,value=${{ github.ref_name }}
34+
type=raw,value=latest
35+
36+
- name: Build and push images
1937
uses: docker/build-push-action@v4
2038
with:
2139
file: cmd/proxy/Dockerfile
2240
build-args: VERSION=${{ github.ref_name }}
23-
tags: gomods/athens:latest,gomods/athens:${{ github.ref_name }}
41+
tags: ${{ steps.meta.outputs.tags }}
42+
labels: ${{ steps.meta.outputs.labels }}
2443
push: true
44+
platforms: linux/amd64,linux/arm64

.goreleaser.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ builds:
1212
- darwin
1313
goarch:
1414
- amd64
15+
- arm64
1516
main: cmd/proxy/main.go
1617
binary: athens
1718
ldflags:

cmd/proxy/Dockerfile

+14-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@
88
ARG GOLANG_VERSION=1.20
99
ARG ALPINE_VERSION=3.17
1010

11-
FROM golang:${GOLANG_VERSION}-alpine AS builder
11+
FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION}-alpine AS builder
12+
13+
ARG VERSION="unset" \
14+
TARGETARCH
15+
16+
ENV GOARCH=${TARGETARCH} \
17+
GO111MODULE=on \
18+
CGO_ENABLED=0 \
19+
GOPROXY="https://proxy.golang.org"
1220

1321
WORKDIR $GOPATH/src/github.com/gomods/athens
1422

1523
COPY . .
1624

17-
ARG VERSION="unset"
18-
19-
RUN DATE="$(date -u +%Y-%m-%d-%H:%M:%S-%Z)" && GO111MODULE=on CGO_ENABLED=0 GOPROXY="https://proxy.golang.org" go build -ldflags "-X github.com/gomods/athens/pkg/build.version=$VERSION -X github.com/gomods/athens/pkg/build.buildDate=$DATE -s -w" -o /bin/athens-proxy ./cmd/proxy
25+
RUN DATE="$(date -u +%Y-%m-%d-%H:%M:%S-%Z)" && \
26+
go build \
27+
-ldflags "-X github.com/gomods/athens/pkg/build.version=$VERSION -X github.com/gomods/athens/pkg/build.buildDate=$DATE -s -w" \
28+
-o /bin/athens-proxy ./cmd/proxy
2029

2130
FROM alpine:${ALPINE_VERSION}
2231

@@ -30,7 +39,7 @@ RUN chmod 644 /config/config.toml
3039

3140
# Add tini, see https://github.com/gomods/athens/issues/1155 for details.
3241
RUN apk add --update git git-lfs mercurial openssh-client subversion procps fossil tini && \
33-
mkdir -p /usr/local/go
42+
mkdir -p /usr/local/go
3443

3544
ARG USER=athens
3645
RUN adduser -D -h /home/$USER $USER

0 commit comments

Comments
 (0)