Skip to content

Commit

Permalink
use arm64 runners (#592)
Browse files Browse the repository at this point in the history
* test arm64 runners

* remove tags from build

* fix

* test

* test

* test

* test pushing

* prune untagged

* don't push on pr

* don't push on pr
  • Loading branch information
Zibbp authored Jan 23, 2025
1 parent 237261e commit 286d7a0
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 63 deletions.
141 changes: 141 additions & 0 deletions .github/workflows/docker-build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Docker Build & Publish

on:
push:
branches: ["main"]
# Publish semver tags as releases.
tags: ["v*.*.*"]
pull_request:
branches: ["main"]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
OCI_IMAGE_NAME: ""

jobs:
build:
name: Build OCI Images
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
arch: amd64
platform: linux/amd64
- os: ubuntu-24.04-arm
arch: arm64
platform: linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Set correct OCI image name
id: ociImageName
run: echo "::set-output name=lowerCaseValue::${OCI_IMAGE_NAME,,}"
env:
OCI_IMAGE_NAME: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Checkout the repo
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

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

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

# Login into GitHub Container Registry except on PR
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
push: ${{ github.event_name != 'pull_request'}}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,"name=${{ steps.ociImageName.outputs.lowerCaseValue }}",push-by-digest=true,name-canonical=true

- name: Export digest
if: github.event_name != 'pull_request'
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
if: github.event_name != 'pull_request'
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs:
- build
steps:
- name: Set correct OCI image name
id: ociImageName
run: echo "::set-output name=lowerCaseValue::${OCI_IMAGE_NAME,,}"
env:
OCI_IMAGE_NAME: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true

- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ steps.ociImageName.outputs.lowerCaseValue }}
tags: |
type=semver,pattern={{version}}
type=raw,value=dev
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ steps.ociImageName.outputs.lowerCaseValue }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ steps.ociImageName.outputs.lowerCaseValue }}:${{ steps.meta.outputs.version }}
63 changes: 0 additions & 63 deletions .github/workflows/docker-publish.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/packages-delete-untagged.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Delete Untagged Packages
on:
schedule:
- cron: "30 1 * * 0"
workflow_run:
workflows: ["Docker Build & Publish"]
types:
- completed
workflow_dispatch:
jobs:
delete-untagged:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: dataaxiom/ghcr-cleanup-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 286d7a0

Please sign in to comment.