fix: docker build - use root context for monorepo workspaces

- Change build context from ./frontend|backend to root (.)
- Update Dockerfiles to copy from correct paths
- Use npm install instead of npm ci (workspaces share root lockfile)
- Remove obsolete version attribute from docker-compose.yml

Fixes npm ci errors when package-lock.json is at workspace root.
This commit is contained in:
2026-04-14 15:45:27 -04:00
parent 20d1f216a0
commit d2e20ad82a
3 changed files with 36 additions and 30 deletions
+17 -14
View File
@@ -3,20 +3,20 @@ FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
# Copy root package files for workspace install
COPY package*.json ./
COPY prisma ./prisma/
COPY backend/package*.json ./backend/
COPY backend/prisma ./backend/prisma/
# Install dependencies
RUN npm ci
# Install dependencies using npm install (no individual lockfile in workspace)
RUN npm install --legacy-peer-deps
# Copy source code
COPY . .
# Copy backend source
COPY backend/ ./backend/
# Generate Prisma client
# Generate Prisma client and build
WORKDIR /app/backend
RUN npx prisma generate
# Build TypeScript
RUN npm run build
# Production stage
@@ -29,14 +29,17 @@ RUN apk add --no-cache openssl
# Copy package files
COPY package*.json ./
COPY backend/package*.json ./backend/
# Install production dependencies only
RUN npm ci --only=production
# Install production dependencies
RUN npm install --legacy-peer-deps --omit=dev
# Copy built files from builder
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/backend/dist ./backend/dist
COPY --from=builder /app/backend/node_modules/.prisma ./backend/node_modules/.prisma
COPY --from=builder /app/backend/prisma ./backend/prisma
WORKDIR /app/backend
# Expose port
EXPOSE 3001
+4 -6
View File
@@ -1,5 +1,3 @@
version: '3.8'
services:
postgres:
image: postgres:16-alpine
@@ -37,8 +35,8 @@ services:
backend:
build:
context: ./backend
dockerfile: Dockerfile
context: .
dockerfile: backend/Dockerfile
container_name: coop-backend
environment:
- NODE_ENV=production
@@ -69,8 +67,8 @@ services:
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
context: .
dockerfile: frontend/Dockerfile
container_name: coop-frontend
environment:
- NEXT_PUBLIC_API_URL=http://localhost:3001
+15 -10
View File
@@ -3,16 +3,18 @@ FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
# Copy root package files for workspace install
COPY package*.json ./
COPY frontend/package*.json ./frontend/
# Install dependencies
RUN npm ci
# Install dependencies using npm install (no individual lockfile in workspace)
RUN npm install --legacy-peer-deps
# Copy source code
COPY . .
# Copy frontend source
COPY frontend/ ./frontend/
# Build Next.js app
WORKDIR /app/frontend
RUN npm run build
# Production stage
@@ -22,14 +24,17 @@ WORKDIR /app
# Copy package files
COPY package*.json ./
COPY frontend/package*.json ./frontend/
# Install production dependencies only
RUN npm ci --only=production
# Install production dependencies
RUN npm install --legacy-peer-deps --omit=dev
# Copy built files from builder
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/frontend/.next ./frontend/.next
COPY --from=builder /app/frontend/public ./frontend/public
COPY --from=builder /app/frontend/next.config.js ./frontend/
WORKDIR /app/frontend
# Expose port
EXPOSE 3000