Publish API-only Docker image workflow (aigc-apps/PAI-RAG)
The Publish API-only Docker image workflow from aigc-apps/PAI-RAG, 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 Publish API-only Docker image workflow from the aigc-apps/PAI-RAG 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
name: Publish API-only Docker image
# Configures this workflow to run on manual dispatch or push to specific branches
on:
workflow_dispatch:
inputs:
push_to_prod:
description: 'Push to production registry'
required: false
default: false
type: boolean
push:
branches: ["feature"]
paths:
- 'backend/**'
- 'integrations/**'
- 'resources/**'
- 'alembic/**'
- 'alembic.ini'
- 'scripts/**'
- 'Dockerfile.api'
- '**/pyproject.toml'
- '**/poetry.lock'
- '.github/workflows/docker-api.yml'
# Environment variables for Container registry
env:
API_REGISTRY: mybigpai-public-registry.cn-beijing.cr.aliyuncs.com
jobs:
build-and-push-api-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check disk space
run: df . -h
- name: Free disk space
run: |
sudo docker rmi $(docker image ls -aq) >/dev/null 2>&1 || true
sudo rm -rf \
/usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
/usr/lib/jvm || true
df . -h
- name: Extract version
run: |
pip install poetry
CURRENT_TIME="`date +%Y%m%d%H%M%S`"
echo "API_VERSION_TAG=$CURRENT_TIME" >> $GITHUB_ENV
- name: Login to ACR Hangzhou region
uses: docker/login-action@v1
with:
registry: ${{ env.API_REGISTRY }}
username: ${{ secrets.ACR_USER }}
password: ${{ secrets.ACR_PUBLIC_PASSWORD }}
- name: Build and push API-only image
env:
API_IMAGE_TAG: ${{ env.API_VERSION_TAG }}
run: |
# Build using Dockerfile.api
docker build -f Dockerfile.api -t ${{ env.API_REGISTRY }}/mybigpai/pairag-api:$API_IMAGE_TAG .
# Always push to test registry
docker push ${{ env.API_REGISTRY }}/mybigpai/pairag-api:$API_IMAGE_TAG
- name: Free disk space
run: |
docker image prune --filter "until=168h" --force -a
docker builder prune --filter "until=24h" -f
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Publish API-only Docker image # Configures this workflow to run on manual dispatch or push to specific branches on: workflow_dispatch: inputs: push_to_prod: description: 'Push to production registry' required: false default: false type: boolean push: branches: ["feature"] paths: - 'backend/**' - 'integrations/**' - 'resources/**' - 'alembic/**' - 'alembic.ini' - 'scripts/**' - 'Dockerfile.api' - '**/pyproject.toml' - '**/poetry.lock' - '.github/workflows/docker-api.yml' # Environment variables for Container registry env: API_REGISTRY: mybigpai-public-registry.cn-beijing.cr.aliyuncs.com concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build-and-push-api-image: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout repository uses: actions/checkout@v4 - name: Check disk space run: df . -h - name: Free disk space run: | sudo docker rmi $(docker image ls -aq) >/dev/null 2>&1 || true sudo rm -rf \ /usr/share/dotnet /usr/local/lib/android /opt/ghc \ /usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \ /usr/lib/jvm || true df . -h - name: Extract version run: | pip install poetry CURRENT_TIME="`date +%Y%m%d%H%M%S`" echo "API_VERSION_TAG=$CURRENT_TIME" >> $GITHUB_ENV - name: Login to ACR Hangzhou region uses: docker/login-action@v1 with: registry: ${{ env.API_REGISTRY }} username: ${{ secrets.ACR_USER }} password: ${{ secrets.ACR_PUBLIC_PASSWORD }} - name: Build and push API-only image env: API_IMAGE_TAG: ${{ env.API_VERSION_TAG }} run: | # Build using Dockerfile.api docker build -f Dockerfile.api -t ${{ env.API_REGISTRY }}/mybigpai/pairag-api:$API_IMAGE_TAG . # Always push to test registry docker push ${{ env.API_REGISTRY }}/mybigpai/pairag-api:$API_IMAGE_TAG - name: Free disk space run: | docker image prune --filter "until=168h" --force -a docker builder prune --filter "until=24h" -f
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.
1 third-party action is referenced by a movable tag. Pin it 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.