This commit is contained in:
+16
-8
@@ -14,27 +14,35 @@ ENV TZ=Asia/Tehran
|
||||
# Set workdir for clarity
|
||||
WORKDIR /app
|
||||
|
||||
# Stage 2: Dependencies
|
||||
# Stage 2: Dependencies (for build)
|
||||
FROM base AS deps
|
||||
WORKDIR /temp-deps
|
||||
COPY package*.json ./
|
||||
RUN npm ci --ignore-scripts --no-fund --no-audit
|
||||
|
||||
# Stage 3: Build
|
||||
# Stage 3: Production dependencies only
|
||||
FROM base AS prod-deps
|
||||
WORKDIR /temp-deps
|
||||
COPY package*.json ./
|
||||
RUN npm ci --omit=dev --ignore-scripts --no-fund --no-audit
|
||||
|
||||
# Stage 4: Build
|
||||
FROM base AS builder
|
||||
WORKDIR /build
|
||||
COPY . ./
|
||||
COPY package*.json ./
|
||||
COPY --from=deps /temp-deps/node_modules ./node_modules
|
||||
RUN if [ -f package.json ] && grep -q '"build":' package.json; then npm run build; fi
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Stage 4: Runner
|
||||
# Stage 5: Runner
|
||||
FROM base AS runner
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
WORKDIR /app
|
||||
|
||||
COPY . ./
|
||||
COPY --from=builder --chown=appuser:appgroup /build/ ./
|
||||
RUN chown -R appuser:appgroup /app
|
||||
COPY --from=builder --chown=appuser:appgroup /build/package*.json ./
|
||||
COPY --from=prod-deps --chown=appuser:appgroup /temp-deps/node_modules ./node_modules
|
||||
COPY --from=builder --chown=appuser:appgroup /build/dist ./dist
|
||||
COPY --from=builder --chown=appuser:appgroup /build/database ./database
|
||||
|
||||
USER appuser
|
||||
ENV NODE_ENV=production
|
||||
|
||||
Reference in New Issue
Block a user