Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Publish multi-arch docker image (amd64 and arm64) #1862

Merged
merged 7 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .github/workflows/release.canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64,linux/arm64

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push canary tag
uses: docker/build-push-action@v4
with:
file: cmd/proxy/Dockerfile
build-args: VERSION=${{github.sha}}
tags: gomods/athens:canary
push: true

- name: Set Short SHA
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push commit tag

- name: Build and push images
uses: docker/build-push-action@v4
with:
file: cmd/proxy/Dockerfile
build-args: VERSION=${{github.sha}}
tags: gomods/athens-dev:${{ steps.vars.outputs.sha_short }}
build-args: VERSION=${{ github.sha }}
tags: gomods/athens:canary,gomods/athens-dev:${{ steps.vars.outputs.sha_short }}
push: true
platforms: linux/amd64,linux/arm64
24 changes: 22 additions & 2 deletions .github/workflows/release.latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,37 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64,linux/arm64

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push latest tag

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
gomods/athens
tags: |
type=raw,value=${{ github.ref_name }}
type=raw,value=latest

- name: Build and push images
uses: docker/build-push-action@v4
with:
file: cmd/proxy/Dockerfile
build-args: VERSION=${{ github.ref_name }}
tags: gomods/athens:latest,gomods/athens:${{ github.ref_name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
platforms: linux/amd64,linux/arm64
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ builds:
- darwin
goarch:
- amd64
- arm64
main: cmd/proxy/main.go
binary: athens
ldflags:
Expand Down
19 changes: 14 additions & 5 deletions cmd/proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@
ARG GOLANG_VERSION=1.20
ARG ALPINE_VERSION=3.17

FROM golang:${GOLANG_VERSION}-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION}-alpine AS builder

ARG VERSION="unset" \
TARGETARCH

ENV GOARCH=${TARGETARCH} \
GO111MODULE=on \
CGO_ENABLED=0 \
GOPROXY="https://proxy.golang.org"

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

COPY . .

ARG VERSION="unset"

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
RUN DATE="$(date -u +%Y-%m-%d-%H:%M:%S-%Z)" && \
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

FROM alpine:${ALPINE_VERSION}

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

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

ARG USER=athens
RUN adduser -D -h /home/$USER $USER
Expand Down