Deploy workflow (tiangolo/uvicorn-gunicorn-fastapi-docker)
The Deploy workflow from tiangolo/uvicorn-gunicorn-fastapi-docker, 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 Deploy workflow from the tiangolo/uvicorn-gunicorn-fastapi-docker 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: Deploy
on:
push:
branches:
- master
workflow_dispatch:
schedule:
# cron every week on monday
- cron: "0 0 * * 1"
permissions: {}
jobs:
deploy:
permissions:
contents: read
strategy:
matrix:
image:
- name: latest
python_version: "3.11"
- name: python3.11
python_version: "3.11"
- name: python3.10
python_version: "3.10"
- name: python3.11-slim
python_version: "3.11"
- name: python3.10-slim
python_version: "3.10"
fail-fast: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
persist-credentials: false
- name: Set Dockerfile name
if: matrix.image.name != 'latest'
run: echo "DOCKERFILE_NAME=${{ matrix.image.name }}" >> $GITHUB_ENV
- name: Set Dockerfile name latest
if: matrix.image.name == 'latest'
run: echo "DOCKERFILE_NAME=python${{ matrix.image.python_version }}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: Login to DockerHub
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get date for tags
run: echo "DATE_TAG=$(date -I)" >> "$GITHUB_ENV"
- name: Build and push
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
push: true
platforms: linux/amd64,linux/arm64
tags: |
tiangolo/uvicorn-gunicorn-fastapi:${{ matrix.image.name }}
tiangolo/uvicorn-gunicorn-fastapi:${{ matrix.image.name }}-${{ env.DATE_TAG }}
context: ./docker-images/
file: ./docker-images/${{ env.DOCKERFILE_NAME }}.dockerfile
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@1b9a80c056b620d92cedb9d9b5a223409c68ddfa # v5
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: tiangolo/uvicorn-gunicorn-fastapi
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Deploy on: push: branches: - master workflow_dispatch: schedule: # cron every week on monday - cron: "0 0 * * 1" permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: deploy: timeout-minutes: 30 permissions: contents: read strategy: matrix: image: - name: latest python_version: "3.11" - name: python3.11 python_version: "3.11" - name: python3.10 python_version: "3.10" - name: python3.11-slim python_version: "3.11" - name: python3.10-slim python_version: "3.10" fail-fast: true runs-on: latchkey-small steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Set Dockerfile name if: matrix.image.name != 'latest' run: echo "DOCKERFILE_NAME=${{ matrix.image.name }}" >> $GITHUB_ENV - name: Set Dockerfile name latest if: matrix.image.name == 'latest' run: echo "DOCKERFILE_NAME=python${{ matrix.image.python_version }}" >> $GITHUB_ENV - name: Set up Docker Buildx uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 - name: Login to DockerHub uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Get date for tags run: echo "DATE_TAG=$(date -I)" >> "$GITHUB_ENV" - name: Build and push uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0 with: push: true platforms: linux/amd64,linux/arm64 tags: | tiangolo/uvicorn-gunicorn-fastapi:${{ matrix.image.name }} tiangolo/uvicorn-gunicorn-fastapi:${{ matrix.image.name }}-${{ env.DATE_TAG }} context: ./docker-images/ file: ./docker-images/${{ env.DOCKERFILE_NAME }}.dockerfile - name: Docker Hub Description uses: peter-evans/dockerhub-description@1b9a80c056b620d92cedb9d9b5a223409c68ddfa # v5 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} repository: tiangolo/uvicorn-gunicorn-fastapi
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:
- Container pulls and builds
This workflow runs 1 job (5 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.