fix: prisma db push를 builder 스테이지에서 실행하도록 수정
- docker-compose.prod.yml에 migrate 서비스 추가 (builder target 사용) - deploy.sh: postgres 먼저 시작 → migrate 실행 → 나머지 서비스 시작 - Dockerfile에서 불필요한 prisma schema 복사 제거 (runner에 prisma CLI 없음)
This commit is contained in:
@@ -34,10 +34,6 @@ COPY . .
|
||||
RUN cd packages/database && npx prisma generate
|
||||
RUN pnpm turbo run build --filter=@startover/${APP_NAME}
|
||||
|
||||
# Copy Prisma schema and engine for runtime migration
|
||||
RUN mkdir -p /app/prisma
|
||||
RUN cp packages/database/prisma/schema.prisma /app/prisma/schema.prisma
|
||||
|
||||
# Ensure public directories exist for COPY
|
||||
RUN mkdir -p /app/apps/${APP_NAME}/public
|
||||
|
||||
@@ -54,7 +50,6 @@ WORKDIR /app
|
||||
COPY --from=builder /app/apps/${APP_NAME}/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/.next/static ./apps/${APP_NAME}/.next/static
|
||||
COPY --from=builder /app/prisma/schema.prisma ./prisma/schema.prisma
|
||||
|
||||
USER nextjs
|
||||
EXPOSE 3000
|
||||
|
||||
+10
-8
@@ -51,22 +51,24 @@ if [ -f "$APP_DIR/.env.production" ]; then
|
||||
cp "$APP_DIR/.env.production" "$APP_DIR/repo/.env.production"
|
||||
fi
|
||||
|
||||
# Build and deploy
|
||||
log "Building and deploying with Docker Compose..."
|
||||
docker compose -f docker-compose.prod.yml --env-file .env.production up -d --build --remove-orphans 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
# Wait for postgres to be healthy
|
||||
# Step 1: Start postgres and wait for healthy
|
||||
log "Starting postgres..."
|
||||
docker compose -f docker-compose.prod.yml --env-file .env.production up -d postgres 2>&1 | tee -a "$LOG_FILE"
|
||||
log "Waiting for postgres to be healthy..."
|
||||
sleep 10
|
||||
|
||||
# Apply database schema
|
||||
# Step 2: Run database migration (uses builder stage with prisma CLI)
|
||||
log "Applying database schema (prisma db push)..."
|
||||
docker compose -f docker-compose.prod.yml --env-file .env.production exec -T web npx prisma db push --schema=./prisma/schema.prisma --skip-generate --accept-data-loss 2>&1 | tee -a "$LOG_FILE"
|
||||
docker compose -f docker-compose.prod.yml --env-file .env.production run --rm migrate 2>&1 | tee -a "$LOG_FILE"
|
||||
log "Database schema applied."
|
||||
|
||||
# Step 3: Build and deploy all services
|
||||
log "Building and deploying all services..."
|
||||
docker compose -f docker-compose.prod.yml --env-file .env.production up -d --build --remove-orphans 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
# Wait for services to stabilize
|
||||
log "Waiting for services to stabilize..."
|
||||
sleep 5
|
||||
sleep 10
|
||||
|
||||
# Health check
|
||||
if curl -sf http://localhost/health > /dev/null 2>&1; then
|
||||
|
||||
@@ -47,6 +47,18 @@ services:
|
||||
- web
|
||||
- admin
|
||||
|
||||
migrate:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: builder
|
||||
environment:
|
||||
DATABASE_URL: postgresql://${DB_USER:-startover}:${DB_PASSWORD}@postgres:5432/${DB_NAME:-startover_prod}?schema=public
|
||||
command: sh -c "cd packages/database && npx prisma db push --skip-generate --accept-data-loss"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
web:
|
||||
build:
|
||||
context: .
|
||||
|
||||
Reference in New Issue
Block a user