From 74de55e7ab1c95d3cb9f29056f510099eea1c111 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 3 Dec 2026 03:50:41 +1300 Subject: [PATCH 1/3] CI: kache as the compile cache in place of rust-cache (only main writes it; the R2 bucket once KACHE_BUCKET is set, else the GitHub cache); the server image builds dependencies in a cargo-chef layer; the app job's Postgres user is visualci --- .github/workflows/ci.yml | 84 ++++++++++++++++++++++++++++++++++++---- app/src/testing.rs | 2 +- docker/server.Dockerfile | 14 ++++++- 3 files changed, 90 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 710ef512..43d7ef77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,21 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@v2 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, + # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull + # request can't put artifacts into main's builds. + - uses: kunobi-ninja/kache-action@v1 + with: + version: "2.4.0" + cache-key-prefix: kache-${{ github.job }} + save-cache: ${{ github.ref == 'refs/heads/main' }} + pr-comment: false + s3-bucket: ${{ vars.KACHE_BUCKET }} + s3-endpoint: ${{ vars.KACHE_ENDPOINT }} + s3-region: auto + s3-prefix: visualci + s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }} + s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }} - run: rustup show active-toolchain || rustup toolchain install - run: cargo fmt --all --check - run: cargo clippy --locked --workspace --all-targets -- -D warnings @@ -41,8 +55,8 @@ jobs: postgres: image: postgres:17 env: - POSTGRES_USER: loco - POSTGRES_PASSWORD: loco + POSTGRES_USER: visualci + POSTGRES_PASSWORD: visualci POSTGRES_DB: visualci_app_test ports: ["55433:5432"] options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 @@ -56,9 +70,21 @@ jobs: docker run -d --name s3 -p 59000:9000 \ -e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret rustfs/rustfs:1.0.6 for _ in $(seq 1 30); do curl -s -o /dev/null http://127.0.0.1:59000/ && break; sleep 1; done - - uses: Swatinem/rust-cache@v2 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, + # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull + # request can't put artifacts into main's builds. + - uses: kunobi-ninja/kache-action@v1 with: - workspaces: app + version: "2.4.0" + cache-key-prefix: kache-${{ github.job }} + save-cache: ${{ github.ref == 'refs/heads/main' }} + pr-comment: false + s3-bucket: ${{ vars.KACHE_BUCKET }} + s3-endpoint: ${{ vars.KACHE_ENDPOINT }} + s3-region: auto + s3-prefix: visualci + s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }} + s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }} - run: rustup show active-toolchain || rustup toolchain install - run: cargo fmt --check - run: cargo clippy --locked --all-targets -- -D warnings @@ -99,7 +125,21 @@ jobs: options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 steps: - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@v2 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, + # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull + # request can't put artifacts into main's builds. + - uses: kunobi-ninja/kache-action@v1 + with: + version: "2.4.0" + cache-key-prefix: kache-${{ github.job }} + save-cache: ${{ github.ref == 'refs/heads/main' }} + pr-comment: false + s3-bucket: ${{ vars.KACHE_BUCKET }} + s3-endpoint: ${{ vars.KACHE_ENDPOINT }} + s3-region: auto + s3-prefix: visualci + s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }} + s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }} # The request tests also write the MCP tools' and REST API's answers as JSON snapshots, for the visual job. - run: cargo test --locked --workspace env: @@ -141,7 +181,21 @@ jobs: docker run -d --name s3 -p 59000:9000 \ -e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret rustfs/rustfs:1.0.6 for _ in $(seq 1 30); do curl -s -o /dev/null http://127.0.0.1:59000/ && break; sleep 1; done - - uses: Swatinem/rust-cache@v2 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, + # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull + # request can't put artifacts into main's builds. + - uses: kunobi-ninja/kache-action@v1 + with: + version: "2.4.0" + cache-key-prefix: kache-${{ github.job }} + save-cache: ${{ github.ref == 'refs/heads/main' }} + pr-comment: false + s3-bucket: ${{ vars.KACHE_BUCKET }} + s3-endpoint: ${{ vars.KACHE_ENDPOINT }} + s3-region: auto + s3-prefix: visualci + s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }} + s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }} - run: cargo build --locked -p visualci_server -p visualci-cli - uses: pnpm/action-setup@v4 with: @@ -198,7 +252,21 @@ jobs: node-version: "24" # The Compare two PDFs page runs crates/visualci-wasm in the browser (scripts/wasm.mjs builds it). - run: rustup target add wasm32-unknown-unknown - - uses: Swatinem/rust-cache@v2 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, + # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull + # request can't put artifacts into main's builds. + - uses: kunobi-ninja/kache-action@v1 + with: + version: "2.4.0" + cache-key-prefix: kache-${{ github.job }} + save-cache: ${{ github.ref == 'refs/heads/main' }} + pr-comment: false + s3-bucket: ${{ vars.KACHE_BUCKET }} + s3-endpoint: ${{ vars.KACHE_ENDPOINT }} + s3-region: auto + s3-prefix: visualci + s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }} + s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }} with: key: wasm # The production site: with the Plausible snippets (analytics.ts) and, required, the WebAssembly. diff --git a/app/src/testing.rs b/app/src/testing.rs index 3b9a7f39..4370da6f 100644 --- a/app/src/testing.rs +++ b/app/src/testing.rs @@ -7,7 +7,7 @@ use laravel::Application; use laravel::foundation::ApplicationBuilder; -const CI_DATABASE: &str = "postgres://loco:loco@127.0.0.1:55433/visualci_app_test"; +const CI_DATABASE: &str = "postgres://visualci:visualci@127.0.0.1:55433/visualci_app_test"; pub fn create() -> Application { configure().create() diff --git a/docker/server.Dockerfile b/docker/server.Dockerfile index 3ee54e9d..5693a7fd 100644 --- a/docker/server.Dockerfile +++ b/docker/server.Dockerfile @@ -10,8 +10,20 @@ ARG VISUALCI_ANALYTICS=0 ENV VISUALCI_ANALYTICS=${VISUALCI_ANALYTICS} RUN if [ -f pnpm-lock.yaml ]; then pnpm build; else npm run build; fi -FROM rust:1.99.1-trixie AS build +# Dependencies build in a layer of their own (cargo-chef), rebuilt only when Cargo.toml or Cargo.lock change: a commit +# that only changes our code compiles only our crates. +FROM rust:1.99.1-trixie AS chef +RUN cargo install cargo-chef --locked --version 0.1.78 WORKDIR /src + +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS build +COPY --from=planner /src/recipe.json recipe.json +COPY rust-toolchain.toml ./ +RUN cargo chef cook --release --locked -p visualci_server --recipe-path recipe.json COPY . . ARG BUILD_SHA=dev ENV BUILD_SHA=${BUILD_SHA} From a6a91cb846719c6aa8d59ae18ef475204602b557 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 3 Dec 2026 04:16:58 +1300 Subject: [PATCH 2/3] CI: kache's read-write key is a secret of the kache-write environment, which only main may use; kache-action pinned to a commit --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43d7ef77..d40c0e3b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,13 +23,14 @@ env: jobs: lint: runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }} + environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }} timeout-minutes: 30 steps: - uses: actions/checkout@v4 - # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, - # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull - # request can't put artifacts into main's builds. - - uses: kunobi-ninja/kache-action@v1 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the + # GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment, + # which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key. + - uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1 with: version: "2.4.0" cache-key-prefix: kache-${{ github.job }} @@ -50,6 +51,7 @@ jobs: # The Laravel Rust app (app/, sc-8900): its own workspace until it replaces server/ at cutover. Not deployed yet. app: runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }} + environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }} timeout-minutes: 40 services: postgres: @@ -70,10 +72,10 @@ jobs: docker run -d --name s3 -p 59000:9000 \ -e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret rustfs/rustfs:1.0.6 for _ in $(seq 1 30); do curl -s -o /dev/null http://127.0.0.1:59000/ && break; sleep 1; done - # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, - # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull - # request can't put artifacts into main's builds. - - uses: kunobi-ninja/kache-action@v1 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the + # GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment, + # which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key. + - uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1 with: version: "2.4.0" cache-key-prefix: kache-${{ github.job }} @@ -113,6 +115,7 @@ jobs: test: runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }} + environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }} timeout-minutes: 40 services: postgres: @@ -125,10 +128,10 @@ jobs: options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 steps: - uses: actions/checkout@v4 - # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, - # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull - # request can't put artifacts into main's builds. - - uses: kunobi-ninja/kache-action@v1 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the + # GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment, + # which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key. + - uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1 with: version: "2.4.0" cache-key-prefix: kache-${{ github.job }} @@ -160,6 +163,7 @@ jobs: visual: needs: [test] runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }} + environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }} timeout-minutes: 30 services: postgres: @@ -181,10 +185,10 @@ jobs: docker run -d --name s3 -p 59000:9000 \ -e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret rustfs/rustfs:1.0.6 for _ in $(seq 1 30); do curl -s -o /dev/null http://127.0.0.1:59000/ && break; sleep 1; done - # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, - # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull - # request can't put artifacts into main's builds. - - uses: kunobi-ninja/kache-action@v1 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the + # GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment, + # which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key. + - uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1 with: version: "2.4.0" cache-key-prefix: kache-${{ github.job }} @@ -236,6 +240,7 @@ jobs: clients: runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }} + environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }} timeout-minutes: 15 steps: - uses: actions/checkout@v4 @@ -252,10 +257,10 @@ jobs: node-version: "24" # The Compare two PDFs page runs crates/visualci-wasm in the browser (scripts/wasm.mjs builds it). - run: rustup target add wasm32-unknown-unknown - # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares once KACHE_BUCKET is set, - # else the GitHub Actions cache. Only main writes it; pull requests read (with a read-only key), so a pull - # request can't put artifacts into main's builds. - - uses: kunobi-ninja/kache-action@v1 + # Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the + # GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment, + # which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key. + - uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1 with: version: "2.4.0" cache-key-prefix: kache-${{ github.job }} From 2c568536a33e999afafc185f3a5ce2322061c4c6 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 3 Dec 2026 04:54:12 +1300 Subject: [PATCH 3/3] CI: drop the old cache key the kache step left behind (a duplicated with:, which stopped the workflow from starting) --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d40c0e3b..43ae6e88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -272,8 +272,6 @@ jobs: s3-prefix: visualci s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }} s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }} - with: - key: wasm # The production site: with the Plausible snippets (analytics.ts) and, required, the WebAssembly. - run: pnpm install --frozen-lockfile && VISUALCI_ANALYTICS=1 VISUALCI_REQUIRE_WASM=1 pnpm build working-directory: server/frontend