Build and push to Docker Hub workflow (wassim249/fastapi-langgraph-agent-production-ready-template)
The Build and push to Docker Hub workflow from wassim249/fastapi-langgraph-agent-production-ready-template, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Build and push to Docker Hub workflow from the wassim249/fastapi-langgraph-agent-production-ready-template 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: Build and push to Docker Hub
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build-and-push:
name: Build and push to Docker Hub
runs-on: ubuntu-latest
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install utilities
run: |
sudo apt-get update
sudo apt-get install -y make
- name: Sanitize repository name
id: sanitize
run: |
REPO_NAME=$(echo "${{ github.event.repository.name }}" | sed 's/^\///' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g')
echo "REPO_NAME=${REPO_NAME}" >> "$GITHUB_ENV"
- name: Build Image
run: |
make docker-build ENV=production
- name: Log in to Docker Hub
if: ${{ github.event_name == 'push' && env.DOCKER_USERNAME != '' }}
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Push Image
if: ${{ github.event_name == 'push' && env.DOCKER_USERNAME != '' }}
run: |
docker tag fastapi-langgraph-template:production ${{ secrets.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:production
docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:production
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Build and push to Docker Hub on: push: branches: - master pull_request: branches: - master concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build-and-push: timeout-minutes: 30 name: Build and push to Docker Hub runs-on: latchkey-small env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Install utilities run: | sudo apt-get update sudo apt-get install -y make - name: Sanitize repository name id: sanitize run: | REPO_NAME=$(echo "${{ github.event.repository.name }}" | sed 's/^\///' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g') echo "REPO_NAME=${REPO_NAME}" >> "$GITHUB_ENV" - name: Build Image run: | make docker-build ENV=production - name: Log in to Docker Hub if: ${{ github.event_name == 'push' && env.DOCKER_USERNAME != '' }} run: | echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin - name: Push Image if: ${{ github.event_name == 'push' && env.DOCKER_USERNAME != '' }} run: | docker tag fastapi-langgraph-template:production ${{ secrets.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:production docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:production
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.
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.