Test #38
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: OCI Image CI | |
on: | |
push: | |
branches: [ "main" ] | |
env: | |
IMAGE_NAME: caddy | |
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} | |
REGISTRY_USER: ${{ github.actor }} | |
REGISTRY_PASSWORD: ${{ github.token }} | |
jobs: | |
build-and-push: | |
strategy: | |
matrix: | |
platform: [amd64, arm64] | |
include: | |
- platform: amd64 | |
runner: ubuntu-24.04 | |
- platform: arm64 | |
runner: ubuntu-24.04-arm | |
runs-on: ${{ matrix.runner }} | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
steps: | |
# Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
install: true | |
# Log in to GitHub Container Registry | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ env.REGISTRY_USER }} | |
password: ${{ env.REGISTRY_PASSWORD }} | |
# Extract the tag from the Containerfile using awk | |
- name: Get upstream tag | |
id: get_upstream_tag | |
run: | | |
UPSTREAM_TAG=$(awk '/^FROM .*caddy:/ { split($2, a, ":"); print a[2] }' Containerfile | tail -n 1) | |
echo "Extracted UPSTREAM_TAG=${UPSTREAM_TAG}" | |
if [ -z "$UPSTREAM_TAG" ]; then | |
echo "UPSTREAM_TAG must not be empty" | |
exit 1 | |
fi | |
echo "UPSTREAM_TAG=${UPSTREAM_TAG}" >> "$GITHUB_ENV" | |
# Build and push the architecture-specific Docker image | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Containerfile # Specify the Containerfile here | |
platforms: linux/${{ matrix.platform }} | |
push: true | |
tags: | | |
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.UPSTREAM_TAG }}-${{ matrix.platform }} | |
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:latest-${{ matrix.platform }} | |
create-manifest: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
# Log in to GitHub Container Registry | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ env.REGISTRY_USER }} | |
password: ${{ env.REGISTRY_PASSWORD }} | |
# Create and push the multi-architecture manifest using Docker commands | |
- name: Create and Push Manifest | |
run: | | |
docker manifest create ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.UPSTREAM_TAG }} \ | |
--amend ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.UPSTREAM_TAG }}-amd64 \ | |
--amend ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.UPSTREAM_TAG }}-arm64 | |
docker manifest push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.UPSTREAM_TAG }} | |
docker manifest create ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest \ | |
--amend ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest-amd64 \ | |
--amend ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest-arm64 | |
docker manifest push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest |