impoves docker

This commit is contained in:
2026-02-18 19:02:29 +01:00
parent 61545bcf1b
commit 9b783037ff
2 changed files with 35 additions and 13 deletions

9
backend/.dockerignore Normal file
View File

@@ -0,0 +1,9 @@
node_modules
dist
.env
.env.*
npm-debug.log*
*.log
.git
.gitignore
README.md

View File

@@ -1,28 +1,41 @@
FROM node:20-alpine # ── Build stage ──────────────────────────────────────────────────────────────
FROM node:20-alpine AS builder
# Install OpenSSL for Prisma # Install OpenSSL for Prisma client generation
RUN apk add --no-cache openssl RUN apk add --no-cache openssl
WORKDIR /app WORKDIR /app
# Copy package files # Install all dependencies (including devDependencies needed for build)
COPY package*.json ./ COPY package*.json ./
COPY prisma ./prisma/
# Install dependencies
RUN npm ci RUN npm ci
# Generate Prisma client # Generate Prisma client and compile TypeScript
COPY prisma ./prisma/
RUN npx prisma generate RUN npx prisma generate
# Copy source code
COPY . . COPY . .
# Build TypeScript
RUN npm run build RUN npm run build
# Expose port # ── Production stage ──────────────────────────────────────────────────────────
FROM node:20-alpine AS production
# Install OpenSSL required by Prisma at runtime
RUN apk add --no-cache openssl
WORKDIR /app
# Install production dependencies only
COPY package*.json ./
RUN npm ci --omit=dev
# Copy Prisma schema + generated client from builder
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
# Copy compiled application
COPY --from=builder /app/dist ./dist
EXPOSE 3001 EXPOSE 3001
# Start the application CMD ["sh", "-c", "npx prisma migrate deploy && node dist/index.js"]
CMD ["sh", "-c", "npx prisma migrate deploy && npm start"]