feat(docker): bring AITM services into the compose stack (+ mcp/gitnexus Dockerfiles)
aitm-api, aitm-mcp, and gitnexus now build and run healthy in the same docker-compose stack as gitgram Postgres+Redis. - NEW aitimemachine/mcp/Dockerfile — multi-stage; builds gitnexus-shared, gitnexus (native tree-sitter), the root @gitgram/timemachine lib (rewritten to file:.. + --install-links so file: engine deps are copied, not symlinked), then the mcp server; runtime starts HTTP transport (node dist/index.js --transport http). - NEW aitimemachine/gitnexus/Dockerfile — multi-stage (python3/make/g++ for tree-sitter); builds gitnexus-shared then gitnexus; serve on 0.0.0.0:3010. - compose: fix build contexts to the aitimemachine root for aitm-api, aitm-mcp, gitnexus (so file:../ engine siblings resolve); gitnexus host port 3010->13010 (stray host process owned :3010; internal port unchanged). - scripts/build-engines.sh: npm install before TS engine build when node_modules absent. - api-server: regenerate stale package-lock; declare ioredis as optionalDependency and drop the @ts-ignore in providerHealthService (typed dynamic import, tsc clean). Verified: aitm-api :3001/health, aitm-mcp :3003/health, gitnexus :13010/api/health all 200 healthy. aitm-website needs a Clerk key; context7 service def is pre-existing-broken. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
76d8f69185
commit
3408f0c873
808
aitimemachine/api-server/package-lock.json
generated
808
aitimemachine/api-server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -56,5 +56,8 @@
|
||||
"tsx": "^4.6.0",
|
||||
"typescript": "^5.3.0",
|
||||
"vitest": "^4.0.18"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"ioredis": "^5.11.1"
|
||||
}
|
||||
}
|
||||
|
||||
89
aitimemachine/gitnexus/Dockerfile
Normal file
89
aitimemachine/gitnexus/Dockerfile
Normal file
@ -0,0 +1,89 @@
|
||||
# syntax=docker/dockerfile:1.7
|
||||
#
|
||||
# GitNexus — code intelligence HTTP/MCP server (production image).
|
||||
#
|
||||
# Build context MUST be the aitimemachine root, because gitnexus' build.js
|
||||
# compiles and inlines the sibling `gitnexus-shared` package resolved via
|
||||
# `file:../gitnexus-shared`:
|
||||
#
|
||||
# docker build -f gitnexus/Dockerfile -t gitnexus .
|
||||
#
|
||||
# Stage 1 (builder) compiles the native tree-sitter grammars + the TS library.
|
||||
# Stage 2 (runtime) runs the CLI `serve` command over HTTP on port 3010.
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# Stage 1: builder
|
||||
# node:22 (gitnexus requires node >=22) + python3 / make / g++ for the native
|
||||
# tree-sitter grammar builds (node-gyp). Mirrors gitnexus/Dockerfile.test.
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
FROM node:22-bookworm-slim AS builder
|
||||
|
||||
RUN set -eux; \
|
||||
apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
python3 \
|
||||
make \
|
||||
g++; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# gitnexus' build.js runs tsc with cwd=gitnexus-shared, so the shared package
|
||||
# needs its own node_modules/.bin/tsc. Copy both engine sources.
|
||||
COPY gitnexus-shared ./gitnexus-shared
|
||||
COPY gitnexus ./gitnexus
|
||||
|
||||
# 1. gitnexus-shared deps (provides tsc for build.js step 1).
|
||||
RUN set -eux; \
|
||||
cd /app/gitnexus-shared; \
|
||||
npm install --no-audit --no-fund
|
||||
|
||||
# 2. gitnexus deps — native tree-sitter grammars compile during install via
|
||||
# node-gyp; rebuild any that need an explicit pass (see Dockerfile.test).
|
||||
RUN set -eux; \
|
||||
cd /app/gitnexus; \
|
||||
npm install --no-audit --no-fund --ignore-scripts; \
|
||||
npm rebuild 2>&1 || true; \
|
||||
npm rebuild tree-sitter-swift 2>&1 || true; \
|
||||
if [ -d node_modules/tree-sitter-kotlin ]; then \
|
||||
(cd node_modules/tree-sitter-kotlin && npx --yes node-gyp rebuild 2>&1 || true); \
|
||||
fi
|
||||
|
||||
# 3. Build the TS library (compiles gitnexus-shared + gitnexus, inlines the
|
||||
# shared dist). gitnexus-web is absent from the context → that step is
|
||||
# skipped by build.js, and run the grammar postinstall builder explicitly.
|
||||
RUN set -eux; \
|
||||
cd /app/gitnexus; \
|
||||
node scripts/build-tree-sitter-grammars.cjs 2>&1 || true; \
|
||||
node scripts/build.js
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# Stage 2: runtime
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
FROM node:22-bookworm-slim AS runtime
|
||||
|
||||
ENV NODE_ENV=production \
|
||||
PORT=3010
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# The runtime serves via `tsx src/cli/index.ts serve`, so ship the full source
|
||||
# tree + node_modules (tsx + native grammars) from the builder.
|
||||
COPY --from=builder /app/gitnexus ./gitnexus
|
||||
COPY --from=builder /app/gitnexus-shared ./gitnexus-shared
|
||||
|
||||
RUN chown -R node:node /app
|
||||
USER node
|
||||
|
||||
WORKDIR /app/gitnexus
|
||||
|
||||
EXPOSE 3010
|
||||
|
||||
# gitnexus exposes /api/health; the compose healthcheck tolerates other paths.
|
||||
HEALTHCHECK --interval=20s --timeout=5s --start-period=20s --retries=5 \
|
||||
CMD node -e "require('http').get('http://127.0.0.1:'+(process.env.PORT||3010)+'/api/health',r=>process.exit(r.statusCode<500?0:1)).on('error',()=>process.exit(1))"
|
||||
|
||||
# serve defaults to port 4747 / host localhost; bind 0.0.0.0 on PORT for the
|
||||
# container so the published port and healthcheck reach it.
|
||||
CMD ["sh", "-c", "npx tsx src/cli/index.ts serve --port ${PORT:-3010} --host 0.0.0.0"]
|
||||
113
aitimemachine/mcp/Dockerfile
Normal file
113
aitimemachine/mcp/Dockerfile
Normal file
@ -0,0 +1,113 @@
|
||||
# syntax=docker/dockerfile:1.7
|
||||
#
|
||||
# AITM MCP server — production image.
|
||||
#
|
||||
# Build context MUST be the aitimemachine root (the dir containing the root
|
||||
# @gitgram/timemachine package + the gitnexus / gitnexus-shared engine repos),
|
||||
# because the mcp server resolves several siblings via `file:../` references:
|
||||
# - @gitgram/timemachine → the repo root package (NOT published to npm)
|
||||
# - gitnexus → file:../gitnexus
|
||||
# - gitnexus-shared → file:../gitnexus-shared
|
||||
#
|
||||
# docker build -f mcp/Dockerfile -t aitm-mcp .
|
||||
#
|
||||
# Stage 1 (builder) compiles gitnexus-shared, gitnexus (native tree-sitter),
|
||||
# the root @gitgram/timemachine library, then the mcp server itself.
|
||||
# Stage 2 (runtime) ships only the built artifacts on a slim base.
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# Stage 1: builder
|
||||
# node:20 + python3 / make / g++ for gitnexus' native tree-sitter grammars.
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
FROM node:20-bookworm-slim AS builder
|
||||
|
||||
RUN set -eux; \
|
||||
apt-get -o Acquire::Check-Valid-Until=false update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
python3 \
|
||||
make \
|
||||
g++; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the engine sources the mcp build depends on (siblings + root package).
|
||||
# .dockerignore strips node_modules/dist/etc so everything is built from source.
|
||||
COPY gitnexus-shared ./gitnexus-shared
|
||||
COPY gitnexus ./gitnexus
|
||||
COPY package.json ./package.json
|
||||
COPY tsconfig*.json ./
|
||||
COPY src ./src
|
||||
COPY mcp ./mcp
|
||||
|
||||
# 1. gitnexus-shared: needs its own tsc (gitnexus' build.js runs tsc with
|
||||
# cwd=gitnexus-shared, resolving node_modules/.bin/tsc there).
|
||||
RUN set -eux; \
|
||||
cd /app/gitnexus-shared; \
|
||||
npm install --no-audit --no-fund
|
||||
|
||||
# 2. gitnexus: install deps (native tree-sitter compiles via node-gyp during
|
||||
# install) then build (build.js compiles gitnexus-shared + gitnexus and
|
||||
# inlines the shared dist). gitnexus-web is absent → that step is skipped.
|
||||
RUN set -eux; \
|
||||
cd /app/gitnexus; \
|
||||
npm install --no-audit --no-fund; \
|
||||
npm rebuild 2>&1 || true; \
|
||||
node scripts/build.js
|
||||
|
||||
# 3. Root @gitgram/timemachine library (tsc → lib/). This is the package the
|
||||
# mcp server imports as "@gitgram/timemachine"; it is not on the registry.
|
||||
# The root has pre-existing type errors in files the mcp never loads at
|
||||
# runtime (api-server.ts, server/cli-endpoints.ts). tsc has noEmitOnError
|
||||
# unset, so it still emits lib/ JS — tolerate the non-zero exit, then assert
|
||||
# the runtime entrypoints the mcp imports actually compiled.
|
||||
RUN set -eux; \
|
||||
cd /app; \
|
||||
npm install --no-audit --no-fund --ignore-scripts; \
|
||||
(npx tsc || true); \
|
||||
test -f lib/core/index.js; \
|
||||
test -f lib/server/session-server.js
|
||||
|
||||
# 4. mcp server: rewrite the unpublished @gitgram/timemachine dep to a local
|
||||
# file: ref, then install with --install-links so npm COPIES the file: engine
|
||||
# deps (gitnexus, gitnexus-shared, @gitgram/timemachine root) into
|
||||
# mcp/node_modules as real, self-contained directories (instead of symlinks
|
||||
# into sibling dirs) — making mcp/node_modules the only thing the runtime
|
||||
# stage needs. better-sqlite3 (a root-pkg dep) compiles here via node-gyp.
|
||||
# Finally compile the mcp TS (tsc).
|
||||
RUN set -eux; \
|
||||
cd /app/mcp; \
|
||||
node -e "const fs=require('fs');const p=require('./package.json');p.dependencies['@gitgram/timemachine']='file:..';fs.writeFileSync('package.json',JSON.stringify(p,null,2));"; \
|
||||
npm install --no-audit --no-fund --install-links; \
|
||||
npm run build
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# Stage 2: runtime
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
FROM node:20-bookworm-slim AS runtime
|
||||
|
||||
ENV NODE_ENV=production \
|
||||
PORT=3003
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# mcp build output + its resolved node_modules (which already contains the
|
||||
# copied file: engine deps and the npm-installed siblings).
|
||||
COPY --from=builder /app/mcp/dist ./mcp/dist
|
||||
COPY --from=builder /app/mcp/node_modules ./mcp/node_modules
|
||||
COPY --from=builder /app/mcp/package.json ./mcp/package.json
|
||||
|
||||
RUN chown -R node:node /app
|
||||
USER node
|
||||
|
||||
WORKDIR /app/mcp
|
||||
|
||||
EXPOSE 3003
|
||||
|
||||
# /health is unauthenticated on the HTTP transport.
|
||||
HEALTHCHECK --interval=20s --timeout=5s --start-period=20s --retries=5 \
|
||||
CMD node -e "require('http').get('http://127.0.0.1:'+(process.env.PORT||3003)+'/health',r=>process.exit(r.statusCode<500?0:1)).on('error',()=>process.exit(1))"
|
||||
|
||||
# The MCP server selects HTTP transport via CLI flags (no PORT-env auto-start).
|
||||
CMD ["sh", "-c", "node dist/index.js --transport http --port ${PORT:-3003}"]
|
||||
@ -27,7 +27,12 @@ step "TS engine libraries"
|
||||
build_ts() {
|
||||
local dir="$1" label="$2" cmd="${3:-npm run build}"
|
||||
if [ -d "$AITM_ROOT/$dir" ]; then
|
||||
( cd "$AITM_ROOT/$dir" && eval "$cmd" ) && ok "$label built" || warn "$label build failed (run npm install first?)"
|
||||
# Install deps first when node_modules is absent (e.g. inside the Docker
|
||||
# image where .dockerignore strips them) so the build's tsc/devDeps resolve.
|
||||
( cd "$AITM_ROOT/$dir" \
|
||||
&& { [ -d node_modules ] || npm install --no-audit --no-fund; } \
|
||||
&& eval "$cmd" ) \
|
||||
&& ok "$label built" || warn "$label build failed (run npm install first?)"
|
||||
else
|
||||
warn "$label: $dir missing — skipped"
|
||||
fi
|
||||
|
||||
@ -179,8 +179,11 @@ services:
|
||||
|
||||
aitm-api:
|
||||
build:
|
||||
context: ./aitimemachine/api-server
|
||||
dockerfile: Dockerfile
|
||||
# Context is the aitimemachine root: the api-server Dockerfile builds the
|
||||
# bundled engines (scripts/build-engines.sh) and resolves the file:../
|
||||
# engine siblings from there.
|
||||
context: ./aitimemachine
|
||||
dockerfile: api-server/Dockerfile
|
||||
container_name: aitm-api
|
||||
networks:
|
||||
- gitgram-net
|
||||
@ -254,8 +257,10 @@ services:
|
||||
|
||||
aitm-mcp:
|
||||
build:
|
||||
context: ./aitimemachine/mcp
|
||||
dockerfile: Dockerfile
|
||||
# Context is the aitimemachine root so the file:../ siblings
|
||||
# (@gitgram/timemachine root pkg, gitnexus, gitnexus-shared) resolve.
|
||||
context: ./aitimemachine
|
||||
dockerfile: mcp/Dockerfile
|
||||
container_name: aitm-mcp
|
||||
networks:
|
||||
- gitgram-net
|
||||
@ -289,13 +294,18 @@ services:
|
||||
|
||||
gitnexus:
|
||||
build:
|
||||
context: ./aitimemachine/gitnexus
|
||||
dockerfile: Dockerfile
|
||||
# Context is the aitimemachine root so the file:../gitnexus-shared
|
||||
# sibling resolves during build.js.
|
||||
context: ./aitimemachine
|
||||
dockerfile: gitnexus/Dockerfile
|
||||
container_name: gitnexus
|
||||
networks:
|
||||
- gitgram-net
|
||||
ports:
|
||||
- "3010:3010"
|
||||
# Host 3010 is occupied by a stray host-side node process; publish on
|
||||
# 13010 instead. Internal port stays 3010 so inter-service comms
|
||||
# (e.g. aitm-mcp -> http://gitnexus:3010) are unaffected.
|
||||
- "13010:3010"
|
||||
environment:
|
||||
NODE_ENV: development
|
||||
PORT: "3010"
|
||||
|
||||
Reference in New Issue
Block a user