Skip to content

Commit

Permalink
Cache for CI (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen authored Sep 3, 2024
1 parent 2140ee0 commit 609dfc5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
- uses: actions/checkout@v4
- name: Format
run: cargo fmt --all -- --check

clippy:
runs-on: ubuntu-latest
steps:
Expand All @@ -17,18 +18,37 @@ jobs:
run: cargo clippy --fix
- name: Check for diff
run: git diff --exit-code

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose

test:
runs-on: ubuntu-latest-32-core
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- name: Build
run: cargo build --verbose

- name: Run tests
run: ./scripts/e2e_test.sh

- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ RUN cargo install --git https://github.com/lambdaclass/cairo-vm --rev 37ea72977d
FROM ghcr.io/cartridge-gg/stone-prover:main AS prover

FROM python:3.9.18-slim-bookworm AS final

WORKDIR /

RUN apt update && apt install -y build-essential libgmp-dev elfutils jq git
RUN pip install --upgrade pip

RUN git clone --depth=1 -b v2.7.0-rc.3 https://github.com/starkware-libs/cairo.git
RUN mv cairo/corelib/ .
RUN rm -rf cairo

RUN pip install cairo-lang==0.13.1
RUN pip install sympy==1.12.1

COPY --from=builder /app/target/release/prover /usr/local/bin/prover
COPY --from=builder /usr/local/cargo/bin/cairo1-run /usr/local/bin/cairo1-run
COPY --from=prover /usr/bin/cpu_air_prover /usr/local/bin/cpu_air_prover
COPY --from=prover /usr/bin/cpu_air_verifier /usr/local/bin/cpu_air_verifier

COPY --from=builder /app/config/cpu_air_prover_config.json /config/cpu_air_prover_config.json
RUN git clone --depth=1 -b v2.7.0-rc.3 https://github.com/starkware-libs/cairo.git
RUN mv cairo/corelib/ .
RUN rm -rf cairo

RUN pip install cairo-lang==0.13.1
RUN pip install sympy==1.12.1

EXPOSE 3000

Expand Down
23 changes: 17 additions & 6 deletions scripts/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
set -eux
IMAGE_NAME="http-prover-test"
# Check if the image already exists
podman build -t $IMAGE_NAME .
if podman images | grep -q "$IMAGE_NAME"; then

if docker images | grep -q "$IMAGE_NAME"; then
echo "Image $IMAGE_NAME already exists. Skipping build step."
else
echo "Image $IMAGE_NAME does not exist. Building the image..."
podman build -t $IMAGE_NAME .

if [ "${CI:-}" == "true" ]; then
docker buildx build -t $IMAGE_NAME . \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
--output=type=docker,dest=image.tar
docker load -i image.tar
else
docker build -t $IMAGE_NAME .
fi

if [ $? -ne 0 ]; then
echo "Failed to build the image. Exiting."
exit 1
Expand All @@ -25,14 +35,15 @@ KEYGEN_OUTPUT=$(cargo run -p keygen)
ADMIN_PUBLIC_KEY=$(echo "$KEYGEN_OUTPUT" | grep "Public key" | awk '{print $3}' | tr -d ',' | tr -d '[:space:]')
ADMIN_PRIVATE_KEY=$(echo "$KEYGEN_OUTPUT" | grep "Private key" | awk '{print $3}' | tr -d ',' | tr -d '[:space:]')

podman run -d --replace --name http_prover_test \
docker run -d --name http_prover_test \
-p 3040:3000 $IMAGE_NAME \
--jwt-secret-key "secret" \
--message-expiration-time 3600 \
--session-expiration-time 3600 \
--authorized-keys $PUBLIC_KEY,$ADMIN_PUBLIC_KEY \
--admin-key $ADMIN_PUBLIC_KEY
--admin-key $ADMIN_PUBLIC_KEY

PRIVATE_KEY=$PRIVATE_KEY PROVER_URL="http://localhost:3040" ADMIN_PRIVATE_KEY=$ADMIN_PRIVATE_KEY cargo test --no-fail-fast --workspace --verbose

podman stop http_prover_test
docker stop http_prover_test
docker rm http_prover_test

0 comments on commit 609dfc5

Please sign in to comment.