Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# The Docker image only needs nginx.conf, nginx.headers.conf and the prebuilt
# dist/ (see Dockerfile).
# The Docker image only needs nginx.conf, the two nginx.*headers.conf files and
# the prebuilt dist/ (see Dockerfile). mcp-server/Dockerfile has its own
# Dockerfile.dockerignore.
# Keep the build context small and avoid leaking source/secrets into the image.
node_modules
.git
Expand All @@ -26,6 +27,7 @@ vite.config.js
tsconfig.json
package-lock.json
apps.json
mcp-server

# The page manifest is build metadata for the MCP indexer, not site content:
# keep it out of the nginx web root. mcp-server/Dockerfile.dockerignore lets it in.
Expand Down
23 changes: 21 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dependabot keeps npm dependencies, pinned GitHub Actions and the Docker base
# image up to date.
# Dependabot keeps npm and uv dependencies, pinned GitHub Actions and the Docker
# base images up to date.
# Action updates land as SHA bumps with the human-readable tag in a comment.
version: 2
updates:
Expand Down Expand Up @@ -39,6 +39,18 @@ updates:
actions-dependencies:
update-types: [minor, patch]

# The MCP server's own lockfile (mcp-server/uv.lock). The SDK is pinned
# exactly, so an SDK bump is a PR of its own and runs the protocol tests.
- package-ecosystem: uv
directory: /mcp-server
schedule:
interval: weekly
open-pull-requests-limit: 5
groups:
mcp-server-dependencies:
update-types: [minor, patch]
exclude-patterns: [mcp]

- package-ecosystem: github-actions
directory: /
schedule:
Expand All @@ -56,3 +68,10 @@ updates:
schedule:
interval: weekly
open-pull-requests-limit: 5

# mcp-server/Dockerfile pins python and uv by tag and digest.
- package-ecosystem: docker
directory: /mcp-server
schedule:
interval: weekly
open-pull-requests-limit: 5
127 changes: 112 additions & 15 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# with:
# registry: apps.json # in the CALLING repo
# image-name: ghcr.io/org/knowledge-base
# mcp-image-name: ghcr.io/org/knowledge-base-mcp # optional: the MCP server
# secrets:
# docs-token: ${{ steps.app-token.outputs.token }}
#
Expand Down Expand Up @@ -53,6 +54,24 @@ on:
type: string
required: false
default: ''
mcp-image-name:
description: >-
MCP server image to build and push from the same dist/ and with the
same tags, e.g. ghcr.io/org/knowledge-base-mcp. It runs beside the
site image in one task; see contract/DEPLOYMENT.md. Empty builds no
MCP image. Ignored without image-name.
type: string
required: false
default: ''
python-index:
description: >-
Python package index for the MCP image's dependencies, for runners
that cannot reach pypi.org — an Artifactory PyPI remote, say. Empty
means PyPI. The lockfile needs no change: the image installs from
hash-pinned requirements exported from it, which name no index.
type: string
required: false
default: ''
image-tags:
description: 'Newline- or comma-separated tags to push. Defaults to the calling run''s SHA.'
type: string
Expand Down Expand Up @@ -108,6 +127,14 @@ on:
node-mirror-token:
description: Authorization header value for `node-mirror`.
required: false
python-index-username:
description: User name for `python-index`, when it needs credentials.
required: false
python-index-token:
description: >-
Password or token for `python-index`. Reaches the image build as a
BuildKit secret, never as a build argument or a layer.
required: false
ca-certificates:
description: >-
Extra CA certificates (PEM) the image build trusts while `apk upgrade`
Expand All @@ -118,6 +145,9 @@ on:
image:
description: 'The first pushed image reference, when one was pushed.'
value: ${{ jobs.build.outputs.image }}
mcp-image:
description: 'The first pushed MCP image reference, when one was pushed.'
value: ${{ jobs.build.outputs.mcp-image }}

