mirror of
https://github.com/abusoww/tuxmate.git
synced 2026-04-17 15:53:24 +02:00
fix: use static export for both CF Pages and Docker
- Set output: 'export' in next.config.ts (creates /out directory) - Replaced Node.js standalone Dockerfile with nginx serving static files - Updated docker-compose.yml for nginx (port 80) - Both CF Pages and Docker now use the same static build
This commit is contained in:
68
Dockerfile
68
Dockerfile
@@ -1,15 +1,4 @@
|
||||
# Stage 1: Install dependencies
|
||||
FROM node:20-alpine AS deps
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci --only=production && \
|
||||
npm cache clean --force
|
||||
|
||||
# Stage 2: Build the application
|
||||
# Stage 1: Build the application
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
|
||||
@@ -19,45 +8,40 @@ ENV NEXT_TELEMETRY_DISABLED=1
|
||||
# Copy package files
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
# Install all dependencies (including devDependencies)
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build Next.js application
|
||||
# Build Next.js application (static export to /app/out)
|
||||
RUN npm run build
|
||||
|
||||
# Stage 3: Production runtime
|
||||
FROM node:20-alpine AS runner
|
||||
WORKDIR /app
|
||||
# Stage 2: Serve static files with nginx
|
||||
FROM nginx:alpine AS runner
|
||||
|
||||
# Set environment to production
|
||||
ENV NODE_ENV=production
|
||||
# Disable Next.js telemetry
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
# Copy custom nginx config for SPA routing
|
||||
RUN echo 'server { \
|
||||
listen 80; \
|
||||
listen [::]:80; \
|
||||
root /usr/share/nginx/html; \
|
||||
index index.html; \
|
||||
location / { \
|
||||
try_files $uri $uri/ $uri.html /index.html; \
|
||||
} \
|
||||
location /_next/static/ { \
|
||||
expires 1y; \
|
||||
add_header Cache-Control "public, immutable"; \
|
||||
} \
|
||||
gzip on; \
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript; \
|
||||
}' > /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Create non-root user for security
|
||||
RUN addgroup --system --gid 1001 nodejs && \
|
||||
adduser --system --uid 1001 nextjs
|
||||
|
||||
# Copy necessary files from builder
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
|
||||
# Set correct permissions
|
||||
RUN chown -R nextjs:nodejs /app
|
||||
|
||||
# Switch to non-root user
|
||||
USER nextjs
|
||||
# Copy static files from builder
|
||||
COPY --from=builder /app/out /usr/share/nginx/html
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
EXPOSE 80
|
||||
|
||||
# Set environment variable for port
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
# Start the application
|
||||
CMD ["node", "server.js"]
|
||||
# Start nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
Reference in New Issue
Block a user