Docker Build workflow (cashubtc/nutshell)
The Docker Build workflow from cashubtc/nutshell, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, 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 Build workflow from the cashubtc/nutshell 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 Build
on:
release:
types: [released]
workflow_dispatch:
inputs:
tag_name:
description: 'Tag to build and push (e.g. 0.20.2)'
required: true
type: string
permissions:
contents: read
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Cache Docker layers
uses: actions/cache@v5
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Determine Tags
id: get_tags
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "version_tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
echo "latest_tag=latest" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "version_tag=${{ inputs.tag_name }}" >> "$GITHUB_OUTPUT"
echo "latest_tag=latest" >> "$GITHUB_OUTPUT"
fi
- name: Set up Python
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Verify Versions
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
run: |
python3 scripts/check_version.py "${{ steps.get_tags.outputs.version_tag }}"
- name: Build and push on release
uses: docker/build-push-action@v7
with:
context: .
push: ${{ (github.event_name == 'release' && github.event.action == 'released') || github.event_name == 'workflow_dispatch' }}
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ steps.get_tags.outputs.version_tag }}
${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ steps.get_tags.outputs.latest_tag }}
platforms: linux/amd64,linux/arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Docker Build on: release: types: [released] workflow_dispatch: inputs: tag_name: description: 'Tag to build and push (e.g. 0.20.2)' required: true type: string permissions: contents: read jobs: build-and-push: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout uses: actions/checkout@v6 - name: Login to Docker Hub uses: docker/login-action@v4 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Cache Docker layers uses: actions/cache@v5 id: cache with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx- - name: Determine Tags id: get_tags run: | if [[ "${{ github.event_name }}" == "release" ]]; then echo "version_tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT" echo "latest_tag=latest" >> "$GITHUB_OUTPUT" elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then echo "version_tag=${{ inputs.tag_name }}" >> "$GITHUB_OUTPUT" echo "latest_tag=latest" >> "$GITHUB_OUTPUT" fi - name: Set up Python if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' uses: actions/setup-python@v6 with: cache: 'pip' python-version: "3.11" - name: Verify Versions if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' run: | python3 scripts/check_version.py "${{ steps.get_tags.outputs.version_tag }}" - name: Build and push on release uses: docker/build-push-action@v7 with: context: . push: ${{ (github.event_name == 'release' && github.event.action == 'released') || github.event_name == 'workflow_dispatch' }} tags: | ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ steps.get_tags.outputs.version_tag }} ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ steps.get_tags.outputs.latest_tag }} platforms: linux/amd64,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache
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. - Cache dependency installs on the setup step so they are served from cache.
- 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 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.