Optimize GitHub Actions CI/CD pipeline (#252)

- Switch Docker layer cache from local filesystem to GHA native cache
  (type=gha), eliminating the cache-size workaround hack
- Consolidate cancel-previous-runs into a single dedicated job to
  prevent race conditions from concurrent API calls
- Remove DATABASE_URL build-arg that was never consumed by the Dockerfile
- Add post-deploy health check that fails the job and prints logs if any
  container exits unexpectedly
- Add .nvmrc and use node-version-file instead of hardcoded node-version: 20

Fixes #249

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Chris Parsons 2026-04-01 00:59:21 -07:00 committed by GitHub
parent 383315d0c3
commit 6df66e9cc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 40 deletions

View file

@ -10,8 +10,15 @@ permissions:
contents: read
jobs:
cancel:
name: 🛑 Cancel Previous Runs
runs-on: ubuntu-latest
steps:
- uses: styfle/cancel-workflow-action@0.12.1
test:
name: 🧪 Test
needs: [cancel]
runs-on: ubuntu-latest
services:
@ -30,16 +37,13 @@ jobs:
- 5432:5432
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: '.nvmrc'
cache: 'npm'
- name: 📥 Install dependencies
@ -53,18 +57,16 @@ jobs:
typecheck:
name: ʦ TypeScript
needs: [cancel]
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: '.nvmrc'
cache: 'npm'
- name: 📥 Install dependencies
@ -75,18 +77,16 @@ jobs:
lint:
name: 🔍 Lint
needs: [cancel]
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: '.nvmrc'
cache: 'npm'
- name: 📥 Install dependencies
@ -102,24 +102,12 @@ jobs:
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
- name: 🐳 Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Setup cache
- name: ⚡️ Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: 🔓 Login to Container Registry
uses: docker/login-action@v3
with:
@ -133,26 +121,14 @@ jobs:
context: .
push: true
tags: ${{ vars.CONTAINER_REGISTRY }}/brackt:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
build-args: |
DATABASE_URL=${{ secrets.PROD_DATABASE_URL }}
# This ugly bit is necessary if you don't want your cache to grow forever
# till it hits GitHub's limit of 10GB.
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: 🚚 Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
name: 🚀 Deploy
runs-on: ubuntu-latest
needs: [build]
# only deploy main/dev branch on pushes
# only deploy main branch on pushes
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
steps:
@ -173,3 +149,9 @@ jobs:
cd brackt
docker compose pull
docker compose up -d
sleep 10
if docker compose ps | grep -qE "Exit|exited"; then
echo "One or more containers failed to start:"
docker compose logs --tail=50
exit 1
fi

1
.nvmrc Normal file
View file

@ -0,0 +1 @@
20