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:
parent
383315d0c3
commit
6df66e9cc6
2 changed files with 23 additions and 40 deletions
62
.github/workflows/deploy.yml
vendored
62
.github/workflows/deploy.yml
vendored
|
|
@ -10,10 +10,17 @@ permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
cancel:
|
||||||
|
name: 🛑 Cancel Previous Runs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: styfle/cancel-workflow-action@0.12.1
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: 🧪 Test
|
name: 🧪 Test
|
||||||
|
needs: [cancel]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:15
|
image: postgres:15
|
||||||
|
|
@ -30,16 +37,13 @@ jobs:
|
||||||
- 5432:5432
|
- 5432:5432
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 🛑 Cancel Previous Runs
|
|
||||||
uses: styfle/cancel-workflow-action@0.12.1
|
|
||||||
|
|
||||||
- name: ⬇️ Checkout repo
|
- name: ⬇️ Checkout repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: ⎔ Setup node
|
- name: ⎔ Setup node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version-file: '.nvmrc'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
- name: 📥 Install dependencies
|
- name: 📥 Install dependencies
|
||||||
|
|
@ -53,18 +57,16 @@ jobs:
|
||||||
|
|
||||||
typecheck:
|
typecheck:
|
||||||
name: ʦ TypeScript
|
name: ʦ TypeScript
|
||||||
|
needs: [cancel]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: 🛑 Cancel Previous Runs
|
|
||||||
uses: styfle/cancel-workflow-action@0.12.1
|
|
||||||
|
|
||||||
- name: ⬇️ Checkout repo
|
- name: ⬇️ Checkout repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: ⎔ Setup node
|
- name: ⎔ Setup node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version-file: '.nvmrc'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
- name: 📥 Install dependencies
|
- name: 📥 Install dependencies
|
||||||
|
|
@ -75,18 +77,16 @@ jobs:
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
name: 🔍 Lint
|
name: 🔍 Lint
|
||||||
|
needs: [cancel]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: 🛑 Cancel Previous Runs
|
|
||||||
uses: styfle/cancel-workflow-action@0.12.1
|
|
||||||
|
|
||||||
- name: ⬇️ Checkout repo
|
- name: ⬇️ Checkout repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: ⎔ Setup node
|
- name: ⎔ Setup node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version-file: '.nvmrc'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
- name: 📥 Install dependencies
|
- name: 📥 Install dependencies
|
||||||
|
|
@ -102,24 +102,12 @@ jobs:
|
||||||
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
|
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: 🛑 Cancel Previous Runs
|
|
||||||
uses: styfle/cancel-workflow-action@0.12.1
|
|
||||||
|
|
||||||
- name: ⬇️ Checkout repo
|
- name: ⬇️ Checkout repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: 🐳 Set up Docker Buildx
|
- name: 🐳 Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
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
|
- name: 🔓 Login to Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
|
|
@ -133,26 +121,14 @@ jobs:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ vars.CONTAINER_REGISTRY }}/brackt:latest
|
tags: ${{ vars.CONTAINER_REGISTRY }}/brackt:latest
|
||||||
cache-from: type=local,src=/tmp/.buildx-cache
|
cache-from: type=gha
|
||||||
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
|
cache-to: type=gha,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
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
name: 🚀 Deploy
|
name: 🚀 Deploy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [build]
|
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' }}
|
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
@ -173,3 +149,9 @@ jobs:
|
||||||
cd brackt
|
cd brackt
|
||||||
docker compose pull
|
docker compose pull
|
||||||
docker compose up -d
|
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
1
.nvmrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
20
|
||||||
Loading…
Add table
Reference in a new issue