* Use Docker Compose init service pattern for database migrations Replaces the fragile double-migration approach (server.ts startup + drizzle-kit CLI in CI) with a one-shot migrate service in Docker Compose that the app depends on via condition: service_completed_successfully. - Add scripts/migrate.mjs: programmatic drizzle-orm migration (uses production deps, not drizzle-kit which is devOnly and absent from image) - Dockerfile: copy scripts/ into image, remove drizzle.config.ts (only needed by drizzle-kit CLI) - server.ts: remove runMigrations() entirely; migrations are now handled by the migrate container before the app starts - deploy.yml: remove explicit docker run migration step; replace sleep 10 health check with a poll loop and explicit migrate exit-code check Production server's docker-compose.yaml needs a one-time manual update to add the migrate service — see plan for exact config. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ * Move drizzle-kit to devDependencies; use docker compose wait in deploy drizzle-kit is a dev-only tool (schema generation and local migrations). Now that production migrations run via the programmatic drizzle-orm API in the migrate init container, drizzle-kit has no runtime role. Also replaces the polling health check loop with docker compose wait, which blocks until the migrate service exits and returns its exit code cleanly — no sleep or manual status inspection needed. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ --------- Co-authored-by: Claude <noreply@anthropic.com>
26 lines
No EOL
753 B
Docker
26 lines
No EOL
753 B
Docker
FROM node:20-alpine AS development-dependencies-env
|
|
COPY . /app
|
|
WORKDIR /app
|
|
RUN npm ci
|
|
|
|
FROM node:20-alpine AS production-dependencies-env
|
|
COPY ./package.json package-lock.json /app/
|
|
WORKDIR /app
|
|
RUN npm ci --omit=dev
|
|
|
|
FROM node:20-alpine AS build-env
|
|
COPY . /app/
|
|
COPY --from=development-dependencies-env /app/node_modules /app/node_modules
|
|
WORKDIR /app
|
|
RUN npm run build
|
|
|
|
FROM node:20-alpine
|
|
COPY ./package.json package-lock.json /app/
|
|
COPY --from=production-dependencies-env /app/node_modules /app/node_modules
|
|
COPY --from=build-env /app/build /app/build
|
|
COPY --from=build-env /app/dist /app/dist
|
|
COPY ./drizzle /app/drizzle
|
|
COPY ./scripts /app/scripts
|
|
COPY ./instrument.server.mjs /app/instrument.server.mjs
|
|
WORKDIR /app
|
|
CMD ["npm", "run", "start"] |