Skip to content
Latchkey

Build and Push Docker image workflow (GerevAI/gerev)

The Build and Push Docker image workflow from GerevAI/gerev, 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: GerevAI/gerev.github/workflows/deploy.yamlLicense MITView source

What it does

This is the Build and Push Docker image workflow from the GerevAI/gerev 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 and Push Docker image

on:
# Build from input box
  workflow_dispatch:
    inputs:
      version:
        description: 'Version'
        required: true
      push:
        description: 'Push to Docker Hub'
        required: true
        type: boolean
        default: true

env:
  VERSION: ${{ github.event.inputs.version }}
  PUSH: ${{ github.event.inputs.push }}

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: 🐷 TruffleHog OSS
        uses: trufflesecurity/trufflehog@v3.29.1
        with:
          path: ./
          base: ${{ github.event.repository.default_branch }}
          head: HEAD
          extra_args: --debug --only-verified


      # Use Caching for npm
      - name: Cache node modules
        uses: actions/cache@v2
        with:
          working-directory: ./ui
          path: |
            node_modules
          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-npm-

      - name: Install npm dependencies and build UI
        run: |
          cd ui
          npm install
          npm run build
      
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

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

      - name: Build and push
        uses: docker/build-push-action@v4
        env:
          VERSION: ${{ env.VERSION }}
        with:
          context: .
          file: ./Dockerfile
          platforms: linux/amd64,linux/arm64
          push: ${{ env.PUSH == 'true' }}
          tags: |
            gerev/gerev:${{ env.VERSION }}
            gerev/gerev:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max

The same workflow, on Latchkey

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

name: Build and Push Docker image
 
on:
# Build from input box
  workflow_dispatch:
    inputs:
      version:
        description: 'Version'
        required: true
      push:
        description: 'Push to Docker Hub'
        required: true
        type: boolean
        default: true
 
env:
  VERSION: ${{ github.event.inputs.version }}
  PUSH: ${{ github.event.inputs.push }}
 
jobs:
  build-and-push:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
 
      - name: 🐷 TruffleHog OSS
        uses: trufflesecurity/trufflehog@v3.29.1
        with:
          path: ./
          base: ${{ github.event.repository.default_branch }}
          head: HEAD
          extra_args: --debug --only-verified
 
 
      # Use Caching for npm
      - name: Cache node modules
        uses: actions/cache@v2
        with:
          working-directory: ./ui
          path: |
            node_modules
          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-npm-
 
      - name: Install npm dependencies and build UI
        run: |
          cd ui
          npm install
          npm run build
      
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
 
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2
 
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
 
      - name: Build and push
        uses: docker/build-push-action@v4
        env:
          VERSION: ${{ env.VERSION }}
        with:
          context: .
          file: ./Dockerfile
          platforms: linux/amd64,linux/arm64
          push: ${{ env.PUSH == 'true' }}
          tags: |
            gerev/gerev:${{ env.VERSION }}
            gerev/gerev:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max

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