refactor: Optimize Docker build process, switch to @node-rs/bcrypt, and streamline compose.yaml by removing external services.
This commit is contained in:
parent
18660fa364
commit
c1254520b4
6 changed files with 218 additions and 405 deletions
|
|
@ -1,35 +1,14 @@
|
|||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install build dependencies for native modules (bcrypt, prisma)
|
||||
RUN apk add --no-cache python3 make g++
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
COPY pnpm-lock.yaml* ./
|
||||
|
||||
# Install pnpm and dependencies with build scripts enabled
|
||||
RUN npm install -g pnpm && \
|
||||
pnpm install --frozen-lockfile --ignore-scripts=false
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Generate Prisma client
|
||||
RUN pnpm prisma:generate
|
||||
|
||||
# Build application
|
||||
RUN pnpm build
|
||||
|
||||
# Production stage
|
||||
FROM node:20-alpine AS production
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install build dependencies for native modules (bcrypt, prisma)
|
||||
RUN apk add --no-cache python3 make g++
|
||||
# Install dependencies ทั้ง runtime และ build
|
||||
RUN apk add --no-cache \
|
||||
python3 \
|
||||
make \
|
||||
g++ \
|
||||
openssl-dev \
|
||||
libstdc++
|
||||
|
||||
# Install pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
|
@ -38,27 +17,28 @@ RUN npm install -g pnpm
|
|||
COPY package*.json ./
|
||||
COPY pnpm-lock.yaml* ./
|
||||
|
||||
# Install production dependencies with build scripts enabled
|
||||
RUN pnpm install --frozen-lockfile --ignore-scripts=false
|
||||
# Install dependencies
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Copy prisma schema and generate client
|
||||
COPY --from=builder /app/prisma ./prisma
|
||||
# Copy prisma schema
|
||||
COPY prisma ./prisma
|
||||
|
||||
# Generate Prisma client
|
||||
RUN pnpm prisma:generate
|
||||
|
||||
# Copy built files from builder
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY --from=builder /app/public ./public
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build application
|
||||
RUN pnpm build
|
||||
|
||||
# Set environment
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=4000
|
||||
|
||||
# Expose port
|
||||
EXPOSE 4000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:4000/health || exit 1
|
||||
|
||||
# Start application
|
||||
CMD ["node", "dist/server.js"]
|
||||
CMD ["npm", "start"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue