* Fix ActivityFeed: Remove dynamic import that was causing it to disappear in production * Fix ActivityFeed hydration error: Move localStorage read to useEffect to prevent server/client mismatch * Update Node.js version to 25 in Gitea workflows - Fix EBADENGINE error for camera-controls@3.1.2 which requires Node.js >=22 - Update production-deploy.yml, dev-deploy.yml, and ci-cd-with-gitea-vars.yml.disabled - Node.js v25 matches local development environment * Update Dockerfile to use Node.js 25 - Update base image from node:20 to node:25 - Matches Gitea workflow configuration and camera-controls@3.1.2 requirements * Fix production deployment: Start database dependencies - Remove --no-deps flag which prevented postgres and redis from starting - Remove --build flag as image is already built in previous step - This fixes 'Can't reach database server at postgres:5432' error * Fix postgres health check in production - Remove init-db.sql volume mount (not available in CI/CD environment) - Init script not needed as Prisma handles schema migrations - Postgres will initialize empty database automatically * Fix cache permission error in Docker container - Create cache directories AFTER copying standalone files - Create both fetch-cache and images subdirectories - Set proper ownership for nextjs user - Fixes EACCES permission denied errors for prerender cache * Fix German jogging fallback text * Use Directus content in production * fix: Security vulnerability - block malicious file requests * fix: Switch projects to Directus, add security fixes and example projects
106 lines
3.7 KiB
Docker
106 lines
3.7 KiB
Docker
# Multi-stage build for optimized production image
|
|
FROM node:25 AS base
|
|
|
|
# Install dependencies only when needed
|
|
FROM base AS deps
|
|
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /app
|
|
|
|
# Copy package files first for better caching
|
|
COPY package.json package-lock.json* ./
|
|
RUN npm ci --only=production && npm cache clean --force
|
|
|
|
# Rebuild the source code only when needed
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
|
|
# Copy package files first for better caching
|
|
COPY package.json package-lock.json* ./
|
|
|
|
# Install all dependencies (including dev dependencies for build)
|
|
# Use npm ci with cache mount for faster builds
|
|
RUN --mount=type=cache,target=/root/.npm \
|
|
npm ci
|
|
|
|
# Copy Prisma schema first (for better caching)
|
|
COPY prisma ./prisma
|
|
|
|
# Generate Prisma client (cached if schema unchanged)
|
|
RUN npx prisma generate
|
|
|
|
# Copy source code (this invalidates cache when code changes)
|
|
COPY . .
|
|
|
|
# Build the application
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV NODE_ENV=production
|
|
RUN npm run build
|
|
|
|
# Verify standalone output was created and show structure for debugging
|
|
RUN if [ ! -d .next/standalone ]; then \
|
|
echo "ERROR: .next/standalone directory not found!"; \
|
|
echo "Contents of .next directory:"; \
|
|
ls -la .next/ || true; \
|
|
echo "Checking if standalone exists in different location:"; \
|
|
find .next -name "standalone" -type d || true; \
|
|
exit 1; \
|
|
fi && \
|
|
echo "✅ Standalone output found" && \
|
|
ls -la .next/standalone/ && \
|
|
echo "Standalone structure:" && \
|
|
find .next/standalone -type f -name "server.js" || echo "server.js not found in standalone"
|
|
|
|
# Production image, copy all the files and run next
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Install curl for health checks
|
|
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create a non-root user
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# Copy the built application
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# Automatically leverage output traces to reduce image size
|
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
|
# Copy standalone output (contains server.js and all dependencies)
|
|
# The standalone output structure is: .next/standalone/ (not .next/standalone/app/)
|
|
# Next.js creates: .next/standalone/server.js, .next/standalone/.next/, .next/standalone/node_modules/
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
# Create cache directories with correct permissions AFTER copying standalone
|
|
RUN mkdir -p .next/cache/fetch-cache .next/cache/images && \
|
|
chown -R nextjs:nodejs .next/cache
|
|
|
|
# Copy Prisma files
|
|
COPY --from=builder /app/prisma ./prisma
|
|
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
|
COPY --from=builder /app/node_modules/prisma ./node_modules/prisma
|
|
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
|
|
|
# Create scripts directory and copy start script AFTER standalone to ensure it's not overwritten
|
|
RUN mkdir -p scripts && chown nextjs:nodejs scripts
|
|
COPY --from=builder --chown=nextjs:nodejs /app/scripts/start-with-migrate.js ./scripts/start-with-migrate.js
|
|
|
|
# Note: Environment variables should be passed via docker-compose or runtime environment
|
|
# DO NOT copy .env files into the image for security reasons
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:3000/api/health || exit 1
|
|
|
|
CMD ["node", "scripts/start-with-migrate.js"] |