permissions:
contents: read
Expand All @@ -131,6 +161,7 @@ jobs:
runs-on: ${{ (startsWith(inputs.runs-on, '[') || startsWith(inputs.runs-on, '{')) && fromJSON(inputs.runs-on) || inputs.runs-on }}
outputs:
image: ${{ steps.push.outputs.image }}
mcp-image: ${{ steps.push.outputs.mcp-image }}
steps:
# The caller's repo holds the registry; this repo holds the build. They are
# checked out side by side, and the build runs from this one.
Expand Down Expand Up @@ -249,42 +280,108 @@ jobs:
# Force the plain `docker login` path instead.
ecr: 'false'

- name: Build and push the image
- name: Build and push the images
id: push
if: ${{ inputs.image-name != '' }}
working-directory: knowledge-base
env:
KB_IMAGE: ${{ inputs.image-name }}
KB_MCP_IMAGE: ${{ inputs.mcp-image-name }}
KB_TAGS: ${{ inputs.image-tags }}
KB_SHA: ${{ github.sha }}
KB_CA_CERTIFICATES: ${{ secrets.ca-certificates }}
KB_PYTHON_INDEX: ${{ inputs.python-index }}
KB_PYTHON_INDEX_USERNAME: ${{ secrets.python-index-username }}
KB_PYTHON_INDEX_TOKEN: ${{ secrets.python-index-token }}
run: |
set -euo pipefail

# The Dockerfile trusts every *.pem in trusted_certs/ for its apk step.
# Both Dockerfiles trust every *.pem in trusted_certs/ for their
# package downloads.
if [ -n "${KB_CA_CERTIFICATES:-}" ]; then
printf '%s\n' "$KB_CA_CERTIFICATES" > trusted_certs/ca-certificates.pem
fi

tags="${KB_TAGS:-$KB_SHA}"
# Accept either separator; normalise to one tag per line.
tags="$(printf '%s' "$tags" | tr ',' '\n' | sed '/^[[:space:]]*$/d')"
first_tag="$(head -n 1 <<< "$tags")"

args=()
first=''
while IFS= read -r tag; do
ref="$KB_IMAGE:$tag"
args+=(-t "$ref")
[ -z "$first" ] && first="$ref"
done <<< "$tags"
# The index URL travels as a BuildKit secret: it may carry credentials,
# and a build argument would be recorded in the image history. Checked
# before anything is built, so a bad input pushes nothing.
secret=()
if [ -n "${KB_MCP_IMAGE:-}" ] && [ -n "${KB_PYTHON_INDEX:-}" ]; then
case "$KB_PYTHON_INDEX" in
*[[:space:]]*|*@*)
echo "::error::python-index must be a single URL without credentials; pass them as secrets"
exit 1 ;;
http://*|https://*) ;;
*)
echo "::error::python-index must be an http(s) URL, got '$KB_PYTHON_INDEX'"
exit 1 ;;
esac
index="$KB_PYTHON_INDEX"
if [ -n "${KB_PYTHON_INDEX_TOKEN:-}" ]; then
user="$(jq -rn --arg v "${KB_PYTHON_INDEX_USERNAME:-__token__}" '$v|@uri')"
token="$(jq -rn --arg v "$KB_PYTHON_INDEX_TOKEN" '$v|@uri')"
# GitHub masks the raw secret; the percent-encoded form is not guaranteed to match.
echo "::add-mask::${token}"
index="${index%%://*}://${user}:${token}@${index#*://}"
echo "::add-mask::${index}"
fi
export KB_PYTHON_INDEX_URL="$index"
secret=(--secret id=python-index,env=KB_PYTHON_INDEX_URL)
echo "The MCP image installs from ${KB_PYTHON_INDEX}${KB_PYTHON_INDEX_TOKEN:+ (authenticated)}"
fi

docker build "${args[@]}" .
while IFS= read -r tag; do
docker push "$KB_IMAGE:$tag"
done <<< "$tags"
# Never call these inside $(...): errexit is off in a command
# substitution, and a failed build would no longer fail the step.
build() {
local image="$1" dockerfile="$2" tag args=()
shift 2
while IFS= read -r tag; do
args+=(-t "$image:$tag")
done <<< "$tags"
docker build -f "$dockerfile" "${args[@]}" "$@" .
}
# Only the first tag goes out before both images are in place; it is
# the one reported as an output, so a consumer never sees a pair in
# which one image is missing. The other tags (aliases such as
# `latest`) are promoted afterwards: if that fails the pair is
# published and the aliases can be re-run on their own.
publish() {
local images=() outputs=() tag i
if [ -n "${KB_MCP_IMAGE:-}" ]; then
images+=("$KB_MCP_IMAGE")
outputs+=(mcp-image)
fi
images+=("$KB_IMAGE")
outputs+=(image)
for i in "${!images[@]}"; do
docker push "${images[$i]}:$first_tag"
done
for i in "${!images[@]}"; do
echo "${outputs[$i]}=${images[$i]}:$first_tag" >> "$GITHUB_OUTPUT"
echo "Pushed \`${images[$i]}:$first_tag\`." >> "$GITHUB_STEP_SUMMARY"
done
while IFS= read -r tag; do
[ "$tag" = "$first_tag" ] && continue
for i in "${!images[@]}"; do
docker push "${images[$i]}:$tag"
done
done <<< "$tags"
}

echo "image=$first" >> "$GITHUB_OUTPUT"
echo "Pushed \`$first\`." >> "$GITHUB_STEP_SUMMARY"
# The two images are one version: both are built before either is
# pushed, so a failed MCP build leaves both repositories as they were.
# The MCP image goes first because its push is the likelier to fail
# (a repository nobody created yet).
build "$KB_IMAGE" Dockerfile
if [ -n "${KB_MCP_IMAGE:-}" ]; then
build "$KB_MCP_IMAGE" mcp-server/Dockerfile ${secret[@]+"${secret[@]}"}
fi
publish

# kb-build.json records which release of which repo produced each app. An
# image is opaque once pushed; this is how "the docs are wrong" becomes an
Expand Down
48 changes: 46 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# typecheck — astro check (TypeScript / Astro type errors)
# build — headless build from the vendored fixture; uploads dist/
# e2e — Playwright: embedded web-fragment harness + standalone layer
# mcp — MCP server (mcp-server/, Python): ruff, mypy, import-linter, pytest, and an index of the real build
# image — docker build + container integration tests against real nginx + Trivy scan
# audit — npm dependency vulnerability gate

Expand Down Expand Up @@ -208,8 +209,8 @@ jobs:
runs-on: '["ubuntu-latest"]'
# ── 5. Container image ─────────────────────────────────────────────────────
#
# Builds the runtime image from the dist/ the build job produced, then scans
# it. `npm audit` below covers JS dependencies only — nothing else in CI looks
# Builds both runtime images (the site and the MCP server) from the dist/ the
# build job produced, runs them as a deployment's task does, then scans them. `npm audit` below covers JS dependencies only — nothing else in CI looks
# at the nginx base image, which is what the digest pin in the Dockerfile
# exists to control. CRITICAL-only so a routine base-image CVE does not block
# unrelated PRs; the fix is to bump the pinned digest.
Expand All @@ -232,6 +233,8 @@ jobs:
# Also proves the Dockerfile's dist/ sanity checks pass on a real build.
- name: Build image
run: docker build -t knowledge-base:ci .
- name: Build MCP image
run: docker build -f mcp-server/Dockerfile -t knowledge-base-mcp:ci .
# The CSP checks in the container suite need a real browser: a policy that
# blocks something the page needs fails silently, and only a browser
# reports the violation.
Expand All @@ -245,6 +248,7 @@ jobs:
run: npm run test:container
env:
KB_IMAGE: knowledge-base:ci
KB_MCP_IMAGE: knowledge-base-mcp:ci
KB_SKIP_BUILD: 'true'
- name: Scan image
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
Expand All @@ -254,6 +258,14 @@ jobs:
exit-code: '1'
ignore-unfixed: true
severity: CRITICAL
- name: Scan MCP image
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: knowledge-base-mcp:ci
format: table
exit-code: '1'
ignore-unfixed: true
severity: CRITICAL
- name: Upload Playwright report
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand All @@ -262,6 +274,38 @@ jobs:
path: playwright-report/
retention-days: 7

