Skip to content
Latchkey

Build Docker workflow (gnmyt/Nexterm)

The Build Docker workflow from gnmyt/Nexterm, 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: gnmyt/Nexterm.github/workflows/build-docker.ymlLicense MITView source

What it does

This is the Build Docker workflow from the gnmyt/Nexterm 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: Build Docker

on:
  workflow_call:
    inputs:
      version:
        required: true
        type: string

jobs:
  build-components:
    name: "Docker ${{ matrix.slug }} (${{ matrix.platform_arch }})"
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        slug: [server, engine]
        platform_arch: [amd64, arm64]
        include:
          - platform_arch: amd64
            platform: linux/amd64
            runner: ubuntu-latest
          - platform_arch: arm64
            platform: linux/arm64
            runner: ubuntu-24.04-arm
          - slug: server
            image_name: nexterm/server
            dockerfile: Dockerfile.server
          - slug: engine
            image_name: nexterm/engine
            dockerfile: Dockerfile.engine

    steps:
      - name: Checkout project
        uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ matrix.image_name }}

      - name: Build and push by digest
        id: build
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ${{ matrix.dockerfile }}
          platforms: ${{ matrix.platform }}
          labels: ${{ steps.meta.outputs.labels }}
          build-args: |
            VERSION=${{ inputs.version }}
          outputs: type=image,name=${{ matrix.image_name }},push-by-digest=true,name-canonical=true,push=true
          cache-from: type=gha,scope=${{ matrix.slug }}-${{ matrix.platform_arch }}
          cache-to: type=gha,mode=max,scope=${{ matrix.slug }}-${{ matrix.platform_arch }}

      - name: Export digest
        run: |
          mkdir -p ${{ runner.temp }}/digests/${{ matrix.slug }}
          digest="${{ steps.build.outputs.digest }}"
          touch "${{ runner.temp }}/digests/${{ matrix.slug }}/${digest#sha256:}"

      - name: Upload digest
        uses: actions/upload-artifact@v4
        with:
          name: digests-${{ matrix.slug }}-${{ matrix.platform_arch }}
          path: ${{ runner.temp }}/digests/${{ matrix.slug }}/
          if-no-files-found: error
          retention-days: 1

  merge-components:
    name: "Merge Manifests (${{ matrix.slug }})"
    runs-on: ubuntu-latest
    needs: build-components
    strategy:
      matrix:
        include:
          - image: nexterm/server
            slug: server
          - image: nexterm/engine
            slug: engine

    steps:
      - name: Download digests
        uses: actions/download-artifact@v4
        with:
          path: ${{ runner.temp }}/digests/${{ matrix.slug }}
          pattern: digests-${{ matrix.slug }}-*
          merge-multiple: true

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Create manifest list and push
        run: |
          docker buildx imagetools create \
            -t ${{ matrix.image }}:latest \
            -t ${{ matrix.image }}:${{ inputs.version }} \
            $(printf '${{ matrix.image }}@sha256:%s ' $(ls "${{ runner.temp }}/digests/${{ matrix.slug }}"))

  build-aio:
    name: "Docker aio (${{ matrix.platform_arch }})"
    runs-on: ${{ matrix.runner }}
    needs: merge-components
    strategy:
      fail-fast: false
      matrix:
        platform_arch: [amd64, arm64]
        include:
          - platform_arch: amd64
            platform: linux/amd64
            runner: ubuntu-latest
          - platform_arch: arm64
            platform: linux/arm64
            runner: ubuntu-24.04-arm

    steps:
      - name: Checkout project
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: nexterm/aio

      - name: Build and push by digest
        id: build
        uses: docker/build-push-action@v6
        with:
          context: .
          file: Dockerfile
          platforms: ${{ matrix.platform }}
          labels: ${{ steps.meta.outputs.labels }}
          build-args: |
            SERVER_IMAGE=nexterm/server:${{ inputs.version }}
            ENGINE_IMAGE=nexterm/engine:${{ inputs.version }}
          outputs: type=image,name=nexterm/aio,push-by-digest=true,name-canonical=true,push=true
          cache-from: type=gha,scope=aio-${{ matrix.platform_arch }}
          cache-to: type=gha,mode=max,scope=aio-${{ matrix.platform_arch }}

      - name: Export digest
        run: |
          mkdir -p ${{ runner.temp }}/digests/aio
          digest="${{ steps.build.outputs.digest }}"
          touch "${{ runner.temp }}/digests/aio/${digest#sha256:}"

      - name: Upload digest
        uses: actions/upload-artifact@v4
        with:
          name: digests-aio-${{ matrix.platform_arch }}
          path: ${{ runner.temp }}/digests/aio/
          if-no-files-found: error
          retention-days: 1

  merge-aio:
    name: "Merge Manifests (aio)"
    runs-on: ubuntu-latest
    needs: build-aio

    steps:
      - name: Download digests
        uses: actions/download-artifact@v4
        with:
          path: ${{ runner.temp }}/digests/aio
          pattern: digests-aio-*
          merge-multiple: true

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Create manifest list and push
        run: |
          docker buildx imagetools create \
            -t nexterm/aio:latest \
            -t nexterm/aio:${{ inputs.version }} \
            $(printf 'nexterm/aio@sha256:%s ' $(ls "${{ runner.temp }}/digests/aio"))

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Build Docker
 
on:
  workflow_call:
    inputs:
      version:
        required: true
        type: string
 
