deploy docker ghcr

This commit is contained in:
bipproduction
2026-03-02 15:09:46 +08:00
parent 0ba30aa5b2
commit ed664d5b10
2 changed files with 79 additions and 59 deletions

View File

@@ -1,48 +1,69 @@
FROM debian:bookworm-slim AS base
# ==============================
# Stage 1: Builder (Debian)
# ==============================
FROM node:20-bookworm-slim AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
curl unzip ca-certificates libssl3 && \
rm -rf /var/lib/apt/lists/* && \
curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:$PATH"
WORKDIR /app
# ---- deps ----
FROM base AS deps
# Install dependencies yang sebelumnya pakai apk
RUN apt-get update && apt-get install -y --no-install-recommends \
libc6 \
git \
openssl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile
COPY package.json bun.lockb* ./
# ---- builder ----
FROM deps AS builder
ENV ONNXRUNTIME_NODE_INSTALL_CUDA=0
ENV SHARP_IGNORE_GLOBAL_LIBVIPS=1
COPY prisma ./prisma
RUN bunx prisma generate
RUN npm install --ignore-scripts
COPY src ./src
COPY types ./types
COPY tsconfig.json ./
COPY . .
# BUN_PUBLIC_* vars are baked into the browser bundle at build time
ARG BUN_PUBLIC_BASE_URL
ENV BUN_PUBLIC_BASE_URL=${BUN_PUBLIC_BASE_URL}
RUN bun run build
# Skip telemetry & limit memory
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_OPTIONS="--max-old-space-size=4096"
# ---- runner ----
FROM base AS runner
# Generate prisma client
RUN npx prisma generate
COPY package.json bun.lockb ./
RUN bun install --production
# Build Next.js
RUN npm run build
COPY --from=builder /app/generated ./generated
COPY --from=builder /app/.next ./.next
COPY src ./src
COPY prisma ./prisma
COPY types ./types
COPY tsconfig.json ./
# ==============================
# Stage 2: Runner (Debian)
# ==============================
FROM node:20-bookworm-slim AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN apt-get update && apt-get install -y --no-install-recommends \
openssl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Buat user non-root (cara Debian)
RUN groupadd --system --gid 1001 nodejs \
&& useradd --system --uid 1001 --gid nodejs nextjs
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
CMD ["bun", "run", "./src/index.tsx"]
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["npx", "next", "start"]