From 23a8281f5f5128e7df4db53b9a7ab5625136389d Mon Sep 17 00:00:00 2001 From: continuist Date: Fri, 19 Sep 2025 18:35:09 -0400 Subject: [PATCH] Update CI workflow to use new Cargo Chef based approach using pre-built Rust backend images for test stage --- .forgejo/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index ffb68cd..ddda77b 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -14,6 +14,7 @@ jobs: RUN_ID: ${{ github.run_id }} POSTGRES_IMG_DIGEST: ${{ secrets.POSTGRES_IMG_DIGEST }} RUST_IMG_DIGEST: ${{ secrets.RUST_IMG_DIGEST }} + PREBUILT_BACKEND_TEST_IMAGE: ${{ secrets.REGISTRY_HOST }}/${{ github.repository }}/sharenet-test-rust steps: - name: Checkout code @@ -35,9 +36,41 @@ jobs: podman --remote version podman --remote run --rm alpine:3.20 echo "Hello from host rootless Podman!" + - name: Login to container registry with PAT + run: | + echo "${{ secrets.REGISTRY_TOKEN }}" | podman --remote login \ + -u "${{ secrets.REGISTRY_USERNAME }}" \ + --password-stdin \ + "${{ secrets.REGISTRY_HOST }}" + - name: Create network run: podman --remote network create integ-${{ env.RUN_ID }} + - name: Check if dependencies changed + id: check-deps + run: | + # Get hash of Cargo.toml and Cargo.lock + DEPS_HASH=$(sha256sum Cargo.toml Cargo.lock | sha256sum | cut -d' ' -f1) + echo "deps_hash=$DEPS_HASH" >> $GITHUB_OUTPUT + + # Check if image exists with this hash tag + if podman --remote manifest inspect "$PREBUILT_BACKEND_TEST_IMAGE:$DEPS_HASH" >/dev/null 2>&1; then + echo "rebuild_needed=false" >> $GITHUB_OUTPUT + else + echo "rebuild_needed=true" >> $GITHUB_OUTPUT + fi + + - name: Build optimized Rust test image (if needed) + if: steps.check-deps.outputs.rebuild_needed == 'true' + run: | + podman --remote build \ + -f backend/Dockerfile.test-rust \ + -t "$PREBUILT_BACKEND_TEST_IMAGE:${{ steps.check-deps.outputs.deps_hash }}" \ + -t "$PREBUILT_BACKEND_TEST_IMAGE:latest" + + podman --remote push "$PREBUILT_BACKEND_TEST_IMAGE:${{ steps.check-deps.outputs.deps_hash }}" + podman --remote push "$PREBUILT_BACKEND_TEST_IMAGE:latest" + - name: Start PostgreSQL run: | podman --remote run -d \ @@ -63,7 +96,7 @@ jobs: -v /home/ci-service/.cache:/c \ alpine:3.20 sh -lc 'mkdir -p /c/cargo' - - name: Run backend tests (tar-pipe, no bind mount of source) + - name: Run backend tests with cached dependencies run: | set -euo pipefail set -o pipefail @@ -73,11 +106,12 @@ jobs: -e CARGO_HOME=/cargo \ -e DATABASE_URL=postgres://postgres:password@test-postgres-${{ env.RUN_ID }}:5432/sharenet_test \ -v /home/ci-service/.cache/cargo:/cargo \ - "$RUST_IMG_DIGEST" \ + "$PREBUILT_BACKEND_TEST_IMAGE:${{ steps.check-deps.outputs.deps_hash }}" \ sh -euxc ' mkdir -p /workspace tar -x -C /workspace cd /workspace/backend + cargo chef cook --release --recipe-path /app/recipe.json cargo test --lib -- --test-threads=1 '