Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ─── Database ────────────────────────────────────────────────────────────────
# PostgreSQL connection string used by Prisma.
# Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public
# Leave as-is for local Docker Compose (see docker-compose.yml).
DATABASE_URL=postgresql://vortex:vortex@localhost:5432/vortex?schema=public

# ─── Server ──────────────────────────────────────────────────────────────────
# Port the relay API + WebSocket feed listen on
PORT=4000
Expand Down
61 changes: 55 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,63 @@ jobs:
backend:
name: Backend (Nest)
runs-on: ubuntu-latest

# Spin up a PostgreSQL service container so Prisma can connect during the
# migrate step (migrate deploy requires a live DB).
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: vortex
POSTGRES_PASSWORD: vortex
POSTGRES_DB: vortex
ports:
- 5432:5432
# Wait until postgres is healthy before the steps run.
options: >-
--health-cmd="pg_isready -U vortex"
--health-interval=10s
--health-timeout=5s
--health-retries=5

env:
DATABASE_URL: postgresql://vortex:vortex@localhost:5432/vortex?schema=public

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install
- run: npm run lint
- run: npm run typecheck
- run: npm run build
- run: npm test
- run: npm run test:e2e
cache: npm

- name: Install dependencies
run: npm install

# ── Prisma ──────────────────────────────────────────────────────────────
- name: Validate Prisma schema
run: npm run db:validate

- name: Generate Prisma client
run: npm run db:generate

# Apply all pending migrations to the CI database so the schema stays in
# sync and any broken migration SQL is caught before merge.
- name: Run database migrations
run: npm run db:migrate:prod

# ── Build & test ────────────────────────────────────────────────────────
- name: Lint
run: npm run lint

- name: Type-check
run: npm run typecheck

- name: Build
run: npm run build

- name: Unit tests
run: npm test

- name: E2E tests
run: npm run test:e2e
27 changes: 25 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
# ─── Build stage ─────────────────────────────────────────────────────────────
FROM node:20-alpine AS build
WORKDIR /app

# Install all deps (including dev) so the NestJS compiler and Prisma generator
# are available.
COPY package*.json ./
RUN npm install

# Copy source + Prisma schema before generating so the client is built from the
# correct schema rather than whatever was cached in node_modules.
COPY prisma ./prisma
RUN npm run db:generate

COPY . .
RUN npm run build

# ─── Runtime stage ───────────────────────────────────────────────────────────
FROM node:20-alpine AS runtime
WORKDIR /app

ENV NODE_ENV=production

# Install production-only deps.
COPY package*.json ./
RUN npm install --omit=dev
COPY --from=build /app/dist ./dist

# Copy generated Prisma client and migration files so `migrate deploy` works at
# container start without needing the full dev toolchain.
COPY --from=build /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=build /app/node_modules/@prisma/client ./node_modules/@prisma/client
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/dist ./dist

EXPOSE 4000
CMD ["node", "dist/main.js"]

# Run pending migrations then start the server.
# `migrate deploy` is idempotent — it only applies un-applied migrations.
CMD ["sh", "-c", "npx prisma migrate deploy && node dist/main.js"]
Loading