diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 8a3cb7e..4c23863 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -151,6 +151,92 @@ jobs: run: sccache --show-stats if: always() + # compliance-agent's integration tests (compliance-agent/tests) need MongoDB. + # mongod runs as a process inside this job container, not as a `services:` + # container: three tries with a mongo service lost the database mid-run + # (pruefwerk #584), while the same tests against a mongo capped like a job + # (3 GB, 2 CPUs) pass locally and peak at ~0.5 GB. A process here can't be + # removed by the runner, and its log is printed when a test fails. + agent-integration: + name: Agent integration + if: github.event_name == 'pull_request' + runs-on: docker + container: + image: rust:1.94-bookworm + env: + MONGODB_VERSION: "7.0.45" + MONGODB_SHA256: e97e79211a7106a065d9119039ead401f32cfbbfa1681977fdeba4b4a4bf1f63 + steps: + - name: Checkout + run: | + git init + git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" + git fetch --depth=1 origin "${GITHUB_SHA}" + git checkout FETCH_HEAD + - name: Use Kellnr crates.io mirror + run: | + : "${CARGO_HOME:=/usr/local/cargo}" + mkdir -p "$CARGO_HOME" + { + echo '[source.crates-io]' + echo 'replace-with = "kellnr"' + echo '[registries.kellnr]' + echo 'index = "sparse+https://crates.breakpilot.com/api/v1/cratesio/"' + } >> "$CARGO_HOME/config.toml" + env: + RUSTC_WRAPPER: "" + - name: Install sccache + run: | + curl -fsSL https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-x86_64-unknown-linux-musl.tar.gz \ + | tar xz --strip-components=1 -C /usr/local/bin/ sccache-v0.10.0-x86_64-unknown-linux-musl/sccache + chmod +x /usr/local/bin/sccache + env: + RUSTC_WRAPPER: "" + - name: Configure git auth for the private firmwerk dependency + run: | + git config --global \ + url."https://platform-ci:${{ secrets.PLATFORM_CI_TOKEN }}@git.breakpilot.com/".insteadOf \ + "ssh://git@git.breakpilot.com:22222/" + env: + RUSTC_WRAPPER: "" + + # Build first, so compiling and mongod never share the job's 3 GB. + - name: Build the agent integration tests + run: cargo test -p compliance-agent --test '*' --no-run + + # The official Debian 12 build, checked against its sha256; a small + # WiredTiger cache, no auth (the job container is its only client). + - name: Start MongoDB + run: | + T="mongodb-linux-x86_64-debian12-${MONGODB_VERSION}" + curl -fsSL "https://fastdl.mongodb.org/linux/${T}.tgz" -o /tmp/mongodb.tgz + echo "${MONGODB_SHA256} /tmp/mongodb.tgz" | sha256sum -c - + tar -xzf /tmp/mongodb.tgz -C /opt + mkdir -p /tmp/mongo-db + "/opt/${T}/bin/mongod" --dbpath /tmp/mongo-db --bind_ip 127.0.0.1 --port 27017 \ + --wiredTigerCacheSizeGB 0.25 --fork --logpath /tmp/mongod.log + for i in $(seq 1 30); do + if (exec 3<>/dev/tcp/127.0.0.1/27017) 2>/dev/null; then echo "mongod is up"; exit 0; fi + sleep 1 + done + echo "mongod did not start"; tail -50 /tmp/mongod.log; exit 1 + shell: bash + env: + RUSTC_WRAPPER: "" + + - name: Tests (agent integration) + run: cargo test -p compliance-agent --test '*' + env: + TEST_MONGODB_URI: mongodb://127.0.0.1:27017/ + + - name: MongoDB log + if: failure() + run: | + pgrep -a mongod || echo "mongod is not running" + tail -100 /tmp/mongod.log || true + env: + RUSTC_WRAPPER: "" + # --------------------------------------------------------------------------- # Stage 2: Deploy (only on main, after checks pass) # Each service only deploys when its relevant files changed.