chore: deploy with Docker Compose on Dokploy

Add the two runtime images and their compose file: `api` (Bun bundle,
runs `prisma migrate deploy` before `bun run start`) and `web` (Vite
build served by nginx, which proxies `/api/*` to the API and keeps the
SSE streams unbuffered with a long read timeout). The database is
external and both services join the `dokploy-network` for Traefik.

Remove the GitHub Actions workflow: there is no hosted CI, so the
verification scripts run locally.
This commit is contained in:
Jose Selesan
2026-10-16 15:44:26 -03:00
parent 370e3022c8
commit f87d46c975
6 changed files with 182 additions and 53 deletions

20
.dockerignore Normal file
View File

@@ -0,0 +1,20 @@
.git
.github
**/node_modules
**/.turbo
**/dist
**/build
**/coverage
**/*.tsbuildinfo
**/*.log
.DS_Store
# env (examples are kept: they never contain secrets)
.env
.env.*
!.env.example
# generated files (rebuilt inside the image)
apps/api/src/generated
apps/web/src/routeTree.gen.ts
apps/web/.tanstack

View File

@@ -1,53 +0,0 @@
name: CI
on:
push:
branches: [main]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Prisma needs a connection string to generate the client; no database is
# contacted during lint, typecheck, test or build.
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/superlist?schema=public
BETTER_AUTH_SECRET: ci-only-secret-not-used-at-build-time
BETTER_AUTH_URL: http://localhost:4100
CORS_ORIGIN: http://localhost:7153
VITE_API_URL: http://localhost:4100
jobs:
verify:
name: Verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.4.0
# The Prisma CLI runs on Node.
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Generate Prisma client
run: bun run db:generate
- name: Lint and format check
run: bun run lint:ci
- name: Typecheck
run: bun run typecheck
- name: Test
run: bun run test
- name: Build
run: bun run build

27
apps/api/Dockerfile Normal file
View File

@@ -0,0 +1,27 @@
# Build context is the repository root (Bun workspace monorepo).
FROM oven/bun:1.4.0 AS base
WORKDIR /app
# Manifests first so `bun install` only reruns when the lockfile changes.
FROM base AS deps
COPY package.json bun.lock bunfig.toml ./
COPY apps/api/package.json apps/api/package.json
COPY apps/web/package.json apps/web/package.json
COPY packages/shared/package.json packages/shared/package.json
RUN bun install --frozen-lockfile
FROM deps AS build
COPY . .
# `prisma.config.ts` reads DATABASE_URL at load time; generate never connects,
# so a placeholder is enough to produce the client in src/generated/.
RUN cd apps/api && DATABASE_URL="postgresql://user:pass@localhost:5432/db" bunx prisma generate
RUN cd apps/api && bun run build
# Runtime keeps the full tree: `prisma migrate deploy` runs on startup and
# needs the Prisma CLI (devDependency), prisma/ and prisma.config.ts.
FROM base AS runtime
ENV NODE_ENV=production
COPY --from=build /app /app
WORKDIR /app/apps/api
EXPOSE 4100
CMD ["sh", "-c", "bunx prisma migrate deploy && bun run start"]

23
apps/web/Dockerfile Normal file
View File

@@ -0,0 +1,23 @@
# Build context is the repository root (Bun workspace monorepo).
FROM oven/bun:1.4.0 AS build
WORKDIR /app
# Manifests first so `bun install` only reruns when the lockfile changes.
COPY package.json bun.lock bunfig.toml ./
COPY apps/api/package.json apps/api/package.json
COPY apps/web/package.json apps/web/package.json
COPY packages/shared/package.json packages/shared/package.json
RUN bun install --frozen-lockfile
COPY . .
# Empty by default: in production the SPA and the API share one origin and the
# browser calls `/api/*` (nginx proxies it). Set the build arg to point the
# frontend at a different API origin.
ARG VITE_API_URL=""
ENV VITE_API_URL=$VITE_API_URL
RUN cd apps/web && bun run build
FROM nginx:alpine AS runtime
COPY apps/web/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/apps/web/dist /usr/share/nginx/html
EXPOSE 80

47
apps/web/nginx.conf Normal file
View File

@@ -0,0 +1,47 @@
# Serves the built SPA and proxies /api/* to the Bun API container.
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
# API proxy: no path rewrite, /api/* reaches the API as-is. `proxy_buffering
# off` and the long read timeout keep the SSE streams (/lists/:id/events)
# flowing in realtime instead of being batched or cut off.
location /api/ {
proxy_pass http://api:4100;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 1h;
proxy_send_timeout 1h;
}
# PWA: hashed build output is safe to cache forever, the service worker and
# the app shell must always be revalidated so new releases reach clients.
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
}
location = /sw.js {
add_header Cache-Control "no-cache";
}
location = /index.html {
add_header Cache-Control "no-cache";
}
# SPA fallback so deep links (/lists/:id, /invitations, ...) work on reload.
location / {
try_files $uri $uri/ /index.html;
}
}

65
docker-compose.yml Normal file
View File

@@ -0,0 +1,65 @@
# Dokploy deployment: the API and the static frontend behind nginx.
# The database is external (Dokploy's), and the containers join the shared
# `dokploy-network` so Dokploy's Traefik can reach them via the Domains UI.
services:
api:
build:
context: .
dockerfile: apps/api/Dockerfile
restart: unless-stopped
environment:
# Required: no sensible default for any of these.
DATABASE_URL: ${DATABASE_URL:?Set DATABASE_URL in the Dokploy env}
BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:?Set BETTER_AUTH_SECRET in the Dokploy env}
BETTER_AUTH_URL: ${BETTER_AUTH_URL:?Set BETTER_AUTH_URL in the Dokploy env}
CORS_ORIGIN: ${CORS_ORIGIN:?Set CORS_ORIGIN in the Dokploy env}
WEB_APP_URL: ${WEB_APP_URL:?Set WEB_APP_URL in the Dokploy env}
# Optional: sensible defaults when unset.
NODE_ENV: ${NODE_ENV:-production}
PORT: ${PORT:-4100}
LOG_LEVEL: ${LOG_LEVEL:-}
RESEND_API_KEY: ${RESEND_API_KEY:-}
MAIL_FROM: ${MAIL_FROM:-}
expose:
- "4100"
networks:
- dokploy-network
healthcheck:
test:
[
"CMD",
"bun",
"-e",
"fetch(`http://localhost:${PORT:-4100}/api/health`).then((r) => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))",
]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
web:
build:
context: .
dockerfile: apps/web/Dockerfile
args:
# Empty = same origin (nginx proxies /api/*). Only set this if the
# frontend must call the API on a different origin.
VITE_API_URL: ${VITE_API_URL:-}
restart: unless-stopped
depends_on:
api:
condition: service_healthy
expose:
- "80"
networks:
- dokploy-network
healthcheck:
test: ["CMD", "wget", "-qO", "/dev/null", "http://127.0.0.1/"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
networks:
dokploy-network:
external: true