FROM node:22-bookworm-slim AS metapi-builder WORKDIR /app RUN echo 'Acquire::http::Proxy "false";' > /etc/apt/apt.conf.d/99no-proxy && apt-get update && apt-get install -y --no-install-recommends python3 make g++ && rm -rf /var/lib/apt/lists/* ENV PYTHON=/usr/bin/python3 COPY package.json package-lock.json ./ RUN npm ci --ignore-scripts --no-audit --no-fund RUN npm rebuild esbuild sharp better-sqlite3 --no-audit --no-fund COPY . . RUN npm run build:web RUN npx tsc -p tsconfig.json --outDir dist --rootDir src --skipLibCheck --noEmit false 2>/dev/null; true RUN ls dist/server/index.js 2>/dev/null || (echo "=== Server build still missing, trying project reference build ===" && npx tsc -p tsconfig.server.json --skipLibCheck --noEmit false 2>/dev/null; true) RUN npm prune --omit=dev --no-audit --no-fund # ---- Final image ---- FROM ubuntu:24.04 ARG HTTP_PROXY ARG HTTPS_PROXY ARG ALL_PROXY ARG NO_PROXY ENV DEBIAN_FRONTEND=noninteractive ENV NODE_ENV=production ENV HTTP_PROXY=${HTTP_PROXY} ENV HTTPS_PROXY=${HTTPS_PROXY} ENV ALL_PROXY=${ALL_PROXY} ENV NO_PROXY=${NO_PROXY} # Install system deps: Node.js 22, supervisor RUN echo 'Acquire::http::Proxy "false";' > /etc/apt/apt.conf.d/99no-proxy && apt-get update && apt-get install -y --no-install-recommends \ curl ca-certificates gnupg \ supervisor \ && curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \ && apt-get install -y --no-install-recommends nodejs \ && rm -rf /var/lib/apt/lists/* # Install RTK from pre-built binary COPY rtk /usr/local/bin/rtk RUN chmod +x /usr/local/bin/rtk # Copy metapi (built) WORKDIR /app/metapi COPY --from=metapi-builder /app/dist ./dist COPY --from=metapi-builder /app/node_modules ./node_modules COPY --from=metapi-builder /app/package.json ./ COPY --from=metapi-builder /app/drizzle ./drizzle RUN mkdir -p data # Supervisor config RUN mkdir -p /var/log/supervisor COPY <<'SUPERVISOR' /etc/supervisor/conf.d/all.conf [supervisord] nodaemon=true user=root logfile=/var/log/supervisor/supervisord.log pidfile=/tmp/supervisord.pid [program:metapi] command=sh -c "node dist/server/db/migrate.js && node dist/server/index.js" directory=/app/metapi autorestart=true stdout_logfile=/var/log/supervisor/metapi.log stderr_logfile=/var/log/supervisor/metapi.err SUPERVISOR EXPOSE 4000 CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/all.conf"]