381 lines
13 KiB
YAML
381 lines
13 KiB
YAML
name: CI
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
- "feat/**"
|
|
|
|
env:
|
|
CARGO_BUILD_JOBS: "2"
|
|
CARGO_INCREMENTAL: "0"
|
|
RUST_TEST_THREADS: "2"
|
|
TESTCONTAINERS_RYUK_DISABLED: "true"
|
|
|
|
jobs:
|
|
rust:
|
|
name: Rust Checks
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5
|
|
|
|
- name: Verify runner toolchain
|
|
run: |
|
|
python3 --version
|
|
rustc --version
|
|
cargo --version
|
|
rustfmt --version
|
|
cargo clippy --version
|
|
docker --version
|
|
docker info
|
|
|
|
- name: Run tooling unit tests
|
|
run: python3 -m unittest discover -s tests/unit
|
|
|
|
- name: Check Community scope
|
|
run: scripts/check-community-scope.sh
|
|
|
|
- name: Check formatting
|
|
run: cargo fmt --all --check
|
|
|
|
- name: Check Rust code health
|
|
run: scripts/check-rust-code-health.sh
|
|
|
|
- name: Check Rust boundaries
|
|
run: scripts/check-rust-boundaries.sh
|
|
|
|
- name: Run clippy
|
|
run: cargo clippy --workspace --all-targets --all-features --jobs "$CARGO_BUILD_JOBS" -- -D warnings
|
|
|
|
- name: Run tests
|
|
run: cargo test --workspace --all-targets --jobs "$CARGO_BUILD_JOBS"
|
|
|
|
ui:
|
|
name: UI Checks
|
|
runs-on: ubuntu-latest
|
|
needs: rust
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5
|
|
|
|
- name: Verify runner toolchain
|
|
run: |
|
|
node --version
|
|
npm --version
|
|
docker --version
|
|
|
|
- name: Install UI dependencies
|
|
working-directory: apps/ui
|
|
run: npm ci
|
|
|
|
- name: Build UI bundle
|
|
working-directory: apps/ui
|
|
run: npm run build
|
|
|
|
frontend-e2e:
|
|
name: Frontend E2E
|
|
runs-on: ubuntu-latest
|
|
needs: ui
|
|
services:
|
|
crank-e2e-postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_DB: crank
|
|
POSTGRES_USER: crank
|
|
POSTGRES_PASSWORD: crank
|
|
options: >-
|
|
--health-cmd "pg_isready -U crank -d crank"
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
env:
|
|
CRANK_E2E_USE_EXTERNAL_POSTGRES: "1"
|
|
CRANK_E2E_POSTGRES_HOST: crank-e2e-postgres
|
|
CRANK_E2E_POSTGRES_PORT: "5432"
|
|
CRANK_E2E_POSTGRES_DB: crank
|
|
CRANK_E2E_POSTGRES_USER: crank
|
|
CRANK_E2E_POSTGRES_PASSWORD: crank
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5
|
|
|
|
- name: Verify runner toolchain
|
|
run: |
|
|
rustc --version
|
|
cargo --version
|
|
node --version
|
|
npm --version
|
|
docker --version
|
|
|
|
- name: Install UI dependencies
|
|
working-directory: apps/ui
|
|
run: npm ci
|
|
|
|
- name: Install Playwright browser
|
|
working-directory: apps/ui
|
|
run: npx playwright install --with-deps chromium
|
|
|
|
- name: Prebuild e2e services
|
|
run: cargo build -p admin-api -p mcp-server --jobs "$CARGO_BUILD_JOBS"
|
|
|
|
- name: Run Playwright e2e
|
|
working-directory: apps/ui
|
|
run: npx playwright test
|
|
|
|
- name: Show Playwright stack logs
|
|
if: failure()
|
|
run: |
|
|
find .tmp/ui-e2e/logs -maxdepth 1 -type f -print -exec sed -n '1,220p' {} \; || true
|
|
|
|
deployment:
|
|
name: Deployment Manifests
|
|
runs-on: ubuntu-latest
|
|
needs: ui
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5
|
|
|
|
- name: Validate Community deployment manifest
|
|
run: docker compose -f deploy/community/docker-compose.yml --env-file deploy/community/.env.example config -q
|
|
|
|
deploy:
|
|
name: Deploy
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- rust
|
|
- ui
|
|
- frontend-e2e
|
|
- deployment
|
|
if: ${{ gitea.event_name == 'push' && gitea.ref == 'refs/heads/main' }}
|
|
env:
|
|
REGISTRY: git.itexp.me
|
|
IMAGE_TAG: ${{ gitea.sha }}
|
|
ADMIN_API_IMAGE: git.itexp.me/bsodfather/crank-community-admin-api
|
|
MCP_SERVER_IMAGE: git.itexp.me/bsodfather/crank-community-mcp-server
|
|
UI_IMAGE: git.itexp.me/bsodfather/crank-community-ui
|
|
OPENBAO_ENV_FILE: .openbao-env
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5
|
|
|
|
- name: Verify runner toolchain
|
|
run: |
|
|
docker --version
|
|
command -v bao
|
|
bao version
|
|
|
|
- name: Load deployment secrets from OpenBao
|
|
env:
|
|
BAO_ADDR: ${{ secrets.BAO_ADDR }}
|
|
BAO_ROLE_ID: ${{ secrets.BAO_ROLE_ID }}
|
|
BAO_SECRET_ID: ${{ secrets.BAO_SECRET_ID }}
|
|
OPENBAO_APP: crank
|
|
run: scripts/load-openbao-env.sh
|
|
|
|
- name: Login to registry
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
printf '%s' "$DEPLOY_REGISTRY_TOKEN" | \
|
|
docker login '${{ env.REGISTRY }}' -u "$DEPLOY_REGISTRY_USER" --password-stdin
|
|
|
|
- name: Build and push images
|
|
run: |
|
|
docker build -f apps/admin-api/Dockerfile \
|
|
-t '${{ env.ADMIN_API_IMAGE }}:${{ env.IMAGE_TAG }}' \
|
|
-t '${{ env.ADMIN_API_IMAGE }}:main' \
|
|
.
|
|
docker build -f apps/mcp-server/Dockerfile \
|
|
-t '${{ env.MCP_SERVER_IMAGE }}:${{ env.IMAGE_TAG }}' \
|
|
-t '${{ env.MCP_SERVER_IMAGE }}:main' \
|
|
.
|
|
docker build -f apps/ui/Dockerfile \
|
|
-t '${{ env.UI_IMAGE }}:${{ env.IMAGE_TAG }}' \
|
|
-t '${{ env.UI_IMAGE }}:main' \
|
|
.
|
|
docker push '${{ env.ADMIN_API_IMAGE }}:${{ env.IMAGE_TAG }}'
|
|
docker push '${{ env.ADMIN_API_IMAGE }}:main'
|
|
docker push '${{ env.MCP_SERVER_IMAGE }}:${{ env.IMAGE_TAG }}'
|
|
docker push '${{ env.MCP_SERVER_IMAGE }}:main'
|
|
docker push '${{ env.UI_IMAGE }}:${{ env.IMAGE_TAG }}'
|
|
docker push '${{ env.UI_IMAGE }}:main'
|
|
|
|
- name: Configure SSH key
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
mkdir -p ~/.ssh
|
|
chmod 700 ~/.ssh
|
|
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
|
|
- name: Configure known hosts
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
if [ -n "${DEPLOY_KNOWN_HOSTS:-}" ]; then
|
|
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
|
else
|
|
ssh-keyscan -p "${DEPLOY_PORT:-22}" "$DEPLOY_HOST" > ~/.ssh/known_hosts
|
|
fi
|
|
chmod 644 ~/.ssh/known_hosts
|
|
|
|
- name: Sync deployment files to server
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
ssh -p "$DEPLOY_PORT" "$DEPLOY_USER@$DEPLOY_HOST" \
|
|
"mkdir -p '$DEPLOY_PATH'"
|
|
rsync -az -e "ssh -p $DEPLOY_PORT" deploy/community/docker-compose.yml \
|
|
"$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/docker-compose.yml"
|
|
|
|
- name: Write environment file
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
tmp_env="$(mktemp)"
|
|
append_if_set() {
|
|
if [ -n "$2" ]; then
|
|
printf '%s=%s\n' "$1" "$2" >> "$tmp_env"
|
|
fi
|
|
}
|
|
: > "$tmp_env"
|
|
append_if_set POSTGRES_DB "$POSTGRES_DB"
|
|
append_if_set POSTGRES_USER "$POSTGRES_USER"
|
|
append_if_set POSTGRES_PASSWORD "$POSTGRES_PASSWORD"
|
|
append_if_set POSTGRES_HOST "$POSTGRES_HOST"
|
|
if [ -n "${POSTGRES_PORT:-}" ]; then
|
|
append_if_set POSTGRES_PORT "$POSTGRES_PORT"
|
|
elif [ -n "${PGBOUNCER_PORT:-}" ]; then
|
|
append_if_set POSTGRES_PORT "$PGBOUNCER_PORT"
|
|
fi
|
|
append_if_set CRANK_STORAGE_ROOT "$CRANK_STORAGE_ROOT"
|
|
append_if_set CRANK_PUBLISH_BIND "$CRANK_PUBLISH_BIND"
|
|
append_if_set CRANK_ADMIN_BIND "$CRANK_ADMIN_BIND"
|
|
append_if_set CRANK_MCP_BIND "$CRANK_MCP_BIND"
|
|
append_if_set CRANK_MCP_REFRESH_MS "$CRANK_MCP_REFRESH_MS"
|
|
append_if_set CRANK_LOG_LEVEL "$CRANK_LOG_LEVEL"
|
|
append_if_set CRANK_MASTER_KEY "$CRANK_MASTER_KEY"
|
|
append_if_set CRANK_BASE_URL "$CRANK_BASE_URL"
|
|
append_if_set CRANK_CACHE_BACKEND "$CRANK_CACHE_BACKEND"
|
|
append_if_set CRANK_CACHE_URL "$CRANK_CACHE_URL"
|
|
append_if_set CRANK_CACHE_DEFAULT_TTL_MS "$CRANK_CACHE_DEFAULT_TTL_MS"
|
|
append_if_set CRANK_SESSION_SECRET "$CRANK_SESSION_SECRET"
|
|
append_if_set CRANK_PASSWORD_PEPPER "$CRANK_PASSWORD_PEPPER"
|
|
append_if_set CRANK_SESSION_TTL_HOURS "$CRANK_SESSION_TTL_HOURS"
|
|
append_if_set CRANK_BOOTSTRAP_ADMIN_EMAIL "$CRANK_BOOTSTRAP_ADMIN_EMAIL"
|
|
append_if_set CRANK_BOOTSTRAP_ADMIN_PASSWORD "$CRANK_BOOTSTRAP_ADMIN_PASSWORD"
|
|
append_if_set CRANK_BOOTSTRAP_ADMIN_DISPLAY_NAME "$CRANK_BOOTSTRAP_ADMIN_DISPLAY_NAME"
|
|
append_if_set CRANK_DEMO_SEED "$CRANK_DEMO_SEED"
|
|
{
|
|
printf 'COMPOSE_PROJECT_NAME=community\n'
|
|
printf 'CRANK_ADMIN_API_IMAGE=%s:%s\n' '${{ env.ADMIN_API_IMAGE }}' '${{ env.IMAGE_TAG }}'
|
|
printf 'CRANK_MCP_SERVER_IMAGE=%s:%s\n' '${{ env.MCP_SERVER_IMAGE }}' '${{ env.IMAGE_TAG }}'
|
|
printf 'CRANK_UI_IMAGE=%s:%s\n' '${{ env.UI_IMAGE }}' '${{ env.IMAGE_TAG }}'
|
|
} >> "$tmp_env"
|
|
cat "$tmp_env" | ssh -p "$DEPLOY_PORT" "$DEPLOY_USER@$DEPLOY_HOST" \
|
|
"mkdir -p '$DEPLOY_PATH' && cat > '$DEPLOY_PATH/.env'"
|
|
rm -f "$tmp_env"
|
|
|
|
- name: Validate required environment variables
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
ssh -p "$DEPLOY_PORT" "$DEPLOY_USER@$DEPLOY_HOST" "
|
|
set -e
|
|
cd '$DEPLOY_PATH'
|
|
required_vars='
|
|
POSTGRES_HOST
|
|
POSTGRES_PORT
|
|
POSTGRES_DB
|
|
POSTGRES_USER
|
|
POSTGRES_PASSWORD
|
|
CRANK_MASTER_KEY
|
|
CRANK_SESSION_SECRET
|
|
CRANK_PASSWORD_PEPPER
|
|
CRANK_BOOTSTRAP_ADMIN_EMAIL
|
|
CRANK_BOOTSTRAP_ADMIN_PASSWORD
|
|
CRANK_BASE_URL
|
|
'
|
|
for var in \$required_vars; do
|
|
value=\$(grep -E \"^\${var}=\" .env | tail -n1 | cut -d= -f2- || true)
|
|
if [ -z \"\$value\" ]; then
|
|
echo \"missing required env: \$var\" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
"
|
|
|
|
- name: Deploy with Docker Compose
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
ssh -p "$DEPLOY_PORT" "$DEPLOY_USER@$DEPLOY_HOST" "
|
|
set -e
|
|
cd '$DEPLOY_PATH'
|
|
compose_profiles=''
|
|
cache_backend=\$(grep -E '^CRANK_CACHE_BACKEND=' .env | tail -n1 | cut -d= -f2- || true)
|
|
if [ \"\$cache_backend\" = 'valkey' ] || [ \"\$cache_backend\" = 'redis' ]; then
|
|
compose_profiles='--profile cache'
|
|
fi
|
|
echo '$DEPLOY_REGISTRY_TOKEN' | docker login '${{ env.REGISTRY }}' -u '$DEPLOY_REGISTRY_USER' --password-stdin
|
|
docker compose \$compose_profiles config -q
|
|
docker compose \$compose_profiles pull
|
|
docker compose \$compose_profiles down --remove-orphans
|
|
for container in \
|
|
crank-ui-1 \
|
|
crank-admin-api-1 \
|
|
crank-mcp-server-1 \
|
|
crank-postgres-1 \
|
|
crank-valkey-1 \
|
|
crank-community-ui-1 \
|
|
crank-community-admin-api-1 \
|
|
crank-community-mcp-server-1 \
|
|
crank-community-postgres-1 \
|
|
crank-community-valkey-1; do
|
|
if docker ps -a --format '{{.Names}}' | grep -Fx \"\$container\" >/dev/null; then
|
|
docker rm -f \"\$container\"
|
|
fi
|
|
done
|
|
echo 'Docker containers before freeing required ports:'
|
|
docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Ports}}'
|
|
for port in 3000 3001 3002; do
|
|
container_ids=\$(docker ps -aq --filter \"publish=\$port\")
|
|
if [ -n \"\$container_ids\" ]; then
|
|
echo \"Removing containers publishing port \$port\"
|
|
docker inspect --format '{{.Name}} {{json .NetworkSettings.Ports}}' \$container_ids || true
|
|
docker rm -f \$container_ids
|
|
fi
|
|
done
|
|
if command -v ss >/dev/null 2>&1; then
|
|
ss -ltnp '( sport = :3000 or sport = :3001 or sport = :3002 )' || true
|
|
fi
|
|
docker compose \$compose_profiles up -d --remove-orphans
|
|
"
|
|
|
|
- name: Verify health endpoints
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
ssh -p "$DEPLOY_PORT" "$DEPLOY_USER@$DEPLOY_HOST" "
|
|
set -e
|
|
cd '$DEPLOY_PATH'
|
|
for attempt in \$(seq 1 30); do
|
|
if curl --fail --silent http://127.0.0.1:3000/ >/dev/null \
|
|
&& curl --fail --silent http://127.0.0.1:3001/health >/dev/null \
|
|
&& curl --fail --silent http://127.0.0.1:3002/health >/dev/null; then
|
|
exit 0
|
|
fi
|
|
sleep 2
|
|
done
|
|
echo 'deployment health verification failed' >&2
|
|
docker compose ps >&2
|
|
exit 1
|
|
"
|
|
|
|
- name: Run authenticated product smoke
|
|
run: |
|
|
. "$OPENBAO_ENV_FILE"
|
|
CRANK_STAGING_ADMIN_EMAIL="$CRANK_BOOTSTRAP_ADMIN_EMAIL" \
|
|
CRANK_STAGING_ADMIN_PASSWORD="$CRANK_BOOTSTRAP_ADMIN_PASSWORD" \
|
|
scripts/authenticated-product-smoke.sh "$CRANK_BASE_URL"
|