fix(docker): force NODE_ENV=development in build stage to include devDependencies
Coolify auto-injects ARG NODE_ENV into all Dockerfile stages and passes NODE_ENV=production as a build arg. This causes npm ci to skip devDependencies (including typescript), making tsc not found (exit 127) at npm run build. Fix: prefix the npm ci call with NODE_ENV=development to override the injected env var only for the install step, ensuring TypeScript and other build tools are always installed. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
6fcb5cbc1d
commit
34afb8d729
1 changed files with 3 additions and 27 deletions
30
Dockerfile
30
Dockerfile
|
|
@ -6,10 +6,8 @@
|
|||
FROM node:22-bookworm-slim AS deps
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
# Install production dependencies only with cache mount
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
npm ci --omit=dev --prefer-offline
|
||||
|
||||
|
|
@ -19,20 +17,15 @@ RUN --mount=type=cache,target=/root/.npm \
|
|||
FROM node:22-bookworm-slim AS build
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
# Install all dependencies (including devDependencies)
|
||||
# Note: no --prefer-offline so npm always fetches from registry in CI/CD
|
||||
RUN npm ci
|
||||
# Force devDependencies: NODE_ENV=production (injected by Coolify as build arg)
|
||||
# would cause npm to skip devDeps, so we explicitly override here.
|
||||
RUN NODE_ENV=development npm ci
|
||||
|
||||
# Copy TypeScript config
|
||||
COPY tsconfig.json tsconfig.build.json ./
|
||||
|
||||
# Copy source code
|
||||
COPY src ./src
|
||||
|
||||
# Build TypeScript to JavaScript
|
||||
RUN npm run build
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
|
@ -40,12 +33,10 @@ RUN npm run build
|
|||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
FROM node:22-bookworm-slim AS runtime
|
||||
|
||||
# Set production environment
|
||||
ENV NODE_ENV=production
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install runtime dependencies and create non-root user
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
tini \
|
||||
|
|
@ -54,34 +45,19 @@ RUN apt-get update && \
|
|||
rm -rf /var/lib/apt/lists/* && \
|
||||
useradd --system --uid 1001 --create-home agenthub
|
||||
|
||||
# Copy production dependencies from deps stage
|
||||
COPY --from=deps --chown=agenthub:agenthub /app/node_modules ./node_modules
|
||||
|
||||
# Copy built application from build stage
|
||||
COPY --from=build --chown=agenthub:agenthub /app/dist ./dist
|
||||
|
||||
# Copy package.json for metadata
|
||||
COPY --chown=agenthub:agenthub package.json ./
|
||||
|
||||
# Copy Drizzle migrations (required for npm run migrate)
|
||||
COPY --chown=agenthub:agenthub drizzle ./drizzle
|
||||
COPY --chown=agenthub:agenthub drizzle.config.ts ./
|
||||
|
||||
# Copy migration and seed scripts
|
||||
COPY --chown=agenthub:agenthub scripts ./scripts
|
||||
|
||||
# Switch to non-root user
|
||||
USER agenthub
|
||||
|
||||
# Expose application port
|
||||
EXPOSE 3000
|
||||
|
||||
# Add healthcheck
|
||||
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \
|
||||
CMD curl -f http://127.0.0.1:3000/healthz || exit 1
|
||||
|
||||
# Use tini as init system for proper signal handling
|
||||
ENTRYPOINT ["/usr/bin/tini", "--"]
|
||||
|
||||
# Start the application
|
||||
CMD ["node", "dist/server.js"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue