⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(ci): port contention in ci
justin849f5edb5b64
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 49a2f1fa4..a2d30f7a3 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -321,18 +321,20 @@ jobs:- run: npm ci --ignore-scriptsworking-directory: scripts/ui-review-bot- run: scripts/ui-review-bot/node_modules/.bin/playwright install --with-deps chromium+ - name: Allocate runtime test ports+ run: bash scripts/ci/gateway-env.sh >> "$GITHUB_ENV"- name: Start bundled image without Redisrun: docker compose --env-file /dev/null -p kaneo-ci -f scripts/ci/compose.yml up -d --wait --wait-timeout 120 postgres minio app- name: Browser regression and workspace isolation- run: node scripts/ci/browser.mjs http://127.0.0.1:55173+ run: node scripts/ci/browser.mjs "$KANEO_CI_APP_ORIGIN"- name: Verify realtime without Redis- run: node scripts/ci/realtime.mjs http://127.0.0.1:55173+ run: node scripts/ci/realtime.mjs "$KANEO_CI_APP_ORIGIN"- name: Start two API instances with Redisenv:KANEO_CI_REDIS_URL: redis://redis:6379run: docker compose --env-file /dev/null -p kaneo-ci -f scripts/ci/compose.yml --profile realtime up -d --wait --wait-timeout 120 app second redis- name: Verify Redis fan-out- run: node scripts/ci/realtime.mjs http://127.0.0.1:55173 http://127.0.0.1:55174+ run: node scripts/ci/realtime.mjs "$KANEO_CI_APP_ORIGIN" "$KANEO_CI_SECOND_ORIGIN"- name: Upgrade from the latest stable releaseenv:GH_TOKEN: ${{ github.token }}diff --git a/scripts/ci/README.md b/scripts/ci/README.mdindex d8494646d..5e7a7cf91 100644--- a/scripts/ci/README.md+++ b/scripts/ci/README.md@@ -151,12 +151,15 @@ runner's dependencies (`npm ci --ignore-scripts --prefix scripts/ui-review-bot`)After building a candidate image tagged `kaneo:ci`:-```sh+```bash+set -a+source <(bash scripts/ci/gateway-env.sh)+set +adocker compose --env-file /dev/null -p kaneo-ci -f scripts/ci/compose.yml up -d --wait postgres minio app-node scripts/ci/browser.mjs http://127.0.0.1:55173-node scripts/ci/realtime.mjs http://127.0.0.1:55173+node scripts/ci/browser.mjs "$KANEO_CI_APP_ORIGIN"+node scripts/ci/realtime.mjs "$KANEO_CI_APP_ORIGIN"KANEO_CI_REDIS_URL=redis://redis:6379 docker compose --env-file /dev/null -p kaneo-ci -f scripts/ci/compose.yml --profile realtime up -d --wait app second redis-node scripts/ci/realtime.mjs http://127.0.0.1:55173 http://127.0.0.1:55174+node scripts/ci/realtime.mjs "$KANEO_CI_APP_ORIGIN" "$KANEO_CI_SECOND_ORIGIN"GITHUB_REPOSITORY=usekaneo/kaneo GITHUB_REPOSITORY_OWNER=usekaneo bash scripts/ci/upgrade.sh```@@ -168,8 +171,8 @@ Stop only this stack and remove its disposable data afterwards:docker compose --env-file /dev/null -p kaneo-ci -f scripts/ci/compose.yml --profile realtime --profile upgrade down -v```-The stack reserves loopback ports 55173–55175, 59040, 59379 and 59432. It uses-fixed synthetic credentials and test databases; do not expose it to the network.+Docker assigns loopback ports to the gateway before the API instances start.+The stack uses fixed synthetic credentials and test databases; do not expose it to the network.For a local worktree on a copy-on-write filesystem, reuse the pnpm store withoutcopying dependency data:diff --git a/scripts/ci/compose.yml b/scripts/ci/compose.ymlindex 3bb4e9f93..efac119ae 100644--- a/scripts/ci/compose.yml+++ b/scripts/ci/compose.yml@@ -1,12 +1,24 @@# Disposable CI data only. Use a unique --project-name; never load the root .env.services:+ gateway:+ image: ${KANEO_CI_IMAGE:-kaneo:ci}+ entrypoint: ["node", "/ci/gateway.mjs"]+ command: []+ volumes:+ - ./gateway.mjs:/ci/gateway.mjs:ro+ ports:+ - "127.0.0.1::15173"+ - "127.0.0.1::15174"+ - "127.0.0.1::15175"+ - "127.0.0.1::19040"+ healthcheck:+ disable: truepostgres:image: postgres:18environment:POSTGRES_DB: kaneo_ci_testPOSTGRES_USER: postgresPOSTGRES_PASSWORD: ci-only-password- ports: ["127.0.0.1:59432:5432"]volumes:- ./init-databases.sql:/docker-entrypoint-initdb.d/ci.sql:rohealthcheck:@@ -16,7 +28,6 @@ services:retries: 30redis:image: redis:7-alpine- ports: ["127.0.0.1:59379:6379"]healthcheck:test: ["CMD", "redis-cli", "ping"]interval: 2s@@ -31,7 +42,6 @@ services:MINIO_ROOT_PASSWORD: local-test-secret-onlyMINIO_BROWSER: "off"MINIO_UPDATE: "off"- ports: ["127.0.0.1:59040:9000"]healthcheck:test: ["CMD", "curl", "--fail", "--silent", "http://127.0.0.1:9000/minio/health/ready"]interval: 2s@@ -50,7 +60,7 @@ services:NODE_ENV: productionDATABASE_URL: postgresql://postgres:ci-only-password@postgres:5432/kaneo_ci_testAUTH_SECRET: ci-only-secret-with-at-least-32-characters- KANEO_CLIENT_URL: http://127.0.0.1:55173+ KANEO_CLIENT_URL: ${KANEO_CI_APP_ORIGIN:-http://127.0.0.1:55173}DISABLE_REGISTRATION: "false"DISABLE_GUEST_ACCESS: "true"DISABLE_PASSWORD_REGISTRATION: "false"@@ -61,7 +71,6 @@ services:S3_SECRET_ACCESS_KEY: local-test-secret-onlyS3_REGION: us-east-1S3_FORCE_PATH_STYLE: "true"- ports: ["127.0.0.1:55173:5173"]depends_on:postgres: {condition: service_healthy}minio: {condition: service_healthy}@@ -75,9 +84,8 @@ services:profiles: [realtime]environment:<<: *app-env- KANEO_CLIENT_URL: http://127.0.0.1:55174+ KANEO_CLIENT_URL: ${KANEO_CI_SECOND_ORIGIN:-http://127.0.0.1:55174}REDIS_URL: redis://redis:6379- ports: ["127.0.0.1:55174:5173"]depends_on:app: {condition: service_healthy}redis: {condition: service_healthy}@@ -92,9 +100,8 @@ services:environment:<<: *app-envDATABASE_URL: postgresql://postgres:ci-only-password@postgres:5432/kaneo_upgrade_test- KANEO_CLIENT_URL: http://127.0.0.1:55175+ KANEO_CLIENT_URL: ${KANEO_CI_UPGRADE_ORIGIN:-http://127.0.0.1:55175}REDIS_URL: ""- ports: ["127.0.0.1:55175:5173"]depends_on:postgres: {condition: service_healthy}minio: {condition: service_healthy}diff --git a/scripts/ci/gateway-env.sh b/scripts/ci/gateway-env.shnew file mode 100644index 000000000..d5f9cd822--- /dev/null+++ b/scripts/ci/gateway-env.sh@@ -0,0 +1,15 @@+#!/usr/bin/env bash+set -euo pipefail++compose=(docker compose --env-file /dev/null -p kaneo-ci -f scripts/ci/compose.yml)+"${compose[@]}" up -d --no-deps gateway+for mapping in APP:15173 SECOND:15174 UPGRADE:15175 MINIO:19040; do+ name=${mapping%%:*}+ port=${mapping##*:}+ address=$("${compose[@]}" port gateway "$port")+ if [[ ! "$address" =~ ^127\.0\.0\.1:[0-9]+$ ]]; then+ printf 'Unexpected gateway address: %s\n' "$address" >&2+ exit 1+ fi+ printf 'KANEO_CI_%s_ORIGIN=http://%s\n' "$name" "$address"+donediff --git a/scripts/ci/gateway.mjs b/scripts/ci/gateway.mjsnew file mode 100644index 000000000..76cd20bfc--- /dev/null+++ b/scripts/ci/gateway.mjs@@ -0,0 +1,26 @@+import { createServer, connect } from "node:net";+import { pathToFileURL } from "node:url";++export function startGateway(port, host, targetPort) {+ const server = createServer((client) => {+ const upstream = connect(targetPort, host);+ client.on("error", () => upstream.destroy());+ upstream.on("error", () => client.destroy());+ client.pipe(upstream).pipe(client);+ });+ return server.listen(port, "0.0.0.0");+}++if (+ process.argv[1] &&+ import.meta.url === pathToFileURL(process.argv[1]).href+) {+ for (const [port, host, targetPort] of [+ [15173, "app", 5173],+ [15174, "second", 5173],+ [15175, "upgrade", 5173],+ [19040, "minio", 9000],+ ]) {+ startGateway(port, host, targetPort);+ }+}diff --git a/scripts/ci/gateway.test.mjs b/scripts/ci/gateway.test.mjsnew file mode 100644index 000000000..03354073d--- /dev/null+++ b/scripts/ci/gateway.test.mjs@@ -0,0 +1,32 @@+import assert from "node:assert/strict";+import { createServer, connect } from "node:net";+import { test } from "node:test";+import { startGateway } from "./gateway.mjs";++function listen(server) {+ return new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));+}++test("gateway forwards traffic to the configured service", async () => {+ const target = createServer((socket) => socket.pipe(socket));+ await listen(target);+ const gateway = startGateway(0, "127.0.0.1", target.address().port);+ await new Promise((resolve) => gateway.once("listening", resolve));+ try {+ const result = await new Promise((resolve, reject) => {+ const socket = connect(gateway.address().port, "127.0.0.1");+ socket.on("error", reject);+ socket.on("connect", () => socket.write("hello"));+ socket.on("data", (data) => {+ socket.destroy();+ resolve(data.toString());+ });+ });+ assert.equal(result, "hello");+ } finally {+ await Promise.all([+ new Promise((resolve) => gateway.close(resolve)),+ new Promise((resolve) => target.close(resolve)),+ ]);+ }+});diff --git a/scripts/ci/upgrade.mjs b/scripts/ci/upgrade.mjsindex 2b9abb706..6326f06b3 100644--- a/scripts/ci/upgrade.mjs+++ b/scripts/ci/upgrade.mjs@@ -10,6 +10,8 @@ assert.ok("Expected seed|verify ORIGIN STATE_FILE",);const origin = localOrigin(inputOrigin);+const minioOrigin = localOrigin(process.env.KANEO_CI_MINIO_ORIGIN);+const minioUrl = new URL(minioOrigin);await ready(origin);const bytes = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aHAAAAABJRU5ErkJggg==",@@ -21,7 +23,7 @@ if (mode === "seed") {);const { S3Client, CreateBucketCommand } = require("@aws-sdk/client-s3");const storage = new S3Client({- endpoint: "http://127.0.0.1:59040",+ endpoint: minioOrigin,region: "us-east-1",forcePathStyle: true,credentials: {@@ -56,7 +58,7 @@ if (mode === "seed") {);const uploadUrl = new URL(upload.uploadUrl);assert.ok(- ["minio:9000", "127.0.0.1:59040"].includes(uploadUrl.host),+ ["minio:9000", minioUrl.host].includes(uploadUrl.host),"Only the disposable MinIO endpoint is allowed",);// Reach the Compose service through its loopback port while preserving its signed Host header.@@ -64,7 +66,7 @@ if (mode === "seed") {const req = request({hostname: "127.0.0.1",- port: 59040,+ port: minioUrl.port,path: uploadUrl.pathname + uploadUrl.search,method: "PUT",headers: {diff --git a/scripts/ci/upgrade.sh b/scripts/ci/upgrade.shindex 2e6c8da8d..212d035ac 100644--- a/scripts/ci/upgrade.sh+++ b/scripts/ci/upgrade.sh@@ -32,8 +32,8 @@ mkdir -p .cache/ci-resultsprintf 'Upgrade baseline: %s\n' "$KANEO_UPGRADE_IMAGE" | tee .cache/ci-results/upgrade-baseline.txtcompose=(docker compose --env-file /dev/null -p kaneo-ci -f scripts/ci/compose.yml --profile upgrade)"${compose[@]}" up -d --wait --wait-timeout 120 upgrade-node scripts/ci/upgrade.mjs seed http://127.0.0.1:55175 .cache/ci-results/upgrade-state.json+node scripts/ci/upgrade.mjs seed "$KANEO_CI_UPGRADE_ORIGIN" .cache/ci-results/upgrade-state.json"${compose[@]}" stop upgradeexport KANEO_UPGRADE_IMAGE=kaneo:ci"${compose[@]}" up -d --no-deps --wait --wait-timeout 120 --force-recreate upgrade-node scripts/ci/upgrade.mjs verify http://127.0.0.1:55175 .cache/ci-results/upgrade-state.json+node scripts/ci/upgrade.mjs verify "$KANEO_CI_UPGRADE_ORIGIN" .cache/ci-results/upgrade-state.json