[!!]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*
pnpm-debug.log*
# Next.js build output
.next
out
# Next.js
.next/
out/
# Production build
# Production
build
dist
# Environment variables
# Environment files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# IDE and editor files
# IDE
.vscode
.idea
*.swp
*.swo
*~
# OS generated files
# OS
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Git
@ -40,14 +35,23 @@ Thumbs.db
.gitignore
# Docker
Dockerfile
Dockerfile*
docker-compose*
.dockerignore
docker-compose.yml
# Documentation
README.md
docs/
*.md
# Tests
coverage/
.nyc_output
*.test.js
*.test.ts
*.spec.js
*.spec.ts
# Logs
logs
*.log
@ -59,10 +63,60 @@ pids
*.pid.lock
# 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
tmp
temp
tmp/
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
FROM node:22.18.0 AS base
# Use a smaller base image for the final runtime
FROM node:22.18.0-alpine AS base
# Rebuild the source code only when needed
# Build stage
FROM base AS builder
WORKDIR /app
# Install build dependencies for native modules
RUN apt-get update && apt-get install -y \
RUN apk add --no-cache \
python3 \
make \
g++ \
libsqlite3-dev \
&& rm -rf /var/lib/apt/lists/*
sqlite-dev \
ffmpeg-dev
# Install pnpm globally
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 ./
RUN pnpm install
RUN pnpm install
# Copy source code
COPY . .
# Rebuild better-sqlite3 to ensure native bindings are compiled correctly
RUN pnpm rebuild better-sqlite3 || npm 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
RUN pnpm rebuild better-sqlite3
# Build the application
RUN pnpm buildprod
# Production image, copy all the files and run next
# Production stage
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Install FFmpeg for media file analysis
RUN apt-get update && apt-get install -y \
# Install only runtime dependencies
RUN apk add --no-cache \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
sqlite \
&& rm -rf /var/cache/apk/*
RUN groupadd --system --gid 1001 nodejs
RUN useradd --system --uid 1001 --gid nodejs nextjs
# Create user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 --ingroup nodejs nextjs
# Create media directories
RUN mkdir -p /app/data /app/media
# Create necessary directories
RUN mkdir -p /app/data /app/media /app/public/thumbnails
# Ensure directories have correct permissions
RUN chown -R nextjs:nodejs /app/data /app/media
# Copy built application
# Copy only the necessary files from builder
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/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
# Rebuild native bindings for the production environment
RUN npm rebuild better-sqlite3
# Set up volume for persistent data
VOLUME ["/app/data", "/app/media"]
# Set correct permissions
RUN chown -R nextjs:nodejs /app/data /app/media /app/public
# Switch to non-root user
USER nextjs

Binary file not shown.

View File

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