dockerfile changes

This commit is contained in:
parsa aghaei 2026-07-11 20:15:19 +03:30
parent 508356b8d3
commit b0d639996b
2 changed files with 36 additions and 32 deletions

View File

@ -1,5 +1,30 @@
# Build stage for Frontend Application
FROM docker.arvancloud.ir/library/node:22-alpine AS app-builder
RUN sed -i 's/dl-cdn.alpinelinux.org/mirror.arvancloud.ir/g' /etc/apk/repositories && \
apk add --no-cache openssl
WORKDIR /app
COPY frontend/application/package*.json ./
RUN npm config set registry https://registry.npmmirror.com && npm install
COPY frontend/application ./
RUN npm run build
# Build stage for Admin Panel
FROM docker.arvancloud.ir/library/node:22-alpine AS admin-builder
RUN sed -i 's/dl-cdn.alpinelinux.org/mirror.arvancloud.ir/g' /etc/apk/repositories && \
apk add --no-cache openssl
WORKDIR /app
COPY frontend/admin-panel/package*.json ./
RUN npm config set registry https://registry.npmmirror.com && npm install
COPY frontend/admin-panel ./
RUN npm run build
# Production stage
FROM docker.arvancloud.ir/nginxinc/nginx-unprivileged:alpine
COPY dist /usr/share/nginx/html
# No need for apk add here unless needed by nginx, but let's keep it clean
WORKDIR /usr/share/nginx/html
COPY --from=app-builder /app/.next ./.next
COPY --from=app-builder /app/public ./public
COPY --from=admin-builder /app/dist ./admin
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]

View File

@ -1,57 +1,36 @@
# Build stage for Backend
FROM docker.arvancloud.ir/library/node:22-alpine AS builder
RUN apk add --no-cache openssl
# Use ArvanCloud Alpine mirror to fix TLS/timeout issues
RUN sed -i 's/dl-cdn.alpinelinux.org/mirror.arvancloud.ir/g' /etc/apk/repositories && \
apk add --no-cache openssl
WORKDIR /app
# Copy package files
COPY package*.json ./
# Set NPM registry mirror
# Using mirror for npm as well
RUN npm config set registry https://registry.npmmirror.com
RUN npm config set fetch-retries 10
RUN npm config set fetch-retry-mintimeout 20000
RUN npm config set fetch-retry-maxtimeout 120000
RUN npm ci
# Install all dependencies (including devDependencies)
RUN for i in 1 2 3 4 5; do npm ci && exit 0 || (echo "Retry $i in 10s..." && sleep 10); done; exit 1
# Copy the rest of the application
COPY . .
# Build the application (compiles TypeScript to dist folder)
# We also generate prisma client here if prisma schema is present.
RUN npx prisma generate
RUN npm run build
# Production image
# Production stage
FROM docker.arvancloud.ir/library/node:22-alpine
RUN apk add --no-cache openssl
RUN sed -i 's/dl-cdn.alpinelinux.org/mirror.arvancloud.ir/g' /etc/apk/repositories && \
apk add --no-cache openssl
WORKDIR /app
# Copy only package files
COPY package*.json ./
# Set NPM registry mirror
RUN npm config set registry https://registry.npmmirror.com
RUN npm config set fetch-retries 10
RUN npm config set fetch-retry-mintimeout 20000
RUN npm config set fetch-retry-maxtimeout 120000
RUN npm ci --only=production
# Install only production dependencies
RUN for i in 1 2 3 4 5; do npm ci --only=production && exit 0 || (echo "Retry $i in 10s..." && sleep 10); done; exit 1
# Copy built artifacts from the builder stage
COPY --from=builder /app/dist ./dist
# Copy generated prisma client:
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma/client ./node_modules/@prisma/client
EXPOSE 3000
USER node
# Start the application
CMD ["node", "dist/main"]