From 0402bcd7e1eaa622ac95585db7d009bb3e0fce7f Mon Sep 17 00:00:00 2001 From: MarkLo Date: Fri, 21 Nov 2025 09:46:20 +0800 Subject: [PATCH] --- frontend/Dockerfile.railway | 54 +++++++++++++++++++++++++++++++++++++ railway.toml | 3 +-- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 frontend/Dockerfile.railway diff --git a/frontend/Dockerfile.railway b/frontend/Dockerfile.railway new file mode 100644 index 00000000..e31e681e --- /dev/null +++ b/frontend/Dockerfile.railway @@ -0,0 +1,54 @@ +# Multi-stage build for Next.js frontend +FROM node:20-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# Install pnpm +RUN corepack enable && corepack prepare pnpm@latest --activate + +# Install dependencies +COPY frontend/package.json frontend/pnpm-lock.yaml* ./ +RUN pnpm install --frozen-lockfile + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY frontend . + +# Set environment variable for build +ENV NEXT_PUBLIC_API_URL=http://backend:8000 + +# Build Next.js app +RUN pnpm run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# Set permissions for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# Automatically leverage output traces to reduce image size +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] diff --git a/railway.toml b/railway.toml index fbb71ca5..7ad7d0c9 100644 --- a/railway.toml +++ b/railway.toml @@ -12,5 +12,4 @@ sourcePath = "." [[services]] name = "frontend" -dockerfilePath = "Dockerfile" -sourcePath = "frontend" +dockerfilePath = "frontend/Dockerfile.railway"