Skip to content

Build and Push Docker server image #38

Build and Push Docker server image

Build and Push Docker server image #38

Workflow file for this run

name: Build and Push Docker server image
on:
push:
branches: master
paths:
- '**Dockerfile'
- '**docker.yml'
workflow_dispatch:
inputs:
tag:
description: 'change tag name or use default'
required: false
default: 'latest'
type: string
schedule:
- cron: '30 11 * * 5'
env:
REGISTRY_IMAGE: ghcr.io/netpanzer/netpanzer
jobs:
build-env:
runs-on: ubuntu-latest
name: ${{ matrix.platform }}-image
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
- linux/arm/v7
fail-fast: true
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
-
name: Checkout
uses: actions/checkout@v4
with:
submodules: true
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- if: ${{ matrix.platform != 'linux/amd64' }}
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
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.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./support/docker/Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
-
name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
-
name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
# The merge job is needed to complete the job above. # When publishing a
# multi-platform image distributed across multiple runners, it's not as #
# straightforward as just using a matrix
# https://docs.docker.com/build/ci/github-actions/multi-platform/
merge:
runs-on: ubuntu-latest
needs:
- build-env
steps:
-
name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Set tag
run: |
if [ -n "${{ inputs.tag }}" ]; then
TAG="${{ inputs.tag }}"
else
TAG="latest"
fi
# store TAG for use in later steps
echo "TAG=$TAG" >> $GITHUB_ENV
echo "TAG = $TAG" # For debugging (can be removed)
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: type=raw,value=${{ env.TAG }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
-
name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}