2d31c49235
- Updated Dockerfile for production to ensure proper database permissions and improved startup script. - Removed outdated PRODUCTION_README.md and consolidated relevant information into other documentation. - Enhanced deploy.sh script to fix database permissions and streamline deployment process. - Modified docker-compose configuration to use a dedicated production file and adjusted port mappings. - Removed legacy docker-compose.yml file to avoid confusion. - Improved session management by refining secure cookie settings based on environment variables. - Deleted obsolete Nginx configuration and old seed scripts to clean up the project structure. - Updated database setup scripts to reflect new structure and removed old seed data scripts. - Adjusted reset-db script to use environment variable for database path. - Enhanced setup-database script to provide dynamic admin credentials in the summary. - Removed unnecessary backup file for SQLite database.
81 lines
2.2 KiB
Docker
81 lines
2.2 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..."
|
|
|
|
# Ensure database directory has proper permissions
|
|
if [ -d "/app/data" ]; then
|
|
echo "📁 Setting database permissions..."
|
|
chmod -R 755 /app/data /app/backups /app/logs 2>/dev/null || true
|
|
if [ -f "/app/data/sqlite.db" ]; then
|
|
chmod 644 /app/data/sqlite.db 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
echo "🌟 Starting server..."
|
|
exec node server.js
|
|
EOF
|
|
|
|
RUN chmod +x /app/start.sh
|
|
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"] |