Skip to content

Commit

Permalink
feat: Publish multi-arch docker image (amd64 and arm64)
Browse files Browse the repository at this point in the history
  • Loading branch information
project0 committed Mar 24, 2023
1 parent 43ee425 commit 39af567
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 35 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build-push-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
on:
workflow_call:
inputs:
version:
required: true
type: string
tags:
required: true
type: string
labels:
required: false
type: string

jobs:
docker-push:
name: Build and publish docker image
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

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

- name: Build and push images
uses: docker/build-push-action@v4
with:
file: cmd/proxy/Dockerfile
build-args: VERSION=${{ inputs.version }}
tags: ${{ inputs.tags }}
labels: ${{ inputs.labels }}
push: true
platforms: linux/amd64,linux/arm64
26 changes: 6 additions & 20 deletions .github/workflows/release.canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- 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
uses: docker/build-push-action@v4

- name: Build and push canary image
uses: ./.github/workflows/build-push-image.yaml
with:
file: cmd/proxy/Dockerfile
build-args: VERSION=${{github.sha}}
tags: gomods/athens-dev:${{ steps.vars.outputs.sha_short }}
push: true
tags: gomods/athens:canary,gomods/athens-dev:${{ steps.vars.outputs.sha_short }}
version: ${{ github.sha }}
25 changes: 14 additions & 11 deletions .github/workflows/release.latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
images: |
gomods/athens
tags: |
type=raw,value=${{ github.ref_name }}
type=raw,value=latest
- name: Build and push latest tag
uses: docker/build-push-action@v4
uses: ./.github/workflows/build-push-image.yaml
with:
file: cmd/proxy/Dockerfile
build-args: VERSION=${{ github.ref_name }}
tags: gomods/athens:latest,gomods/athens:${{ github.ref_name }}
push: true
tags: {{ steps.meta.outputs.tags }}
labels: {{ steps.meta.outputs.labels }}
version: ${{ github.ref_name }}
17 changes: 13 additions & 4 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 Down

0 comments on commit 39af567

Please sign in to comment.