nextav/Dockerfile

74 lines
1.7 KiB
Docker

# Use official Node.js runtime as the base image
FROM node:22.18.0 AS base
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
# Install build dependencies for native modules
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
libsqlite3-dev \
&& rm -rf /var/lib/apt/lists/*
# Install pnpm globally
RUN npm install -g pnpm
# Copy package files and install all dependencies (including dev dependencies)
COPY package.json package-lock.json ./
RUN pnpm install
# Copy source code
COPY . .
# Rebuild better-sqlite3 to ensure native bindings are compiled correctly
RUN pnpm rebuild better-sqlite3
# Ensure database file exists and has proper permissions
RUN touch /app/media.db && chmod 666 /app/media.db
# Create directories for media storage
RUN mkdir -p /app/data /app/media
# Build the application
RUN pnpm build
# 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 FFmpeg and FFprobe for thumbnail generation
RUN apt-get update && apt-get install -y \
ffmpeg \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd --system --gid 1001 nodejs
RUN useradd --system --uid 1001 --gid nodejs nextjs
# Create media directories
RUN mkdir -p /app/data /app/media
# Copy built application
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder /app/media.db ./media.db
# Set up volume for persistent data
VOLUME ["/app/data", "/app/media"]
# Switch to non-root user
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]