Skip to content

Fix broken CI

Fix broken CI #3

name: Build and push docker image
on:
workflow_dispatch:
push:
branches: [main]
env:
CARGO_TERM_COLOR: always
REGISTRY_IMAGE: ghcr.io/svix/openapi-codegen
jobs:
build:
strategy:
matrix:
platform:
- runner: ubuntu-24.04
name: amd64
- runner: ubuntu-24.04-arm
name: arm64
name: Build and publish ${{ matrix.platform.name }} docker image
if: github.ref == 'refs/heads/main'
runs-on: "${{ matrix.platform.runner }}"
steps:
- uses: actions/checkout@v4
- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
tags: ${{ env.REGISTRY_IMAGE }}
file: Dockerfile
cache-from: type=gha
cache-to: type=gha
platforms: linux/${{ matrix.platform.name }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
- name: Export digest
# we create empty files with the sha256 digest of the docker image as the filename
# since we did not push with a tag, the only way to identify the image is with the digest
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
with:
name: digests-${{ matrix.platform.name }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
publish-merged-manifest:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
needs:
- build
steps:
- uses: actions/checkout@v4
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- run: echo "IMAGE_TAG=$(date +%Y%m%d)-$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
- name: Create manifest list and push
# inside the ${{ runner.temp }}/digests we downloaded empty files with the sha256 digest of the image as the filename
# using printf we get the digest from the filename and we add the digest to the manifest
# this is the recommend way of doing things :(
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create \
-t ${{ env.REGISTRY_IMAGE }}:latest \
-t ${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }} \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect "${{ env.REGISTRY_IMAGE }}:latest"