jobs:
  build-components:
    timeout-minutes: 30
    name: "Docker ${{ matrix.slug }} (${{ matrix.platform_arch }})"
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        slug: [server, engine]
        platform_arch: [amd64, arm64]
        include:
          - platform_arch: amd64
            platform: linux/amd64
            runner: ubuntu-latest
          - platform_arch: arm64
            platform: linux/arm64
            runner: ubuntu-24.04-arm
          - slug: server
            image_name: nexterm/server
            dockerfile: Dockerfile.server
          - slug: engine
            image_name: nexterm/engine
            dockerfile: Dockerfile.engine
 
    steps:
      - name: Checkout project
        uses: actions/checkout@v4
        with:
          submodules: recursive
 
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
 
      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
 
      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ matrix.image_name }}
 
      - name: Build and push by digest
        id: build
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ${{ matrix.dockerfile }}
          platforms: ${{ matrix.platform }}
          labels: ${{ steps.meta.outputs.labels }}
          build-args: |
            VERSION=${{ inputs.version }}
          outputs: type=image,name=${{ matrix.image_name }},push-by-digest=true,name-canonical=true,push=true
          cache-from: type=gha,scope=${{ matrix.slug }}-${{ matrix.platform_arch }}
          cache-to: type=gha,mode=max,scope=${{ matrix.slug }}-${{ matrix.platform_arch }}
 
      - name: Export digest
        run: |
          mkdir -p ${{ runner.temp }}/digests/${{ matrix.slug }}
          digest="${{ steps.build.outputs.digest }}"
          touch "${{ runner.temp }}/digests/${{ matrix.slug }}/${digest#sha256:}"
 
      - name: Upload digest
        uses: actions/upload-artifact@v4
        with:
          name: digests-${{ matrix.slug }}-${{ matrix.platform_arch }}
          path: ${{ runner.temp }}/digests/${{ matrix.slug }}/
          if-no-files-found: error
          retention-days: 1
 
  merge-components:
    timeout-minutes: 30
    name: "Merge Manifests (${{ matrix.slug }})"
    runs-on: latchkey-small
    needs: build-components
    strategy:
      matrix:
        include:
          - image: nexterm/server
            slug: server
          - image: nexterm/engine
            slug: engine
 
    steps:
      - name: Download digests
        uses: actions/download-artifact@v4
        with:
          path: ${{ runner.temp }}/digests/${{ matrix.slug }}
          pattern: digests-${{ matrix.slug }}-*
          merge-multiple: true
 
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
 
      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
 
      - name: Create manifest list and push
        run: |
          docker buildx imagetools create \
            -t ${{ matrix.image }}:latest \
            -t ${{ matrix.image }}:${{ inputs.version }} \
            $(printf '${{ matrix.image }}@sha256:%s ' $(ls "${{ runner.temp }}/digests/${{ matrix.slug }}"))
 
  build-aio:
    timeout-minutes: 30
    name: "Docker aio (${{ matrix.platform_arch }})"
    runs-on: ${{ matrix.runner }}
    needs: merge-components
    strategy:
      fail-fast: false
      matrix:
        platform_arch: [amd64, arm64]
        include:
          - platform_arch: amd64
            platform: linux/amd64
            runner: ubuntu-latest
          - platform_arch: arm64
            platform: linux/arm64
            runner: ubuntu-24.04-arm
 
    steps:
      - name: Checkout project
        uses: actions/checkout@v4
 
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
 
      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
 
      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: nexterm/aio
 
      - name: Build and push by digest
        id: build
        uses: docker/build-push-action@v6
        with:
          context: .
          file: Dockerfile
          platforms: ${{ matrix.platform }}
          labels: ${{ steps.meta.outputs.labels }}
          build-args: |
            SERVER_IMAGE=nexterm/server:${{ inputs.version }}
            ENGINE_IMAGE=nexterm/engine:${{ inputs.version }}
          outputs: type=image,name=nexterm/aio,push-by-digest=true,name-canonical=true,push=true
          cache-from: type=gha,scope=aio-${{ matrix.platform_arch }}
          cache-to: type=gha,mode=max,scope=aio-${{ matrix.platform_arch }}
 
      - name: Export digest
        run: |
          mkdir -p ${{ runner.temp }}/digests/aio
          digest="${{ steps.build.outputs.digest }}"
          touch "${{ runner.temp }}/digests/aio/${digest#sha256:}"
 
      - name: Upload digest
        uses: actions/upload-artifact@v4
        with:
          name: digests-aio-${{ matrix.platform_arch }}
          path: ${{ runner.temp }}/digests/aio/
          if-no-files-found: error
          retention-days: 1
 
  merge-aio:
    timeout-minutes: 30
    name: "Merge Manifests (aio)"
    runs-on: latchkey-small
    needs: build-aio
 
    steps:
      - name: Download digests
        uses: actions/download-artifact@v4
        with:
          path: ${{ runner.temp }}/digests/aio
          pattern: digests-aio-*
          merge-multiple: true
 
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
 
      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
 
      - name: Create manifest list and push
        run: |
          docker buildx imagetools create \
            -t nexterm/aio:latest \
            -t nexterm/aio:${{ inputs.version }} \
            $(printf 'nexterm/aio@sha256:%s ' $(ls "${{ runner.temp }}/digests/aio"))
 

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 4 jobs (8 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow