Skip to content
Latchkey

Docker Image Build/Publish source image workflow (vtuber-plan/olah)

The Docker Image Build/Publish source image workflow from vtuber-plan/olah, explained and optimized by Latchkey.

B

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.

Grade your own workflow free or run it on Latchkey →
Source: vtuber-plan/olah.github/workflows/docker-image-tag-commit.ymlLicense MITView source

What it does

This is the Docker Image Build/Publish source 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

workflow (.yml)
name: Docker Image Build/Publish source image

on:
  push:
    branches:
      - dev
    paths:
      - src/**
      - pyproject.toml
      - requirements.txt
      - docker/build@source/dockerfile
      - .github/workflows/docker-image-tag-commit.yml
  workflow_dispatch:
    inputs:
      git_ref:
        description: Git ref to build from, such as dev or a commit SHA
        required: true
        default: dev

permissions:
  contents: read
  packages: write

concurrency:
  group: docker-source-${{ github.event_name }}-${{ github.ref_name || github.event.inputs.git_ref }}
  cancel-in-progress: true

jobs:
  build-and-push-docker-image:
    name: Build source Docker image and push to registries
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.inputs.git_ref || github.ref_name }}

      - 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: Compute image tags
        env:
          DOCKERHUB_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/olah
          GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/olah
        run: |
          SHORT_SHA="$(git rev-parse --short HEAD)"
          TAGS="${DOCKERHUB_IMAGE}:sha-${SHORT_SHA}"$'\n'"${GHCR_IMAGE}:sha-${SHORT_SHA}"
          if [[ "${{ github.event_name }}" == "push" ]]; then
            TAGS="${TAGS}"$'\n'"${DOCKERHUB_IMAGE}:dev"$'\n'"${GHCR_IMAGE}:dev"
          fi
          {
            echo "IMAGE_TAGS<<EOF"
            echo "${TAGS}"
            echo "EOF"
          } >> "$GITHUB_ENV"

      - name: Build push image
        id: build
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ./docker/build@source/dockerfile
          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 source image
 
on:
  push:
    branches:
      - dev
    paths:
      - src/**
      - pyproject.toml
      - requirements.txt
      - docker/build@source/dockerfile
      - .github/workflows/docker-image-tag-commit.yml
  workflow_dispatch:
    inputs:
      git_ref:
        description: Git ref to build from, such as dev or a commit SHA
        required: true
        default: dev
 
permissions:
  contents: read
  packages: write
 
concurrency:
  group: docker-source-${{ github.event_name }}-${{ github.ref_name || github.event.inputs.git_ref }}
  cancel-in-progress: true
 
jobs:
  build-and-push-docker-image:
    timeout-minutes: 30
    name: Build source Docker image and push to registries
    runs-on: latchkey-small
 
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.inputs.git_ref || github.ref_name }}
 
      - 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: Compute image tags
        env:
          DOCKERHUB_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/olah
          GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/olah
        run: |
          SHORT_SHA="$(git rev-parse --short HEAD)"
          TAGS="${DOCKERHUB_IMAGE}:sha-${SHORT_SHA}"$'\n'"${GHCR_IMAGE}:sha-${SHORT_SHA}"
          if [[ "${{ github.event_name }}" == "push" ]]; then
            TAGS="${TAGS}"$'\n'"${DOCKERHUB_IMAGE}:dev"$'\n'"${GHCR_IMAGE}:dev"
          fi
          {
            echo "IMAGE_TAGS<<EOF"
            echo "${TAGS}"
            echo "EOF"
          } >> "$GITHUB_ENV"
 
      - name: Build push image
        id: build
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ./docker/build@source/dockerfile
          platforms: linux/amd64,linux/arm64
          push: true
          tags: ${{ env.IMAGE_TAGS }}
 
      - name: Print image digest
        run: echo "${{ steps.build.outputs.digest }}"
 

What changed

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:

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow