74 lines
1.9 KiB
Docker
74 lines
1.9 KiB
Docker
# Multi-stage production Dockerfile for LCC Table Tennis Booking
|
|
FROM node:22-slim AS base
|
|
|
|
# Install dependencies only when needed
|
|
FROM base AS deps
|
|
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /app
|
|
|
|
# Install dependencies based on the preferred package manager
|
|
COPY package.json package-lock.json* ./
|
|
RUN \
|
|
if [ -f package-lock.json ]; then npm ci --ignore-scripts; \
|
|
else echo "Lockfile not found." && exit 1; \
|
|
fi
|
|
|
|
# Rebuild the source code only when needed
|
|
FROM base AS builder
|
|
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Rebuild better-sqlite3 for Alpine Linux
|
|
RUN npm rebuild better-sqlite3
|
|
|
|
# Build the application
|
|
RUN npm run build
|
|
|
|
# Production image, copy all the files and run next
|
|
FROM base AS runner
|
|
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Create system user and group
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# Copy necessary files from builder stage
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
# Create public directory if it doesn't exist
|
|
RUN mkdir -p public
|
|
|
|
# Create directories for data and backups
|
|
RUN mkdir -p /app/data /app/backups /app/logs && \
|
|
chown -R nextjs:nodejs /app/data /app/backups /app/logs
|
|
|
|
# Create startup script
|
|
COPY --chown=nextjs:nodejs <<EOF /app/start.sh
|
|
#!/bin/sh
|
|
set -e
|
|
echo "🚀 Starting TT Booking Production..."
|
|
echo "🌟 Starting server..."
|
|
exec node server.js
|
|
EOF
|
|
|
|
RUN chmod +x /app/start.sh
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD curl -f http://localhost:3000/api/health || exit 1
|
|
|
|
CMD ["/app/start.sh"] |