Skip to content
Merged
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
18 changes: 12 additions & 6 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,26 @@ services:
timeout: 5s
retries: 5

# One-shot: applies committed Drizzle migrations (packages/db/src/migrations)
# before web/admin start. Generate migrations with `pnpm db:generate` and
# commit them — this service is a no-op if none exist yet.
# Applies committed Drizzle migrations (packages/db/src/migrations), then
# idles so it stays a healthy long-running container. web/admin wait on its
# healthcheck. Generate migrations with `pnpm db:generate` and commit them.
migrate:
build:
context: .
dockerfile: docker/Dockerfile.migrate
restart: "no"
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
env_file: .env
networks:
- internal
healthcheck:
test: ["CMD-SHELL", "test -f /tmp/migrated"]
interval: 5s
timeout: 3s
retries: 30
start_period: 5s

web:
build:
Expand All @@ -79,7 +85,7 @@ services:
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
condition: service_healthy
env_file: .env
# No host port: Traefik (Dokploy) routes to the container over
# dokploy-network using the port set in the Domain config. Publishing
Expand Down Expand Up @@ -133,7 +139,7 @@ services:
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
condition: service_healthy
env_file: .env
expose:
- "3002"
Expand Down
16 changes: 10 additions & 6 deletions docker/Dockerfile.migrate
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# syntax=docker.io/docker/dockerfile:1
# One-shot migration runner for docker-compose.prod.yml.
# Installs only @vibestack/db and its workspace deps, then runs
# `drizzle-kit migrate` (applies committed SQL from packages/db/src/migrations).
# Generate migrations locally with `pnpm db:generate` and commit them —
# `migrate` is a no-op if the folder is empty.
# Migration runner for docker-compose.prod.yml.
# Installs only @vibestack/db and its workspace deps, applies committed SQL
# from packages/db/src/migrations via `drizzle-kit migrate`, writes a marker,
# then idles so the container stays running (and healthy) instead of exiting.
# Some orchestrators (Dokploy) treat an exited one-shot container as a failed
# deploy and never start the services that depend on it; here dependents wait
# on this container's healthcheck (the marker file), not on it completing.
# Generate migrations locally with `pnpm db:generate` and commit them.

FROM node:22-alpine

Expand All @@ -21,4 +24,5 @@ COPY packages/config packages/config
RUN pnpm --filter @vibestack/db... install

# DATABASE_URL comes from env_file at runtime (docker-compose.prod.yml).
CMD ["pnpm", "--filter", "@vibestack/db", "run", "db:migrate"]
# Migrate, mark done for the healthcheck, then idle so the container stays up.
CMD ["sh", "-c", "pnpm --filter @vibestack/db run db:migrate && touch /tmp/migrated && echo '[migrate] applied; idling' && tail -f /dev/null"]
Loading