agenthub/Dockerfile
Paperclip FoundingEngineer f490152172
Some checks are pending
CI / lint + typecheck + tests (push) Waiting to run
CI / docker build + push (push) Blocked by required conditions
fix(agenthub): Apply J5 deployment fixes discovered during LAN rollout
Five critical fixes discovered and patched on production (192.168.9.23)
during BARAAA-51 deployment, now committed to align repo with reality.

1. tsconfig.build.json: Add rootDir to fix build output path
   - Without rootDir, tsc compiled to dist/src/server.js
   - Dockerfile CMD expected dist/server.js
   - Now builds correctly to dist/server.js

2. Dockerfile: Correct CMD path back to dist/server.js
   - Reverts workaround commit 6d0515d
   - Now matches actual build output with rootDir fix

3. src/routes/sessions.ts: Fix API token prefix parsing
   - Old: split('_') failed because base64url can contain '_'
   - New: Extract prefix by fixed position (first 12 chars)
   - Prevents ~64% authentication failures

4. src/routes/rooms.ts: Add /api/v1 prefix to all routes
   - All 7 room endpoints now properly namespaced
   - Aligns with API versioning convention

5. .env.lan: Add POSTGRES_HOST and POSTGRES_PORT
   - Required for DB connection in Docker Compose
   - Without this, app tried localhost instead of postgres service

6. test/j5-messaging-validation.js: Fix validation script
   - Correct endpoint: /api/v1/agents/:id/tokens
   - Correct field: .secret (not .token)
   - Alexia role: admin (needed for room creation)

All fixes verified with clean build and dist/server.js output check.

Related: BARAAA-63, BARAAA-51

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-02 09:46:43 +00:00

87 lines
3.4 KiB
Docker

# syntax=docker/dockerfile:1.7
# ─────────────────────────────────────────────────────────────────────────────
# Stage 1: Dependencies (production only)
# ─────────────────────────────────────────────────────────────────────────────
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
# ─────────────────────────────────────────────────────────────────────────────
# Stage 2: Build
# ─────────────────────────────────────────────────────────────────────────────
FROM node:22-bookworm-slim AS build
WORKDIR /app
# Copy package files
COPY package.json package-lock.json ./
# Install all dependencies (including devDependencies) with cache mount
RUN --mount=type=cache,target=/root/.npm \
npm ci --prefer-offline
# Copy TypeScript config
COPY tsconfig.json tsconfig.build.json ./
# Copy source code
COPY src ./src
# Build TypeScript to JavaScript
RUN npm run build
# ─────────────────────────────────────────────────────────────────────────────
# Stage 3: Runtime
# ─────────────────────────────────────────────────────────────────────────────
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 \
ca-certificates \
curl && \
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"]