Docker Image Build/Publish release image workflow (vtuber-plan/olah)
The Docker Image Build/Publish release image workflow from vtuber-plan/olah, explained and optimized by Latchkey.
CI health: B - good
Point runs-on at Latchkey and get job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Docker Image Build/Publish release image workflow from the vtuber-plan/olah repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Docker Image Build/Publish release image
on:
workflow_run:
workflows:
- Build and publish release artifacts
types:
- completed
workflow_dispatch:
inputs:
olah_version:
description: Published Olah version already available on PyPI
required: true
default: 0.4.1
permissions:
contents: read
packages: write
concurrency:
group: docker-release-${{ github.event.workflow_run.head_branch || github.event.inputs.olah_version }}
cancel-in-progress: false
jobs:
build-and-push-docker-image:
name: Build release Docker image and push to registries
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Determine package source and image tags
env:
DOCKERHUB_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/olah
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/olah
run: |
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
TAG_NAME="${{ github.event.workflow_run.head_branch }}"
VERSION="${TAG_NAME#v}"
OLAH_SOURCE="https://github.com/${{ github.repository }}/releases/download/${TAG_NAME}/olah-${VERSION}-py3-none-any.whl"
PUSH_LATEST="true"
else
VERSION="${{ github.event.inputs.olah_version }}"
OLAH_SOURCE="olah==${VERSION}"
PUSH_LATEST="false"
fi
TAGS="${DOCKERHUB_IMAGE}:${VERSION}"$'\n'"${GHCR_IMAGE}:${VERSION}"
if [[ "${PUSH_LATEST}" == "true" ]]; then
TAGS="${TAGS}"$'\n'"${DOCKERHUB_IMAGE}:latest"$'\n'"${GHCR_IMAGE}:latest"
fi
echo "OLAH_SOURCE=${OLAH_SOURCE}" >> "$GITHUB_ENV"
echo "OLAH_VERSION=${VERSION}" >> "$GITHUB_ENV"
{
echo "IMAGE_TAGS<<EOF"
echo "${TAGS}"
echo "EOF"
} >> "$GITHUB_ENV"
- name: Checkout code
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 Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- 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 push image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/build@pypi/dockerfile
build-args: |
OLAH_SOURCE=${{ env.OLAH_SOURCE }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE_TAGS }}
- name: Print image digest
run: echo "${{ steps.build.outputs.digest }}"
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Docker Image Build/Publish release image on: workflow_run: workflows: - Build and publish release artifacts types: - completed workflow_dispatch: inputs: olah_version: description: Published Olah version already available on PyPI required: true default: 0.4.1 permissions: contents: read packages: write concurrency: group: docker-release-${{ github.event.workflow_run.head_branch || github.event.inputs.olah_version }} cancel-in-progress: false jobs: build-and-push-docker-image: timeout-minutes: 30 name: Build release Docker image and push to registries if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} runs-on: latchkey-small steps: - name: Determine package source and image tags env: DOCKERHUB_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/olah GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/olah run: | if [[ "${{ github.event_name }}" == "workflow_run" ]]; then TAG_NAME="${{ github.event.workflow_run.head_branch }}" VERSION="${TAG_NAME#v}" OLAH_SOURCE="https://github.com/${{ github.repository }}/releases/download/${TAG_NAME}/olah-${VERSION}-py3-none-any.whl" PUSH_LATEST="true" else VERSION="${{ github.event.inputs.olah_version }}" OLAH_SOURCE="olah==${VERSION}" PUSH_LATEST="false" fi TAGS="${DOCKERHUB_IMAGE}:${VERSION}"$'\n'"${GHCR_IMAGE}:${VERSION}" if [[ "${PUSH_LATEST}" == "true" ]]; then TAGS="${TAGS}"$'\n'"${DOCKERHUB_IMAGE}:latest"$'\n'"${GHCR_IMAGE}:latest" fi echo "OLAH_SOURCE=${OLAH_SOURCE}" >> "$GITHUB_ENV" echo "OLAH_VERSION=${VERSION}" >> "$GITHUB_ENV" { echo "IMAGE_TAGS<<EOF" echo "${TAGS}" echo "EOF" } >> "$GITHUB_ENV" - name: Checkout code 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 Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - 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 push image id: build uses: docker/build-push-action@v5 with: context: . file: ./docker/build@pypi/dockerfile build-args: | OLAH_SOURCE=${{ env.OLAH_SOURCE }} platforms: linux/amd64,linux/arm64 push: true tags: ${{ env.IMAGE_TAGS }} - name: Print image digest run: echo "${{ steps.build.outputs.digest }}"
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
4 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Container pulls and builds
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.