Docker Release Build #2
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: Docker Release Build | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
docker: | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
platform: [linux/amd64, linux/arm64] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for all tags | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
LATEST_TAG=$(git describe --tags --abbrev=0) | |
echo "VERSION=${LATEST_TAG}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate downcase repository name | |
run: | | |
echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ env.REPO }} | |
tags: | | |
type=raw,value=${{ env.VERSION }}-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} | |
type=raw,value=latest-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
platforms: ${{ matrix.platform }} | |
build-args: | | |
VERSION=${{ env.VERSION }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
provenance: false | |
create-manifest: | |
needs: docker | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
LATEST_TAG=$(git describe --tags --abbrev=0) | |
echo "VERSION=${LATEST_TAG}" >> $GITHUB_ENV | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate downcase repository name | |
run: | | |
echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV} | |
- name: Create and push manifest | |
run: | | |
# Create and push the versioned manifest | |
docker manifest create --amend ghcr.io/${{ env.REPO }}:${{ env.VERSION }} \ | |
ghcr.io/${{ env.REPO }}:${{ env.VERSION }}-amd64 \ | |
ghcr.io/${{ env.REPO }}:${{ env.VERSION }}-arm64 | |
docker manifest push --purge ghcr.io/${{ env.REPO }}:${{ env.VERSION }} | |
# Create and push the latest manifest | |
docker manifest create --amend ghcr.io/${{ env.REPO }}:latest \ | |
ghcr.io/${{ env.REPO }}:latest-amd64 \ | |
ghcr.io/${{ env.REPO }}:latest-arm64 | |
docker manifest push --purge ghcr.io/${{ env.REPO }}:latest |