brackt/.forgejo/workflows/deploy.yml
chrisp 08474631c1
Some checks failed
🚀 Deploy / 🧪 Test (push) Failing after 1m34s
🚀 Deploy / ʦ TypeScript (push) Successful in 1m23s
🚀 Deploy / 🔍 Lint (push) Successful in 49s
🚀 Deploy / 🐳 Build (push) Has been skipped
🚀 Deploy / 🚀 Deploy (push) Has been skipped
Optimize CI build pipeline (~15 min → ~3-5 min) (#59)
## Summary

- **Dockerfile layer caching**: `development-dependencies-env` now copies only `package.json`/`package-lock.json` before `npm ci` (was `COPY . /app`), so the npm install layer is cached on every code-only commit instead of rebuilt from scratch
- **Skip QEMU**: `platforms: linux/amd64` added to `build-push-action`, cutting `setup-buildx-action` from ~5 min to ~30 sec
- **npm cache in CI jobs**: Manual `actions/cache@v3` blocks (copy-pasted 3×) replaced with `actions/setup-node@v4` + `cache: 'npm'`, which handles path/key/restore automatically and pins Node 20 explicitly
- **Harden `.npmrc`**: Switched from `COPY .npmrc` to `--mount=type=secret,id=npmrc` in both `npm ci` stages — the file is available during install but never written into a Docker layer, so it cannot leak through the registry build cache regardless of future contents

## Expected timing

| Step | Before | After (code change) |
|---|---|---|
| Setup buildx | ~5 min | ~30 sec |
| Build + push | ~5 min | ~1-2 min |
| Deploy (docker pull) | ~5 min | ~1-2 min |
| **Total** | **~15 min** | **~3-5 min** |

## Test plan

- [ ] Push a code-only commit to main — confirm `setup-buildx-action` logs ~30s (no QEMU), Docker build shows `CACHED` for npm install layers, build+push completes in ~1-2 min
- [ ] Check deploy job — `docker compose pull` should show most layers as `Already exists`
- [ ] Push a commit that changes `package.json` — confirm npm layer correctly re-runs (not cached)
- [ ] Confirm deployed app is functional

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com>
Reviewed-on: #59
2026-05-31 04:35:05 +00:00

140 lines
4.7 KiB
YAML

name: 🚀 Deploy
on:
push:
branches:
- main
pull_request: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
permissions:
contents: read
jobs:
test:
name: 🧪 Test
runs-on: ubuntu-latest
timeout-minutes: 20
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: brackt_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: ⬇️ Checkout repo
uses: https://github.com/actions/checkout@v4
- name: 📥 Install dependencies
run: npm ci
- name: 🧪 Run unit tests
run: npm run test:run
env:
DATABASE_URL: postgresql://test:test@postgres:5432/brackt_test
NODE_OPTIONS: --max-old-space-size=4096
typecheck:
name: ʦ TypeScript
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: ⬇️ Checkout repo
uses: https://github.com/actions/checkout@v4
- name: 📥 Install dependencies
run: npm ci
- name: 🔎 Type check
run: npm run typecheck
lint:
name: 🔍 Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: ⬇️ Checkout repo
uses: https://github.com/actions/checkout@v4
- name: 📥 Install dependencies
run: npm ci
- name: 🔍 Lint (oxlint)
run: npm run lint
build:
name: 🐳 Build
needs: [test, typecheck, lint]
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: ⬇️ Checkout repo
uses: https://github.com/actions/checkout@v4
- name: 🐳 Install Docker CLI
run: apt-get update -qq && apt-get install -y -qq docker.io
- name: 🐳 Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
- name: 🔓 Login to Container Registry
uses: https://github.com/docker/login-action@v3
with:
registry: ${{ vars.CONTAINER_REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: 🗄️ Build and Push to Container Registry
uses: https://github.com/docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ vars.CONTAINER_REGISTRY }}/brackt:latest
cache-from: type=registry,ref=${{ vars.CONTAINER_REGISTRY }}/brackt:buildcache
cache-to: type=registry,ref=${{ vars.CONTAINER_REGISTRY }}/brackt:buildcache,mode=max
secret-files: |
npmrc=./.npmrc
deploy:
name: 🚀 Deploy
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [build]
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
steps:
- name: 🚀 Deploy app to server
uses: https://github.com/appleboy/ssh-action@v1.0.3
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
CONTAINER_REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
with:
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
envs: REGISTRY_USERNAME,REGISTRY_PASSWORD,CONTAINER_REGISTRY
script: |
set -e
docker login $CONTAINER_REGISTRY -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD
cd brackt
docker compose pull
if ! docker compose up --no-deps migrate; then
echo "Migration failed:"
docker compose logs migrate
exit 1
fi
docker compose up -d --remove-orphans