Skip to content

Commit

Permalink
updated docker image to support arm
Browse files Browse the repository at this point in the history
  • Loading branch information
Barakudum committed Nov 30, 2024
1 parent 27976b6 commit 3562221
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 31 deletions.
74 changes: 46 additions & 28 deletions .github/workflows/container-release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Container Release
name: Create and publish a Docker image

on:
push:
Expand All @@ -8,37 +8,55 @@ on:
- v*

env:
IMAGE_NAME: server
REGISTRY: ghcr.io
#IMAGE_NAME: ${{ github.repository }}
IMAGE_NAME: ${{ github.repository_owner }}/server

jobs:
push:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
packages: write
attestations: write
id-token: write

steps:
- uses: actions/checkout@v4

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# This changes all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# This strips the git ref prefix from the version.
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# This strips the "v" prefix from the tag name.
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# This uses the Docker `latest` tag convention.
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Checkout repository
uses: actions/checkout@v4

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

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

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM python:3.12-alpine AS base
ARG PYTHON_VERSION=3.12

RUN apk update
RUN apk upgrade
FROM python:${PYTHON_VERSION}-alpine AS base

RUN apk update && apk upgrade --no-cache

FROM base AS builder

Expand Down

0 comments on commit 3562221

Please sign in to comment.