Dockerfile
Rama main · réplica de lectura del repositorio original.
# Stage 1: deps
FROM node:22-bookworm-slim AS deps
# Native module build dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 make g++ \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package.json package-lock.json ./
ENV npm_config_build_from_source=true
RUN npm ci
RUN npm rebuild sqlite3 --build-from-source
# Stage 2: builder
FROM node:22-bookworm-slim AS builder
WORKDIR /app
ARG APP_VERSION=dev
ARG APP_COMMIT_SHA=local
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
ENV APP_VERSION=$APP_VERSION
ENV APP_COMMIT_SHA=$APP_COMMIT_SHA
ENV NEXT_PUBLIC_APP_VERSION=$APP_VERSION
ENV NEXT_PUBLIC_APP_COMMIT_SHA=$APP_COMMIT_SHA
RUN npm run build
# Stage 3: runner
FROM node:22-bookworm-slim AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ARG APP_VERSION=dev
ARG APP_COMMIT_SHA=local
ENV APP_VERSION=$APP_VERSION
ENV APP_COMMIT_SHA=$APP_COMMIT_SHA
ENV NEXT_PUBLIC_APP_VERSION=$APP_VERSION
ENV NEXT_PUBLIC_APP_COMMIT_SHA=$APP_COMMIT_SHA
# iputils-ping is required for ping-type monitors. Debian's package grants
# the binary cap_net_raw via setcap, so it works for the non-root nextjs user.
RUN apt-get update \
&& apt-get install -y --no-install-recommends iputils-ping \
&& rm -rf /var/lib/apt/lists/*
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy standalone build
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
# Migration SQL files are read from disk at runtime (not bundled by the
# Next.js tracer), so they must be copied explicitly. The migrate CLI is
# included too, so `docker exec` can run status/up/down inside the container.
COPY --from=builder --chown=nextjs:nodejs /app/migrations ./migrations
COPY --from=builder --chown=nextjs:nodejs /app/scripts ./scripts
# The Next standalone output already includes the sqlite/sqlite3 runtime modules
# required by the app, so no extra native dependency copies are needed here.
# Data directory for SQLite
RUN mkdir -p /data && chown nextjs:nodejs /data
USER nextjs
# Environment variables (override at runtime)
ENV PORT=4000
ENV HOSTNAME=0.0.0.0
ENV DATABASE_PATH=/data/logs.db
EXPOSE 4000
VOLUME ["/data"]
CMD ["node", "server.js"]