This commit is contained in:
Matthias Hochmeister
2026-02-23 17:08:58 +01:00
commit f09748f4a1
97 changed files with 17729 additions and 0 deletions

69
backend/Dockerfile Normal file
View File

@@ -0,0 +1,69 @@
# ===========================
# Build Stage
# ===========================
FROM node:20-alpine AS builder
# Set working directory
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache python3 make g++
# Copy package files for dependency installation
COPY package*.json ./
# Install all dependencies (including devDependencies for building)
RUN npm ci
# Copy TypeScript configuration and source code
COPY tsconfig.json ./
COPY src ./src
# Build TypeScript to JavaScript
RUN npm run build
# Prune dev dependencies
RUN npm prune --production
# ===========================
# Production Stage
# ===========================
FROM node:20-alpine AS production
# Install wget for health checks
RUN apk add --no-cache wget
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Copy production node_modules from builder
COPY --from=builder /app/node_modules ./node_modules
# Copy compiled JavaScript from builder
COPY --from=builder /app/dist ./dist
# Copy database migrations (needed for runtime)
COPY --from=builder /app/src/database/migrations ./dist/database/migrations
# Change ownership to non-root user
RUN chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Expose application port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=40s \
CMD wget --quiet --tries=1 --spider http://localhost:3000/health || exit 1
# Start the application
CMD ["node", "dist/server.js"]