Skip to content

Commit

Permalink
Build both amd64 and arm64 container images
Browse files Browse the repository at this point in the history
While here, also publish them to the new Github registry.
  • Loading branch information
artyom committed Dec 14, 2023
1 parent 7eefa3f commit 0959b3c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
54 changes: 25 additions & 29 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: '^1.0.0'
- uses: actions/checkout@v2
go-version: 'stable'
- uses: actions/checkout@v4
- name: Get dependencies
run: go mod download
- name: Install redis
Expand All @@ -30,30 +30,26 @@ jobs:
if: github.event_name == 'push'
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- name: Build image
- uses: actions/checkout@v4
- id: gen-tag
run: |
echo ${GITHUB_REF##*/} | tee ci-version.txt
docker build . --tag image
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin
- name: Push image
run: |
set -u
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables
IMAGE_ID=docker.pkg.github.com/doist/$IMAGE_NAME/$IMAGE_NAME
# Strip git ref prefix from version
VERSION=${GITHUB_REF##*/}
# Strip "v" prefix from tag name
case "${GITHUB_REF}" in refs/tags/*) VERSION=${VERSION#v} ;; esac
case "$VERSION" in master) VERSION=latest ;; esac
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo GITHUB_REF=$GITHUB_REF
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
IMAGE_TAG=${GITHUB_REF##*/}
echo IMAGE_TAG | tee ci-version.txt
echo "tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_PACKAGES_TOKEN }}
- uses: docker/build-push-action@v5
with:
push: true
platforms: |
linux/arm64
linux/amd64
tags: |
ghcr.io/doist/bitmapist-server:${{ steps.gen-tag.outputs.tag }}
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=6,force-compression=true
cache-from: type=gha
cache-to: type=gha,mode=max
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM golang:alpine AS builder
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/golang:alpine AS builder
WORKDIR /app
ENV GOPROXY=https://proxy.golang.org CGO_ENABLED=0
ENV CGO_ENABLED=0
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
ARG TARGETOS TARGETARCH
RUN test -s ci-version.txt && \
go build -trimpath -ldflags='-s -w' -o bitmapist-server \
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags='-s -w' -o bitmapist-server \
-ldflags="-X=main.explicitVersion=$(cat ci-version.txt)" || \
go build -trimpath -ldflags='-s -w' -o bitmapist-server
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags='-s -w' -o bitmapist-server

FROM scratch
COPY --from=builder /app/bitmapist-server .
Expand Down

0 comments on commit 0959b3c

Please sign in to comment.