update docker
This commit is contained in:
+56
-38
@@ -1,61 +1,79 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
FROM node:23-slim AS builder
|
||||
|
||||
WORKDIR /app
|
||||
# Set DEBIAN_FRONTEND to noninteractive to avoid prompts during apt-get operations
|
||||
# ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install pnpm
|
||||
# Copy your custom sources.list file into the container
|
||||
# COPY custom-sources.list /etc/apt/sources.list
|
||||
|
||||
# RUN release=$(grep VERSION_CODENAME= /etc/os-release | cut -d= -f2) && \
|
||||
# echo "deb http://mirror.arvancloud.ir/debian Bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
|
||||
# echo "deb http://mirror.arvancloud.ir/debian-security Bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
|
||||
# echo "deb http://mirror.arvancloud.ir/debian Bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list
|
||||
|
||||
|
||||
# RUN apt-get update --allow-unauthenticated && apt-get install -y --no-install-recommends ca-certificates && update-ca-certificates
|
||||
|
||||
# RUN apt-get update -y && apt-get install -y openssl
|
||||
|
||||
RUN npm config set registry https://hub.megan.ir/npm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# Copy dependency files
|
||||
|
||||
# ARG NODE_ENV
|
||||
# ARG PORT
|
||||
# ARG DATABASE_NAME
|
||||
# ARG DATABASE_USER
|
||||
# ARG DATABASE_PASSWORD
|
||||
# ARG DATABASE_PORT
|
||||
# ARG DATABASE_HOST
|
||||
# ARG DATABASE_URL
|
||||
# ARG SHADOW_DATABASE_URL
|
||||
# ARG JWT_SECRET
|
||||
# ARG JWT_EXPIRES_IN
|
||||
# ARG OTP_STATIC_CODE
|
||||
|
||||
|
||||
# ENV NODE_ENV=${NODE_ENV}
|
||||
# ENV PORT=${PORT}
|
||||
# ENV DATABASE_NAME=${DATABASE_NAME}
|
||||
# ENV DATABASE_USER=${DATABASE_USER}
|
||||
# ENV DATABASE_PASSWORD=${DATABASE_PASSWORD}
|
||||
# ENV DATABASE_PORT=${DATABASE_PORT}
|
||||
# ENV DATABASE_HOST=${DATABASE_HOST}
|
||||
# ENV DATABASE_URL=${DATABASE_URL}
|
||||
# ENV SHADOW_DATABASE_URL=${SHADOW_DATABASE_URL}
|
||||
# ENV JWT_SECRET=${JWT_SECRET}
|
||||
# ENV JWT_EXPIRES_IN=${JWT_EXPIRES_IN}
|
||||
# ENV OTP_STATIC_CODE=${OTP_STATIC_CODE}
|
||||
|
||||
COPY pnpm-lock.yaml package.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Generate Prisma client and build the application
|
||||
RUN pnpm exec prisma generate
|
||||
ENV PRISMA_CLIENT_ENGINE_TYPE=binary
|
||||
|
||||
# RUN pnpm prisma generate
|
||||
RUN pnpm run build
|
||||
|
||||
# Production stage
|
||||
FROM node:20-alpine
|
||||
|
||||
FROM node:23-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install pnpm
|
||||
RUN npm config set registry https://hub.megan.ir/npm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# Install dumb-init for proper signal handling
|
||||
RUN apk add --no-cache dumb-init
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
# RUN pnpm prune --prod
|
||||
|
||||
# Copy package files
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# Install only production dependencies
|
||||
RUN pnpm install --frozen-lockfile --prod
|
||||
|
||||
# Copy built application from builder
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
||||
# COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
||||
# COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
||||
COPY prisma ./prisma
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S nodejs -u 1001
|
||||
CMD ["node", "dist/src/main.js"]
|
||||
|
||||
USER nodejs
|
||||
|
||||
# Expose port
|
||||
EXPOSE 5002
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD node -e "require('http').get('http://localhost:5002/api/v1/health', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"
|
||||
|
||||
# Use dumb-init to handle signals properly
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
# Start application
|
||||
CMD ["node", "dist/main.js"]
|
||||
|
||||
Reference in New Issue
Block a user