Skip to content

fixed workflow

fixed workflow #65

name: Create and publish a Docker image
on:
push:
branches: ["**"] # run for any commit or tag push on any branch
tags-ignore: ["v**"] # reserve v* tags for releases
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- dockerfile: Dockerfile
image: novatecconsulting/opentelemetry-training-application
context: .
registry:
- name: ghcr.io
username: ${{ github.repository_owner }}
password: GITHUB_TOKEN
platform:
- linux/amd64
- linux/arm64
runs-on: ubuntu-latest
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout Repository
uses: actions/checkout@v4
- 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: ${{ matrix.registry.name }}
username: ${{ matrix.registry.username }}
password: ${{ secrets[matrix.registry.password] }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.registry.name }}/${{ matrix.image }}
- name: Build and Push Digest
id: build
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ matrix.registry.name }}/${{ matrix.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
merge:
runs-on: ubuntu-latest
needs:
- build
strategy:
fail-fast: false
matrix:
include:
- image: novatecconsulting/opentelemetry-training-application
registry:
- name: ghcr.io
username: ${{ github.repository_owner }}
password: GITHUB_TOKEN
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: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ matrix.registry.name }}
username: ${{ matrix.registry.username }}
password: ${{ secrets[matrix.registry.password] }}
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.registry.name }}/${{ matrix.image }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- 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 '${{ matrix.registry.name }}/${{ matrix.image }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ matrix.registry.name }}/${{ matrix.image }}:${{ steps.meta.outputs.version }}