feat: add Docker containerization (Dockerfile, compose, dockerignore)
Multi-stage build: frontend (Vite) + backend (TypeScript) in one container. Production image based on node:20-alpine with health check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
# ============================================================
|
||||
# Stage 1: Build Frontend (React + Vite)
|
||||
# ============================================================
|
||||
FROM node:20-alpine AS build-frontend
|
||||
|
||||
WORKDIR /app/frontend
|
||||
COPY frontend/package.json frontend/package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY frontend/ ./
|
||||
RUN npm run build
|
||||
# Output: /app/frontend/../backend/public → /app/backend/public
|
||||
|
||||
# ============================================================
|
||||
# Stage 2: Build Backend (TypeScript → JavaScript)
|
||||
# ============================================================
|
||||
FROM node:20-alpine AS build-backend
|
||||
|
||||
WORKDIR /app/backend
|
||||
COPY backend/package.json backend/package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY backend/ ./
|
||||
RUN npx tsc
|
||||
|
||||
# ============================================================
|
||||
# Stage 3: Production Image
|
||||
# ============================================================
|
||||
FROM node:20-alpine AS production
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Nur Production-Dependencies installieren
|
||||
COPY backend/package.json backend/package-lock.json ./
|
||||
RUN npm ci --omit=dev && npm cache clean --force
|
||||
|
||||
# Compiled Backend
|
||||
COPY --from=build-backend /app/backend/dist ./dist
|
||||
|
||||
# Frontend Build (statische Dateien)
|
||||
COPY --from=build-frontend /app/backend/public ./public
|
||||
|
||||
# Non-root User
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
USER appuser
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3001
|
||||
|
||||
EXPOSE 3001
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||
CMD wget -qO- http://localhost:3001/health || exit 1
|
||||
|
||||
CMD ["node", "dist/index.js"]
|
||||
Reference in New Issue
Block a user