Build & Push Docker Images to GHCR workflow (pwndoc/pwndoc)
The Build & Push Docker Images to GHCR workflow from pwndoc/pwndoc, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Build & Push Docker Images to GHCR workflow from the pwndoc/pwndoc 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: Build & Push Docker Images to GHCR
on:
push:
tags:
- 'v*.*.*' # Runs on version tags (e.g., v1.0.0)
env:
REGISTRY: ghcr.io
IMAGE_NAME_BACKEND: ghcr.io/${{ github.repository }}-backend
IMAGE_NAME_FRONTEND: ghcr.io/${{ github.repository }}-frontend
IMAGE_NAME_LANGUAGETOOLS: ghcr.io/${{ github.repository }}-languagetools
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Check if tag is on main branch
run: |
if ! git branch -r --contains HEAD | grep -q 'origin/main'; then
echo "This tag is not on the main branch. Aborting."
exit 1
fi
- name: Run all tests
run: ./pwndoc-cli test
build-and-push-images:
needs: run-tests
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Backend
id: meta-backend
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME_BACKEND }}
tags: |
type=semver,pattern={{version}},prefix=
type=raw,value=latest
- name: Build & Push Backend Image
uses: docker/build-push-action@v5
with:
context: ./backend
push: true
tags: ${{ steps.meta-backend.outputs.tags }}
- name: Extract metadata (tags, labels) for Frontend
id: meta-frontend
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME_FRONTEND }}
tags: |
type=semver,pattern={{version}},prefix=
type=raw,value=latest
- name: Build & Push Frontend Image
uses: docker/build-push-action@v5
with:
context: ./frontend
push: true
tags: ${{ steps.meta-frontend.outputs.tags }}
- name: Extract metadata (tags, labels) for LanguageTools
id: meta-languagetools
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME_LANGUAGETOOLS }}
tags: |
type=semver,pattern={{version}},prefix=
type=raw,value=latest
- name: Build & Push LanguageTools Image
uses: docker/build-push-action@v5
with:
context: ./languagetool
push: true
tags: ${{ steps.meta-languagetools.outputs.tags }}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Build & Push Docker Images to GHCR on: push: tags: - 'v*.*.*' # Runs on version tags (e.g., v1.0.0) env: REGISTRY: ghcr.io IMAGE_NAME_BACKEND: ghcr.io/${{ github.repository }}-backend IMAGE_NAME_FRONTEND: ghcr.io/${{ github.repository }}-frontend IMAGE_NAME_LANGUAGETOOLS: ghcr.io/${{ github.repository }}-languagetools concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: run-tests: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout repository uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 - name: Check if tag is on main branch run: | if ! git branch -r --contains HEAD | grep -q 'origin/main'; then echo "This tag is not on the main branch. Aborting." exit 1 fi - name: Run all tests run: ./pwndoc-cli test build-and-push-images: timeout-minutes: 30 needs: run-tests runs-on: latchkey-small permissions: contents: read packages: write attestations: write id-token: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Backend id: meta-backend uses: docker/metadata-action@v5 with: images: ${{ env.IMAGE_NAME_BACKEND }} tags: | type=semver,pattern={{version}},prefix= type=raw,value=latest - name: Build & Push Backend Image uses: docker/build-push-action@v5 with: context: ./backend push: true tags: ${{ steps.meta-backend.outputs.tags }} - name: Extract metadata (tags, labels) for Frontend id: meta-frontend uses: docker/metadata-action@v5 with: images: ${{ env.IMAGE_NAME_FRONTEND }} tags: | type=semver,pattern={{version}},prefix= type=raw,value=latest - name: Build & Push Frontend Image uses: docker/build-push-action@v5 with: context: ./frontend push: true tags: ${{ steps.meta-frontend.outputs.tags }} - name: Extract metadata (tags, labels) for LanguageTools id: meta-languagetools uses: docker/metadata-action@v5 with: images: ${{ env.IMAGE_NAME_LANGUAGETOOLS }} tags: | type=semver,pattern={{version}},prefix= type=raw,value=latest - name: Build & Push LanguageTools Image uses: docker/build-push-action@v5 with: context: ./languagetool push: true tags: ${{ steps.meta-languagetools.outputs.tags }}
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. - Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
3 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 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.