Replaces hardcoded production API URLs with localhost defaults for local development in both server and client code. Updates Dockerfile to require API URLs via deployment environment variables. Improves ChatTable to use a batch endpoint for chats and unread counts, with backward compatibility. Adds an env.example file to document required environment variables. Updates next.config.mjs to use environment variables for backend API rewrites and image domains.
52 lines
1.4 KiB
Docker
52 lines
1.4 KiB
Docker
# Use official Node.js image as base
|
|
FROM node:18-alpine AS builder
|
|
WORKDIR /app
|
|
COPY package.json package-lock.json ./
|
|
|
|
RUN npm install --force
|
|
|
|
COPY . .
|
|
|
|
# Install git, get commit hash
|
|
RUN apk add --no-cache git \
|
|
&& git rev-parse --short HEAD > /app/git_commit_sha
|
|
|
|
ENV NEXT_PUBLIC_API_URL=/api
|
|
|
|
# Build the Next.js application
|
|
# The environment variable will be available during build if needed
|
|
# ENV GIT_COMMIT_SHA=$(cat /app/git_commit_sha)
|
|
RUN echo "Building with GIT_COMMIT_SHA=$(cat /app/git_commit_sha)" && npm run build
|
|
|
|
# ---- Production Stage ----
|
|
FROM node:18-alpine AS runner
|
|
|
|
# Set working directory inside the container
|
|
WORKDIR /app
|
|
|
|
RUN mkdir -p /app/public
|
|
|
|
# Copy only necessary files from builder
|
|
COPY --from=builder /app/package.json /app/package-lock.json ./
|
|
COPY --from=builder /app/.next ./.next
|
|
COPY --from=builder /app/node_modules ./node_modules
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# Copy commit hash file from builder stage
|
|
COPY --from=builder /app/git_commit_sha /app/git_commit_sha
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_PUBLIC_API_URL=/api
|
|
# Backend API URL should be set via deployment environment
|
|
# ENV SERVER_API_URL=set_via_deployment
|
|
# ENV API_BASE_URL=set_via_deployment
|
|
# ENV API_HOSTNAME=set_via_deployment
|
|
|
|
# Set GIT_COMMIT_SHA environment variable in the final image by reading the file
|
|
ENV GIT_COMMIT_SHA="$(cat /app/git_commit_sha)"
|
|
|
|
|
|
# Start Next.js server
|
|
CMD ["npm", "run", "start"] |