diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 710ef512..43ae6e88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,10 +23,25 @@ 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 - - uses: Swatinem/rust-cache@v2 + # 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 }} + 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 @@ -36,13 +51,14 @@ 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: 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 +72,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 (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: - 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 @@ -87,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: @@ -99,7 +128,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 (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 }} + 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: @@ -120,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: @@ -141,7 +185,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 (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 }} + 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: @@ -182,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 @@ -198,9 +257,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 (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: - key: wasm + 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 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 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}