52 lines
1.3 KiB
Docker
52 lines
1.3 KiB
Docker
# Stage 1: Build
|
|
FROM node:20-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
# Enable pnpm
|
|
RUN corepack enable pnpm
|
|
|
|
# Build args for Next.js public env vars (inlined at build time)
|
|
ARG NEXT_PUBLIC_API_URL=http://localhost:3000
|
|
|
|
# Copy workspace configuration files
|
|
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
|
|
COPY contracts/package.json ./contracts/
|
|
COPY frontend/package.json ./frontend/
|
|
|
|
# Install dependencies
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
# Copy source code
|
|
COPY contracts ./contracts
|
|
COPY frontend ./frontend
|
|
|
|
# Build contracts first (workspace dependency)
|
|
RUN pnpm --filter @home-service/contracts build
|
|
|
|
# Set env for build and build frontend
|
|
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
|
RUN pnpm --filter @home-service/frontend build
|
|
|
|
# Stage 2: Production
|
|
FROM node:20-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3001
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# For server-side API calls (inside Docker network)
|
|
ENV API_URL=http://backend:3000
|
|
|
|
# Copy standalone build output (monorepo structure puts it in frontend subfolder)
|
|
COPY --from=builder /app/frontend/.next/standalone ./
|
|
COPY --from=builder /app/frontend/.next/static ./frontend/.next/static
|
|
# Copy public folder if exists
|
|
COPY --from=builder /app/frontend/public ./frontend/public
|
|
|
|
EXPOSE 3001
|
|
|
|
WORKDIR /app/frontend
|
|
|
|
CMD ["node", "server.js"]
|