ci: publish Docker images for version tags and stable releases
Some checks failed
ci / tests (push) Has been cancelled
Some checks failed
ci / tests (push) Has been cancelled
- Publish images on semantic version tags (vX.Y.Z) as :vX.Y.Z and :latest - Publish :stable image via workflow_run after successful Stable Tag workflow - Build stable image from exact commit marked as stable - Remove duplicate build steps and unify tag computation https://chatgpt.com/share/694b9758-58fc-800f-a586-8f3a341ece9d
This commit is contained in:
65
.github/workflows/publish-image.yml
vendored
65
.github/workflows/publish-image.yml
vendored
@@ -3,16 +3,19 @@ name: publish-image
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "*"
|
- "v*.*.*"
|
||||||
|
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["Stable Tag"] # MUST match stable-tag.yml -> name: Stable Tag
|
||||||
|
types: [completed]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
|
||||||
uses: ./.github/workflows/reusable-test.yml
|
|
||||||
|
|
||||||
build-and-push:
|
build-and-push:
|
||||||
needs: tests
|
if: |
|
||||||
runs-on: ubuntu-latest
|
(github.event_name == 'push') ||
|
||||||
|
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
@@ -20,6 +23,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# push: checks out the tag ref
|
||||||
|
# workflow_run: checks out the exact commit that the Stable Tag workflow ran on
|
||||||
|
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.ref }}
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
@@ -27,48 +34,34 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Extract tag
|
- name: Login to GHCR
|
||||||
id: meta
|
|
||||||
run: |
|
|
||||||
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Check semver tag
|
|
||||||
id: semver
|
|
||||||
run: |
|
|
||||||
if [[ "${GITHUB_REF_NAME}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
||||||
echo "is_semver=true" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
|
||||||
echo "is_semver=false" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Log in to GHCR
|
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push (tag)
|
- name: Compute tags
|
||||||
uses: docker/build-push-action@v6
|
id: meta
|
||||||
with:
|
shell: bash
|
||||||
context: .
|
run: |
|
||||||
file: ./Dockerfile
|
set -euo pipefail
|
||||||
push: true
|
IMAGE="ghcr.io/${{ github.repository }}"
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
tags: |
|
|
||||||
ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.tag }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
|
|
||||||
- name: Build and push (latest)
|
if [ "${{ github.event_name }}" = "push" ]; then
|
||||||
if: steps.semver.outputs.is_semver == 'true'
|
TAG="${{ github.ref_name }}" # e.g. v1.1.0
|
||||||
|
echo "tags=$IMAGE:$TAG,$IMAGE:latest" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "tags=$IMAGE:stable" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: |
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
ghcr.io/${{ github.repository }}:latest
|
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|||||||
Reference in New Issue
Block a user