# ── 5b. MCP server (Python) ────────────────────────────────────────────────
# mcp-server/ is a self-contained uv project. Lint, types, layering and unit
# tests need nothing else; the last step indexes the real build from the
# `build` job, which is where a page manifest the indexer no longer accepts
# would show up.
mcp:
name: MCP server (Python)
runs-on: ubuntu-latest
needs: build
defaults:
run:
working-directory: mcp-server
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
enable-cache: true
cache-dependency-glob: mcp-server/uv.lock
- run: uv sync --locked --all-extras
- run: uv run ruff format --check .
- run: uv run ruff check .
- run: uv run mypy
- run: uv run lint-imports
- run: uv run pytest
- name: Download dist artifact
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: ci-dist
path: dist
- name: Index the fixture build
run: uv run kb-mcp index --dist ../dist --out ../index.sqlite

# ── 6. Dependency audit ────────────────────────────────────────────────────
audit:
name: npm audit
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ jobs:
# segments in dependabot branches (e.g. dependabot/npm_and_yarn/…).
branch-pattern: "^(feat|feature|fix|bugfix|hotfix|release|support|chore|docs|ci|test|dependabot)/[a-zA-Z0-9._/-]+$"
max-files-changed: "50"
# Reported, not enforced: a feature reviewed whole can outgrow it.
warn-checks: "pr-size"
allowed-target-branches: ${{ steps.targets.outputs.list }}
24 changes: 21 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Closes #43

### Size

**Maximum 50 changed files per PR.** Split larger work.
**Aim for at most 50 changed files per PR**, and split larger work where practical. The PR
check reports a bigger PR as a warning; it does not fail it.

## Commits

Expand All @@ -92,10 +93,11 @@ that is the bug — fix the change, not the test.
A fourth suite needs Docker and is therefore **not** part of `npm test`:

```bash
npm run test:container # integration tests against the real nginx image
npm run test:container # integration tests against the real nginx + MCP images
```

Run it when touching `nginx.conf`, `nginx.headers.conf` or the `Dockerfile`. It
Run it when touching `nginx.conf`, `nginx.headers.conf`, `nginx.security-headers.conf`,
either `Dockerfile` (the site's or `mcp-server/`'s) or the MCP server's HTTP behaviour. It
is the only place the shipped config is executed — the other suites run against
`tests/fragment-server.mjs`, an Express mirror of the nginx rewrites. That mirror
is a second implementation of the same contract and it has drifted twice
Expand All @@ -110,6 +112,22 @@ anything there, rebuild, then run it.

`npm audit --omit=dev --audit-level=high` must also stay clean; it gates CI.

Touching `mcp-server/` (the Python MCP server)? From that directory, all five must
pass — CI's `mcp` job runs the same:

```bash
uv run ruff format --check . # format
uv run ruff check . # lint
uv run mypy # strict types
uv run lint-imports # layering contracts in pyproject.toml
uv run pytest # unit + protocol tests, 90% branch coverage
```

A change to the page manifest (`scripts/page-manifest.js`) is a change to the
indexer's input: update `scripts/page-manifest.schema.json`,
`mcp-server/src/kb_mcp/indexer/manifest.py` and `mcp-server/tests/fixtures/pages.json`
together.

## Repository conventions

### Hermetic by construction
Expand Down
Loading
Loading