Build & Push SwaggerUI Docker image workflow (swagger-api/swagger-ui)
The Build & Push SwaggerUI Docker image workflow from swagger-api/swagger-ui, explained and optimized by Latchkey.
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.
What it does
This is the Build & Push SwaggerUI Docker image workflow from the swagger-api/swagger-ui 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
name: Build & Push SwaggerUI Docker image
on:
workflow_run:
workflows: ["Release SwaggerUI"]
types:
- completed
branches: [master]
jobs:
build-push:
if: github.event.workflow_run.conclusion == 'success'
name: Build & Push SwaggerUI Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci
- name: Build SwaggerUI
run: npm run build
- name: Determine released version
uses: actions/github-script@v9
with:
script: |
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "released-version"
})[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/released-version.zip', Buffer.from(download.data));
- run: |
unzip released-version.zip
RELEASED_VERSION=$(cat released-version.txt)
echo "RELEASED_VERSION=$RELEASED_VERSION" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to DockerHub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_SB_USERNAME }}
password: ${{ secrets.DOCKERHUB_SB_PASSWORD }}
- name: Build docker image and push
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm/v6,linux/arm64,linux/386,linux/ppc64le
provenance: false
tags: swaggerapi/swagger-ui:latest,swaggerapi/swagger-ui:v${{ env.RELEASED_VERSION }}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Build & Push SwaggerUI Docker image on: workflow_run: workflows: ["Release SwaggerUI"] types: - completed branches: [master] jobs: build-push: timeout-minutes: 30 if: github.event.workflow_run.conclusion == 'success' name: Build & Push SwaggerUI Docker image runs-on: latchkey-small steps: - uses: actions/checkout@v7 - name: Use Node.js uses: actions/setup-node@v6 with: node-version-file: .nvmrc cache: npm cache-dependency-path: package-lock.json - name: Install dependencies run: npm ci - name: Build SwaggerUI run: npm run build - name: Determine released version uses: actions/github-script@v9 with: script: | const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ owner: context.repo.owner, repo: context.repo.repo, run_id: context.payload.workflow_run.id, }); const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { return artifact.name == "released-version" })[0]; const download = await github.rest.actions.downloadArtifact({ owner: context.repo.owner, repo: context.repo.repo, artifact_id: matchArtifact.id, archive_format: 'zip', }); const fs = require('fs'); fs.writeFileSync('${{github.workspace}}/released-version.zip', Buffer.from(download.data)); - run: | unzip released-version.zip RELEASED_VERSION=$(cat released-version.txt) echo "RELEASED_VERSION=$RELEASED_VERSION" >> $GITHUB_ENV - name: Set up QEMU uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Log in to DockerHub uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_SB_USERNAME }} password: ${{ secrets.DOCKERHUB_SB_PASSWORD }} - name: Build docker image and push uses: docker/build-push-action@v7 with: context: . push: true platforms: linux/amd64,linux/arm/v6,linux/arm64,linux/386,linux/ppc64le provenance: false tags: swaggerapi/swagger-ui:latest,swaggerapi/swagger-ui:v${{ env.RELEASED_VERSION }}
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. - Add a job timeout so a hung step cannot burn hours of runner time.
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:
- Dependency installs
- 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.