This commit is contained in:
phaichayon
2026-07-16 23:02:27 +07:00
parent 6caa7fdb3e
commit 8d7b85e45d
2 changed files with 31 additions and 37 deletions

View File

@@ -41,43 +41,6 @@ COPY . .
RUN npm run build
# =========================================================
# Migration / Seed image
#
# ใช้ target นี้สำหรับ:
# - npm run migrate
# - npm run seed:master-data
# - npm run seed:super-admin
# =========================================================
FROM base AS migrator
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV HUSKY=0
COPY --from=deps /app/node_modules ./node_modules
COPY package.json ./
# Drizzle configuration
COPY drizzle.config.* ./
# Migration files
COPY drizzle ./drizzle
# Database source code ที่ migration/seed scripts อาจ import
COPY src ./src
COPY scripts ./scripts
# ถ้าโปรเจกต์ใช้ tsconfig path alias
COPY tsconfig.json ./
# ถ้ามีไฟล์ config อื่นที่ scripts ใช้งาน ให้เปิดใช้ตามจริง
# COPY next.config.* ./
# COPY env.* ./
CMD ["npm", "run", "migrate"]
# =========================================================
# Production Runner
# =========================================================

31
Dockerfile.migrator Normal file
View File

@@ -0,0 +1,31 @@
# syntax=docker/dockerfile:1
FROM node:20-bookworm-slim
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV HUSKY=0
COPY package.json package-lock.json ./
RUN npm ci --no-audit --no-fund
COPY drizzle.config.* ./
COPY drizzle ./drizzle
COPY src ./src
COPY scripts ./scripts
COPY tsconfig.json ./
CMD ["sh", "-c", "\
set -e; \
echo 'Running database migrations...'; \
npm run migrate; \
echo 'Running master-data seed...'; \
npm run seed:master-data; \
echo 'Running super-admin seed...'; \
npm run seed:super-admin; \
echo 'Migration and seeds completed successfully'; \
tail -f /dev/null \
"]