Files
timetracker/Dockerfile
Felix Schlusche bad91636b5
All checks were successful
Build and Push Docker Image / build (push) Successful in 47s
feat: upgrade Node.js version to 20-alpine in Dockerfile for improved performance and compatibility
2025-10-31 18:20:31 +01:00

69 lines
1.7 KiB
Docker

# Multi-stage Dockerfile for Zeiterfassung Application
# Optimized for production deployment
# ============================================
# Stage 1: Build - Install dependencies
# ============================================
FROM node:20-alpine AS builder
# Add metadata
LABEL maintainer="timetracker"
LABEL description="Time tracking application with persistent timer and German break rules"
WORKDIR /app
# Install build dependencies for native modules (better-sqlite3)
RUN apk add --no-cache python3 make g++
# Copy package files for dependency installation
COPY package*.json ./
# Install only production dependencies
RUN npm install --omit=dev && \
npm cache clean --force
# ============================================
# Stage 2: Runtime - Slim production image
# ============================================
FROM node:20-alpine
WORKDIR /app
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Copy dependencies from builder stage
COPY --from=builder /app/node_modules ./node_modules
# Copy application files
COPY server.js ./
COPY schema.sql ./
COPY package*.json ./
COPY public ./public
# Create data directory for SQLite database
RUN mkdir -p /app/db
# Expose the application port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Set environment variables
ENV NODE_ENV=production \
PORT=3000
# Build arguments for version info
ARG COMMIT_HASH=unknown
ARG BUILD_DATE=unknown
ENV COMMIT_HASH=${COMMIT_HASH}
ENV BUILD_DATE=${BUILD_DATE}
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Run the application
CMD ["node", "server.js"]