This commit is contained in:
+31
-17
@@ -1,35 +1,49 @@
|
|||||||
# Stage 1: Build Stage
|
# Stage 1: Base — shared tooling and system config
|
||||||
FROM node:22-alpine AS base
|
FROM node:22-alpine AS base
|
||||||
|
|
||||||
RUN npm install -g corepack@latest
|
# Use Liara Alpine mirror
|
||||||
RUN corepack enable && corepack prepare pnpm@9 --activate
|
RUN sed -i 's|https://dl-cdn.alpinelinux.org|https://mirror.de.velop.ir|g' /etc/apk/repositories \
|
||||||
|
&& apk add --no-cache tzdata \
|
||||||
# Install tzdata to support timezone settings
|
&& cp /usr/share/zoneinfo/Asia/Tehran /etc/localtime \
|
||||||
RUN apk add --no-cache tzdata
|
&& echo "Asia/Tehran" > /etc/timezone
|
||||||
|
|
||||||
# Set the timezone to Asia/Tehran
|
|
||||||
RUN cp /usr/share/zoneinfo/Asia/Tehran /etc/localtime && echo "Asia/Tehran" > /etc/timezone
|
|
||||||
|
|
||||||
|
# Install and activate pnpm via corepack
|
||||||
|
RUN npm install -g corepack@latest --registry=https://package-mirror.liara.ir \
|
||||||
|
&& corepack enable \
|
||||||
|
&& corepack prepare pnpm@9 --activate
|
||||||
|
|
||||||
|
# Stage 2: Install all dependencies (including dev)
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
WORKDIR /temp-deps
|
WORKDIR /temp-deps
|
||||||
COPY package*.json pnpm-lock.yaml ./
|
COPY package.json pnpm-lock.yaml ./
|
||||||
RUN pnpm install --frozen-lockfile --loglevel info
|
RUN pnpm install --frozen-lockfile --loglevel info \
|
||||||
|
--registry=https://package-mirror.liara.ir
|
||||||
|
|
||||||
|
# Stage 3: Build
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY . ./
|
COPY . ./
|
||||||
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 pnpm run build; fi
|
RUN if grep -q '"build":' package.json; then pnpm run build; fi
|
||||||
RUN pnpm install --prod --frozen-lockfile --loglevel info
|
|
||||||
|
|
||||||
|
# Stage 4: Production deps only
|
||||||
|
FROM base AS prod-deps
|
||||||
|
WORKDIR /temp-deps
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN pnpm install --prod --frozen-lockfile --loglevel info \
|
||||||
|
--registry=https://package-mirror.liara.ir
|
||||||
|
|
||||||
|
# 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 only production node_modules and build output
|
||||||
COPY --from=builder --chown=appuser:appgroup /build/ ./
|
COPY --from=prod-deps --chown=appuser:appgroup /temp-deps/node_modules ./node_modules
|
||||||
|
COPY --from=builder --chown=appuser:appgroup /build/dist ./dist
|
||||||
|
COPY --chown=appuser:appgroup package.json ./
|
||||||
|
|
||||||
RUN chown -R appuser:appgroup /app
|
RUN chown -R appuser:appgroup /app
|
||||||
|
|
||||||
@@ -38,4 +52,4 @@ USER appuser
|
|||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
EXPOSE 3500
|
EXPOSE 3500
|
||||||
|
|
||||||
CMD ["npm", "start"]
|
CMD ["pnpm", "start"]
|
||||||
|
|||||||
Reference in New Issue
Block a user