Build and Push Base Image workflow (talebook/talebook)
The Build and Push Base Image workflow from talebook/talebook, 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 and Push Base Image workflow from the talebook/talebook repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-2-Clause license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Build and Push Base Image
permissions:
contents: read
# 基础镜像(Dockerfile.base)独立构建,只在以下情况触发,避免日常改 app 时重复编译:
# - 改动了 Dockerfile.base(push 到 master)
# - 打 base-v* 形式的 tag 发布版本(如 base-v8.5.0)
# - 手动触发
on:
push:
branches:
- master
paths:
- "Dockerfile.base"
- ".github/workflows/build-base.yml"
tags:
- "base-v*"
workflow_dispatch:
env:
REGISTRY: docker.io
IMAGE_NAME: talebook/talebook-base
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# base-v8.5.0 -> 8 / 8.5 / 8.5.0;master push -> latest / master
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
type=raw,value=master,enable=${{ github.ref == 'refs/heads/master' }}
type=match,pattern=base-v(\d+),group=1
type=match,pattern=base-v(\d+\.\d+),group=1
type=match,pattern=base-v(\d+\.\d+\.\d+),group=1
- name: Build and push
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile.base
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Build and Push Base Image permissions: contents: read # 基础镜像(Dockerfile.base)独立构建,只在以下情况触发,避免日常改 app 时重复编译: # - 改动了 Dockerfile.base(push 到 master) # - 打 base-v* 形式的 tag 发布版本(如 base-v8.5.0) # - 手动触发 on: push: branches: - master paths: - "Dockerfile.base" - ".github/workflows/build-base.yml" tags: - "base-v*" workflow_dispatch: env: REGISTRY: docker.io IMAGE_NAME: talebook/talebook-base concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: docker: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: platforms: linux/amd64,linux/arm64,linux/arm/v7 - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v3 - name: Login to DockerHub uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # base-v8.5.0 -> 8 / 8.5 / 8.5.0;master push -> latest / master tags: | type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} type=raw,value=master,enable=${{ github.ref == 'refs/heads/master' }} type=match,pattern=base-v(\d+),group=1 type=match,pattern=base-v(\d+\.\d+),group=1 type=match,pattern=base-v(\d+\.\d+\.\d+),group=1 - name: Build and push uses: docker/build-push-action@v5 with: builder: ${{ steps.buildx.outputs.name }} context: . file: ./Dockerfile.base platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}
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.
5 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.