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
|
# Stage 1: Build the application
|
||||||
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
|
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -19,45 +8,40 @@ ENV NEXT_TELEMETRY_DISABLED=1
|
|||||||
# Copy package files
|
# Copy package files
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
|
|
||||||
# Install all dependencies (including devDependencies)
|
# Install dependencies
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build Next.js application
|
# Build Next.js application (static export to /app/out)
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 3: Production runtime
|
# Stage 2: Serve static files with nginx
|
||||||
FROM node:20-alpine AS runner
|
FROM nginx:alpine AS runner
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Set environment to production
|
# Copy custom nginx config for SPA routing
|
||||||
ENV NODE_ENV=production
|
RUN echo 'server { \
|
||||||
# Disable Next.js telemetry
|
listen 80; \
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
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
|
# Copy static files from builder
|
||||||
RUN addgroup --system --gid 1001 nodejs && \
|
COPY --from=builder /app/out /usr/share/nginx/html
|
||||||
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
|
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3000
|
EXPOSE 80
|
||||||
|
|
||||||
# Set environment variable for port
|
# Start nginx
|
||||||
ENV PORT=3000
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
ENV HOSTNAME="0.0.0.0"
|
|
||||||
|
|
||||||
# Start the application
|
|
||||||
CMD ["node", "server.js"]
|
|
||||||
|
|||||||
@@ -8,15 +8,11 @@ services:
|
|||||||
image: ghcr.io/retrozenith/tuxmate:latest
|
image: ghcr.io/retrozenith/tuxmate:latest
|
||||||
container_name: tuxmate
|
container_name: tuxmate
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:80"
|
||||||
environment:
|
|
||||||
- NODE_ENV=production
|
|
||||||
- PORT=3000
|
|
||||||
- NEXT_TELEMETRY_DISABLED=1
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000"]
|
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:80"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
start_period: 40s
|
start_period: 10s
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
// Use 'export' for static hosting (CF Pages), 'standalone' for Docker/self-hosting
|
output: 'export',
|
||||||
output: process.env.STATIC_EXPORT === 'true' ? 'export' : 'standalone',
|
|
||||||
images: {
|
images: {
|
||||||
unoptimized: true,
|
unoptimized: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"build:static": "STATIC_EXPORT=true next build",
|
|
||||||
"pages:build": "STATIC_EXPORT=true npm run build",
|
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
|
|||||||
Reference in New Issue
Block a user