50 lines
No EOL
1.1 KiB
Docker
50 lines
No EOL
1.1 KiB
Docker
FROM oven/bun:latest AS base
|
|
|
|
# Install dependencies only when needed
|
|
FROM base AS deps
|
|
WORKDIR /app
|
|
COPY package.json ./
|
|
RUN bun install
|
|
|
|
# Rebuild the source code only when needed
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Build Next.js
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
RUN bun run build
|
|
|
|
# # Production image, copy all the files and run next
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Copy public folder
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# Set permission for prerender cache
|
|
RUN mkdir .next
|
|
|
|
# Automatically leverage output traces to reduce image size
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder /app/.next/static ./.next/static
|
|
|
|
# Copy migrations and migration script
|
|
COPY --from=builder /app/drizzle ./drizzle
|
|
COPY --from=builder /app/src/db/migrate.ts ./src/db/migrate.ts
|
|
COPY --from=builder /app/src ./src
|
|
|
|
RUN bun install drizzle-orm pg dotenv
|
|
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Custom entrypoint to run migrations then start app
|
|
CMD ["sh", "-c", "bun --bun run src/db/migrate.ts && bun --bun run server.js"] |