[!!]refactor: optimize Docker configuration and update .dockerignore

- Changed base image in Dockerfile to a smaller Alpine version for reduced size.
- Updated package installation commands to use Alpine's package manager.
- Enhanced .dockerignore to exclude additional files and directories, improving build efficiency.
- Added new entries for media, database, and test files to .dockerignore.
- Adjusted docker-compose.yml to use a simplified image name for clarity.
This commit is contained in:
tigeren 2025-08-30 20:12:15 +00:00
parent 9ca11a8c6d
commit 0c8cb78ad2
4 changed files with 98 additions and 52 deletions

View File

@ -5,34 +5,29 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
pnpm-debug.log* pnpm-debug.log*
# Next.js build output # Next.js
.next .next/
out out/
# Production build # Production
build
dist dist
# Environment variables # Environment files
.env .env
.env.local .env.local
.env.development.local .env.development.local
.env.test.local .env.test.local
.env.production.local .env.production.local
# IDE and editor files # IDE
.vscode .vscode
.idea .idea
*.swp *.swp
*.swo *.swo
*~
# OS generated files # OS
.DS_Store .DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db Thumbs.db
# Git # Git
@ -40,14 +35,23 @@ Thumbs.db
.gitignore .gitignore
# Docker # Docker
Dockerfile Dockerfile*
docker-compose*
.dockerignore .dockerignore
docker-compose.yml
# Documentation # Documentation
README.md README.md
docs/
*.md *.md
# Tests
coverage/
.nyc_output
*.test.js
*.test.ts
*.spec.js
*.spec.ts
# Logs # Logs
logs logs
*.log *.log
@ -59,10 +63,60 @@ pids
*.pid.lock *.pid.lock
# Coverage directory used by tools like istanbul # Coverage directory used by tools like istanbul
coverage coverage/
# Dependency directories
jspm_packages/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
# Storybook build outputs
.out
.storybook-out
# Temporary folders # Temporary folders
tmp tmp/
temp temp/
public/thumbnails # Media files (these will be mounted as volumes)
data/
media/
public/thumbnails/
# Database files
*.db
*.sqlite
*.sqlite3
# Backup files
*.bak
*.backup

View File

@ -1,75 +1,67 @@
# Use official Node.js runtime as the base image # Use a smaller base image for the final runtime
FROM node:22.18.0 AS base FROM node:22.18.0-alpine AS base
# Rebuild the source code only when needed # Build stage
FROM base AS builder FROM base AS builder
WORKDIR /app WORKDIR /app
# Install build dependencies for native modules # Install build dependencies for native modules
RUN apt-get update && apt-get install -y \ RUN apk add --no-cache \
python3 \ python3 \
make \ make \
g++ \ g++ \
libsqlite3-dev \ sqlite-dev \
&& rm -rf /var/lib/apt/lists/* ffmpeg-dev
# Install pnpm globally # Install pnpm globally
RUN npm install -g pnpm RUN npm install -g pnpm
# Copy package files and install all dependencies (including dev dependencies) # Copy package files and install all dependencies
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
RUN pnpm install RUN pnpm install
# Copy source code # Copy source code
COPY . . COPY . .
# Rebuild better-sqlite3 to ensure native bindings are compiled correctly # Rebuild better-sqlite3 to ensure native bindings are compiled correctly
RUN pnpm rebuild better-sqlite3 || npm rebuild better-sqlite3 RUN pnpm rebuild better-sqlite3
# Verify native bindings are compiled
RUN find /app/node_modules -name "better_sqlite3.node" -type f
# Database file will be created at runtime via docker-compose
# Create directories for media storage
RUN mkdir -p /app/data /app/media
# Build the application # Build the application
RUN pnpm buildprod RUN pnpm buildprod
# Production image, copy all the files and run next # Production stage
FROM base AS runner FROM base AS runner
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_TELEMETRY_DISABLED=1
# Install FFmpeg for media file analysis # Install only runtime dependencies
RUN apt-get update && apt-get install -y \ RUN apk add --no-cache \
ffmpeg \ ffmpeg \
&& rm -rf /var/lib/apt/lists/* sqlite \
&& rm -rf /var/cache/apk/*
RUN groupadd --system --gid 1001 nodejs # Create user
RUN useradd --system --uid 1001 --gid nodejs nextjs RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 --ingroup nodejs nextjs
# Create media directories # Create necessary directories
RUN mkdir -p /app/data /app/media RUN mkdir -p /app/data /app/media /app/public/thumbnails
# Ensure directories have correct permissions # Copy only the necessary files from builder
RUN chown -R nextjs:nodejs /app/data /app/media
# Copy built application
COPY --from=builder --chown=nextjs:nodejs /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy node_modules to ensure native bindings are available
# Copy the entire node_modules to ensure all native bindings are available
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
# Rebuild native bindings for the production environment # Rebuild native bindings for the production environment
RUN npm rebuild better-sqlite3 RUN npm rebuild better-sqlite3
# Set up volume for persistent data # Set correct permissions
VOLUME ["/app/data", "/app/media"] RUN chown -R nextjs:nodejs /app/data /app/media /app/public
# Switch to non-root user # Switch to non-root user
USER nextjs USER nextjs

Binary file not shown.

View File

@ -2,7 +2,7 @@ version: '3.8'
services: services:
nextav: nextav:
image: ${REGISTRY_URL:-192.168.2.212:3000}/${IMAGE_NAME:-tigeren/nextav}:${IMAGE_TAG:-latest} image: nextav:optimized
container_name: nextav-app container_name: nextav-app
restart: unless-stopped restart: unless-stopped
ports: ports: