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 WORKDIR /app
# Copy package files # Copy root package files for workspace install
COPY package*.json ./ COPY package*.json ./
COPY prisma ./prisma/ COPY backend/package*.json ./backend/
COPY backend/prisma ./backend/prisma/
# Install dependencies # Install dependencies using npm install (no individual lockfile in workspace)
RUN npm ci RUN npm install --legacy-peer-deps
# Copy source code # Copy backend source
COPY . . COPY backend/ ./backend/
# Generate Prisma client # Generate Prisma client and build
WORKDIR /app/backend
RUN npx prisma generate RUN npx prisma generate
# Build TypeScript
RUN npm run build RUN npm run build
# Production stage # Production stage
@@ -29,14 +29,17 @@ RUN apk add --no-cache openssl
# Copy package files # Copy package files
COPY package*.json ./ COPY package*.json ./
COPY backend/package*.json ./backend/
# Install production dependencies only # Install production dependencies
RUN npm ci --only=production RUN npm install --legacy-peer-deps --omit=dev
# Copy built files from builder # Copy built files from builder
COPY --from=builder /app/dist ./dist COPY --from=builder /app/backend/dist ./backend/dist
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma COPY --from=builder /app/backend/node_modules/.prisma ./backend/node_modules/.prisma
COPY --from=builder /app/prisma ./prisma COPY --from=builder /app/backend/prisma ./backend/prisma
WORKDIR /app/backend
# Expose port # Expose port
EXPOSE 3001 EXPOSE 3001
+4 -6
View File
@@ -1,5 +1,3 @@
version: '3.8'
services: services:
postgres: postgres:
image: postgres:16-alpine image: postgres:16-alpine
@@ -37,8 +35,8 @@ services:
backend: backend:
build: build:
context: ./backend context: .
dockerfile: Dockerfile dockerfile: backend/Dockerfile
container_name: coop-backend container_name: coop-backend
environment: environment:
- NODE_ENV=production - NODE_ENV=production
@@ -69,8 +67,8 @@ services:
frontend: frontend:
build: build:
context: ./frontend context: .
dockerfile: Dockerfile dockerfile: frontend/Dockerfile
container_name: coop-frontend container_name: coop-frontend
environment: environment:
- NEXT_PUBLIC_API_URL=http://localhost:3001 - NEXT_PUBLIC_API_URL=http://localhost:3001
+15 -10
View File
@@ -3,16 +3,18 @@ FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Copy package files # Copy root package files for workspace install
COPY package*.json ./ COPY package*.json ./
COPY frontend/package*.json ./frontend/
# Install dependencies # Install dependencies using npm install (no individual lockfile in workspace)
RUN npm ci RUN npm install --legacy-peer-deps
# Copy source code # Copy frontend source
COPY . . COPY frontend/ ./frontend/
# Build Next.js app # Build Next.js app
WORKDIR /app/frontend
RUN npm run build RUN npm run build
# Production stage # Production stage
@@ -22,14 +24,17 @@ WORKDIR /app
# Copy package files # Copy package files
COPY package*.json ./ COPY package*.json ./
COPY frontend/package*.json ./frontend/
# Install production dependencies only # Install production dependencies
RUN npm ci --only=production RUN npm install --legacy-peer-deps --omit=dev
# Copy built files from builder # Copy built files from builder
COPY --from=builder /app/.next ./.next COPY --from=builder /app/frontend/.next ./frontend/.next
COPY --from=builder /app/public ./public COPY --from=builder /app/frontend/public ./frontend/public
COPY --from=builder /app/next.config.js ./ COPY --from=builder /app/frontend/next.config.js ./frontend/
WORKDIR /app/frontend
# Expose port # Expose port
EXPOSE 3000 EXPOSE 3000