mirror of
https://github.com/Mail-0/Zero.git
synced 2026-06-30 07:46:15 +00:00
81 lines
2.1 KiB
Docker
81 lines
2.1 KiB
Docker
# ========================================
|
|
# Base Stage: Alpine Linux with Bun
|
|
# ========================================
|
|
FROM oven/bun:alpine AS base
|
|
|
|
# ========================================
|
|
# Dependencies Stage: Install Dependencies
|
|
# ========================================
|
|
FROM base AS deps
|
|
RUN apk add --no-cache libc6-compat
|
|
WORKDIR /app
|
|
|
|
# Install turbo globally
|
|
RUN bun install -g turbo
|
|
|
|
COPY package.json bun.lock turbo.json ./
|
|
RUN mkdir -p apps packages
|
|
COPY apps/*/package.json ./apps/
|
|
COPY packages/*/package.json ./packages/
|
|
COPY packages/tsconfig/ ./packages/tsconfig/
|
|
|
|
RUN bun install --omit dev --ignore-scripts
|
|
|
|
# ========================================
|
|
# Builder Stage: Build the Application
|
|
# ========================================
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Installing with full context to prevent missing dependencies error
|
|
RUN bun install --omit dev --ignore-scripts
|
|
|
|
# Required for standalone nextjs build
|
|
WORKDIR /app/apps/mail
|
|
RUN bun install sharp
|
|
|
|
# Set environment variables for build
|
|
ENV NEXT_TELEMETRY_DISABLED=1 \
|
|
NODE_ENV=production \
|
|
DOCKER_BUILD=true
|
|
|
|
WORKDIR /app
|
|
RUN cd apps/mail && bun run build
|
|
|
|
# ========================================
|
|
# Runner Stage: Production Environment
|
|
# ========================================
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
RUN addgroup -S -g 1001 bunjs && \
|
|
adduser -S -u 1001 nextjs -G bunjs
|
|
|
|
# Set environment variables for build
|
|
ENV NODE_ENV=production \
|
|
PORT=3000 \
|
|
HOSTNAME="0.0.0.0" \
|
|
NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Copy entrypoint and run it
|
|
COPY scripts/docker/ /app/scripts
|
|
RUN chmod -R +x /app/scripts/*
|
|
|
|
# Copy public assets
|
|
COPY --from=builder --chown=nextjs:bunjs /app/apps/mail/public ./apps/mail/public
|
|
|
|
# Leverage output traces to reduce image size (standalone output)
|
|
COPY --from=builder --chown=nextjs:bunjs /app/apps/mail/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:bunjs /app/apps/mail/.next/static ./apps/mail/.next/static
|
|
|
|
# Switch to non-root user
|
|
USER nextjs
|
|
|
|
# Set server port and host
|
|
EXPOSE 3000
|
|
|
|
# Start the server
|
|
CMD ["/app/scripts/entrypoint.sh"] |