Skip to content
Latchkey

Publish Docker image workflow (Superalgos/Superalgos)

The Publish Docker image workflow from Superalgos/Superalgos, explained and optimized by Latchkey.

C

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.

Grade your own workflow free or run it on Latchkey →
Source: Superalgos/Superalgos.github/workflows/docker.ymlLicense Apache-2.0View source

What it does

This is the Publish Docker image workflow from the Superalgos/Superalgos repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Publish Docker image

on: 
  push:
    branches:
      - master
      - develop
  release:
    types:
      - published
      - created
      - edited

jobs:
  publish:
    if: github.repository == 'superalgos/superalgos'
    name: Publish Image
    runs-on: ubuntu-latest
    steps:
    - id: repository
      uses: ASzc/change-string-case-action@v1
      with:
        string: "${{ github.repository }}"
    - uses: actions/checkout@v2
    - name: Preparation
      id: prep
      run: |
        REGISTRY="ghcr.io"
        IMAGE="${REGISTRY}/${{ steps.repository.outputs.lowercase }}"
        TAGS="${IMAGE}:${{ github.sha }},${IMAGE}:latest"
        REF=${GITHUB_REF,,}
        PREFIX="$(dirname $REF)"
        SUFFIX="$(basename $REF)"
        if [[ $PREFIX = "refs/heads" ]]; then
          TAGS="${TAGS},${IMAGE}:${SUFFIX}"
        elif [[ $PREFIX = "refs/tags" ]]; then
          RELEASE=${SUFFIX#"superalgos-"}
          TAGS="${TAGS},${IMAGE}:${RELEASE}"
        fi
        echo ::set-output name=tags::${TAGS}
    - name: Login in to registry
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ github.token }}
    - name: Set up QEMU
      uses: docker/setup-qemu-action@v1
    - name: Set up Docker Buildx
      id: buildx
      uses: docker/setup-buildx-action@v1
    - name: Available platforms
      run: echo ${{ steps.buildx.outputs.platforms }}
    - name: Push to registry
      uses: docker/build-push-action@v2
      with:
        push: true
        file: ./Docker/Dockerfile
        tags: ${{ steps.prep.outputs.tags }}
        platforms: linux/amd64,linux/arm64,linux/arm/v7

The same workflow, on Latchkey

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

name: Publish Docker image
 
on: 
  push:
    branches:
      - master
      - develop
  release:
    types:
      - published
      - created
      - edited
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  publish:
    timeout-minutes: 30
    if: github.repository == 'superalgos/superalgos'
    name: Publish Image
    runs-on: latchkey-small
    steps:
    - id: repository
      uses: ASzc/change-string-case-action@v1
      with:
        string: "${{ github.repository }}"
    - uses: actions/checkout@v2
    - name: Preparation
      id: prep
      run: |
        REGISTRY="ghcr.io"
        IMAGE="${REGISTRY}/${{ steps.repository.outputs.lowercase }}"
        TAGS="${IMAGE}:${{ github.sha }},${IMAGE}:latest"
        REF=${GITHUB_REF,,}
        PREFIX="$(dirname $REF)"
        SUFFIX="$(basename $REF)"
        if [[ $PREFIX = "refs/heads" ]]; then
          TAGS="${TAGS},${IMAGE}:${SUFFIX}"
        elif [[ $PREFIX = "refs/tags" ]]; then
          RELEASE=${SUFFIX#"superalgos-"}
          TAGS="${TAGS},${IMAGE}:${RELEASE}"
        fi
        echo ::set-output name=tags::${TAGS}
    - name: Login in to registry
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ github.token }}
    - name: Set up QEMU
      uses: docker/setup-qemu-action@v1
    - name: Set up Docker Buildx
      id: buildx
      uses: docker/setup-buildx-action@v1
    - name: Available platforms
      run: echo ${{ steps.buildx.outputs.platforms }}
    - name: Push to registry
      uses: docker/build-push-action@v2
      with:
        push: true
        file: ./Docker/Dockerfile
        tags: ${{ steps.prep.outputs.tags }}
        platforms: linux/amd64,linux/arm64,linux/arm/v7
 

What changed

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:

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