fix(deploy): copy package.json into subdirs and run npm with --prefix to handle monorepo-like layout

This commit is contained in:
2025-08-25 09:36:23 +08:00
parent 10938766f4
commit cbd6cd41de
2 changed files with 8 additions and 8 deletions

View File

@@ -1,9 +1,9 @@
FROM node:20-alpine AS builder
WORKDIR /app
COPY backend/package*.json ./
# Use npm ci if a lockfile exists, otherwise fall back to npm install
RUN sh -c 'if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then npm ci --production; else npm install --production; fi'
COPY backend/ ./
COPY backend/package*.json backend/
# Use npm ci if a lockfile exists in backend, otherwise fall back to npm install
RUN sh -c 'if [ -f backend/package-lock.json ] || [ -f backend/npm-shrinkwrap.json ]; then npm ci --prefix backend --production; else npm install --prefix backend --production; fi'
COPY backend/ backend/
RUN npm run build --prefix backend
FROM node:20-alpine

View File

@@ -1,9 +1,9 @@
FROM node:20-alpine AS builder
WORKDIR /app
COPY frontend/package*.json ./
# Use npm ci when lockfile exists, fallback to npm install
RUN sh -c 'if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then npm ci; else npm install; fi'
COPY frontend/ ./
COPY frontend/package*.json frontend/
# Use npm ci when lockfile exists in frontend, fallback to npm install
RUN sh -c 'if [ -f frontend/package-lock.json ] || [ -f frontend/npm-shrinkwrap.json ]; then npm ci --prefix frontend; else npm install --prefix frontend; fi'
COPY frontend/ frontend/
RUN npm run build --prefix frontend
FROM nginx:stable-alpine