From c84de0f4f493f83ea372d5aa26092594c8b43c36 Mon Sep 17 00:00:00 2001 From: Paperclip FoundingEngineer Date: Sat, 2 May 2026 10:40:34 +0000 Subject: [PATCH] fix(agenthub): Compile migrations and expose postgres port for diagnosis Fixes BARAAA-64 DB migration and auth issues: - Update tsconfig.build.json to compile scripts/migrate.ts (was excluded) - Create entrypoint.sh to run migrations before server start - Update Dockerfile to build migrate.ts and use migration entrypoint - Expose postgres port 15432 temporarily for password diagnosis This ensures tables are created before app starts and allows connecting to postgres from host to diagnose 28P01 auth errors. Co-Authored-By: Paperclip --- Dockerfile | 17 ++++++++++++++--- compose.coolify.yml | 2 ++ scripts/entrypoint.sh | 8 ++++++++ tsconfig.build.json | 5 ++--- 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 scripts/entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 05e01cd..96d3fd3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,10 @@ RUN NODE_ENV=development npm ci COPY tsconfig.json tsconfig.build.json ./ COPY src ./src +# Copy migration script for compilation +COPY scripts/migrate.ts ./scripts/ + +# Build TypeScript to JavaScript (includes src and scripts/migrate.ts) RUN npm run build # ───────────────────────────────────────────────────────────────────────────── @@ -48,9 +52,16 @@ RUN apt-get update && \ COPY --from=deps --chown=agenthub:agenthub /app/node_modules ./node_modules COPY --from=build --chown=agenthub:agenthub /app/dist ./dist COPY --chown=agenthub:agenthub package.json ./ + +# Copy Drizzle migrations (required for migration runtime) COPY --chown=agenthub:agenthub drizzle ./drizzle COPY --chown=agenthub:agenthub drizzle.config.ts ./ -COPY --chown=agenthub:agenthub scripts ./scripts + +# Copy entrypoint script +COPY --chown=agenthub:agenthub scripts/entrypoint.sh /entrypoint.sh + +# Make entrypoint executable +RUN chmod +x /entrypoint.sh USER agenthub @@ -59,5 +70,5 @@ EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \ CMD curl -f http://127.0.0.1:3000/healthz || exit 1 -ENTRYPOINT ["/usr/bin/tini", "--"] -CMD ["node", "dist/server.js"] +# Use tini as init system for proper signal handling and run entrypoint +ENTRYPOINT ["/usr/bin/tini", "--", "/entrypoint.sh"] diff --git a/compose.coolify.yml b/compose.coolify.yml index a5be54b..07046b4 100644 --- a/compose.coolify.yml +++ b/compose.coolify.yml @@ -56,6 +56,8 @@ services: PGDATA: /var/lib/postgresql/data/pgdata volumes: - postgres_data_v2:/var/lib/postgresql/data + ports: + - '15432:5432' restart: unless-stopped healthcheck: test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-agenthub} -d ${POSTGRES_DB:-agenthub}'] diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh new file mode 100644 index 0000000..d575144 --- /dev/null +++ b/scripts/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +echo "[entrypoint] Running database migrations..." +node dist/scripts/migrate.js + +echo "[entrypoint] Starting application server..." +exec node dist/server.js diff --git a/tsconfig.build.json b/tsconfig.build.json index 8aa48a4..b5097cd 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,13 +2,12 @@ "extends": "./tsconfig.json", "compilerOptions": { "noEmit": false, - "rootDir": "src", "outDir": "dist", "module": "ESNext", "moduleResolution": "Bundler", "declaration": false, "sourceMap": true }, - "include": ["src/**/*"], - "exclude": ["node_modules", "dist", "test", "scripts", "vitest.config.ts"] + "include": ["src/**/*", "scripts/migrate.ts"], + "exclude": ["node_modules", "dist", "test", "vitest.config.ts"] }