This commit is contained in:
+17
-9
@@ -14,30 +14,38 @@ ENV TZ=Asia/Tehran
|
|||||||
# Set workdir for clarity
|
# Set workdir for clarity
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Stage 2: Dependencies
|
# Stage 2: Dependencies (for build)
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
WORKDIR /temp-deps
|
WORKDIR /temp-deps
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci --ignore-scripts --no-fund --no-audit
|
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
|
FROM base AS builder
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY . ./
|
COPY package*.json ./
|
||||||
COPY --from=deps /temp-deps/node_modules ./node_modules
|
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
|
FROM base AS runner
|
||||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY . ./
|
COPY --from=builder --chown=appuser:appgroup /build/package*.json ./
|
||||||
COPY --from=builder --chown=appuser:appgroup /build/ ./
|
COPY --from=prod-deps --chown=appuser:appgroup /temp-deps/node_modules ./node_modules
|
||||||
RUN chown -R appuser:appgroup /app
|
COPY --from=builder --chown=appuser:appgroup /build/dist ./dist
|
||||||
|
COPY --from=builder --chown=appuser:appgroup /build/database ./database
|
||||||
|
|
||||||
USER appuser
|
USER appuser
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
EXPOSE 4000
|
EXPOSE 4000
|
||||||
|
|
||||||
CMD ["npm", "run" , "start:prod"]
|
CMD ["npm", "run", "start:prod"]
|
||||||
|
|||||||
Reference in New Issue
Block a user