Create web/Dockerfile
Browse files- web/Dockerfile +60 -0
web/Dockerfile
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Multi-stage build for Next.js application
|
| 2 |
+
|
| 3 |
+
# Stage 1: Dependencies
|
| 4 |
+
FROM node:20-alpine AS deps
|
| 5 |
+
RUN apk add --no-cache libc6-compat
|
| 6 |
+
WORKDIR /app
|
| 7 |
+
|
| 8 |
+
# Copy package files
|
| 9 |
+
COPY package.json package-lock.json* ./
|
| 10 |
+
RUN npm ci
|
| 11 |
+
|
| 12 |
+
# Stage 2: Builder
|
| 13 |
+
FROM node:20-alpine AS builder
|
| 14 |
+
WORKDIR /app
|
| 15 |
+
|
| 16 |
+
# Copy dependencies from deps stage
|
| 17 |
+
COPY --from=deps /app/node_modules ./node_modules
|
| 18 |
+
COPY . .
|
| 19 |
+
|
| 20 |
+
# Build arguments for environment variables
|
| 21 |
+
ARG NEXT_PUBLIC_API_URL
|
| 22 |
+
ARG NEXT_PUBLIC_APP_URL
|
| 23 |
+
ARG NEXT_PUBLIC_WS_URL
|
| 24 |
+
|
| 25 |
+
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
| 26 |
+
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
|
| 27 |
+
ENV NEXT_PUBLIC_WS_URL=$NEXT_PUBLIC_WS_URL
|
| 28 |
+
|
| 29 |
+
# Build the application
|
| 30 |
+
RUN npm run build
|
| 31 |
+
|
| 32 |
+
# Stage 3: Runner
|
| 33 |
+
FROM node:20-alpine AS runner
|
| 34 |
+
WORKDIR /app
|
| 35 |
+
|
| 36 |
+
ENV NODE_ENV production
|
| 37 |
+
|
| 38 |
+
# Create non-root user
|
| 39 |
+
RUN addgroup --system --gid 1001 nodejs
|
| 40 |
+
RUN adduser --system --uid 1001 nextjs
|
| 41 |
+
|
| 42 |
+
# Copy necessary files
|
| 43 |
+
COPY --from=builder /app/public ./public
|
| 44 |
+
|
| 45 |
+
# Set correct permissions for prerender cache
|
| 46 |
+
RUN mkdir .next
|
| 47 |
+
RUN chown nextjs:nodejs .next
|
| 48 |
+
|
| 49 |
+
# Copy build output
|
| 50 |
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
| 51 |
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
| 52 |
+
|
| 53 |
+
USER nextjs
|
| 54 |
+
|
| 55 |
+
EXPOSE 3000
|
| 56 |
+
|
| 57 |
+
ENV PORT 3000
|
| 58 |
+
ENV HOSTNAME "0.0.0.0"
|
| 59 |
+
|
| 60 |
+
CMD ["node", "server.js"]
|