From 07087581a47b774f48e699ecd3af70bb89e7047e Mon Sep 17 00:00:00 2001 From: Elias Tazartes <66871571+Eikix@users.noreply.github.com> Date: Mon, 6 May 2024 15:26:44 +0200 Subject: [PATCH] feat: indexer dockerfile for karnot (#1018) * feat: indexer dockerfile for karnot * fix sha * test release workflow * fix test * revert testing * answer comments --------- Co-authored-by: Gregory Edison --- .../{kakarot_rpc.yml => kakarot_release.yml} | 36 ++++++++++++++++++- .github/workflows/spell_check.yml | 1 + .github/workflows/test.yml | 1 + README.md | 7 ++-- docker/hive/Dockerfile | 7 ++-- docker/indexer/Dockerfile | 30 ++++++++++++++++ docker/rpc/Dockerfile | 4 +-- docker/rpc/Dockerfile.cross | 4 +-- 8 files changed, 80 insertions(+), 10 deletions(-) rename .github/workflows/{kakarot_rpc.yml => kakarot_release.yml} (75%) create mode 100644 docker/indexer/Dockerfile diff --git a/.github/workflows/kakarot_rpc.yml b/.github/workflows/kakarot_release.yml similarity index 75% rename from .github/workflows/kakarot_rpc.yml rename to .github/workflows/kakarot_release.yml index 8235c6b14..9c78a5b74 100644 --- a/.github/workflows/kakarot_rpc.yml +++ b/.github/workflows/kakarot_release.yml @@ -1,5 +1,5 @@ --- -name: RPC +name: release on: release: @@ -8,6 +8,7 @@ on: env: REGISTRY_IMAGE: ghcr.io/${{ github.repository }}/node DOCKER_USERNAME: ${{ github.actor }} + INDEXER_IMAGE: ghcr.io/${{ github.repository }}/indexer jobs: prepare: @@ -118,3 +119,36 @@ jobs: --tag ${{ env.REGISTRY_IMAGE }}:${{ github.ref_name }} \ --tag ${{ env.REGISTRY_IMAGE }}:latest \ --push + + build-push-indexer-docker: + runs-on: ubuntu-latest-16-cores + strategy: + matrix: + include: + - platform: linux/amd64 + apibara_sink_bin_dir: sci7y4a8r7yz05094pl88h3d7vv1s98f + - platform: linux/arm64 + apibara_sink_bin_dir: 5p0wgpyfsk19v8rrprnykiv5inzx8zag + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ env.DOCKER_USERNAME }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: ${{ env.INDEXER_IMAGE }}:${{ github.ref_name }}, ${{ env.INDEXER_IMAGE }}:latest + context: . + file: ./docker/indexer/Dockerfile + platforms: ${{ matrix.platform }} + build-args: | + APIBARA_SINK_BIN_DIR=${{ matrix.apibara_sink_bin_dir }} diff --git a/.github/workflows/spell_check.yml b/.github/workflows/spell_check.yml index 7b5247a8f..9bb8af863 100644 --- a/.github/workflows/spell_check.yml +++ b/.github/workflows/spell_check.yml @@ -1,3 +1,4 @@ +--- name: Spell Check on: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78342a846..e21323f48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,3 +1,4 @@ +--- name: test on: diff --git a/README.md b/README.md index 858f6a4ff..622dd02e1 100644 --- a/README.md +++ b/README.md @@ -308,10 +308,11 @@ the passing tests: If you which to run our hive test suite locally, the following steps should be taken: - Set up the repo: `make setup`. -- Build a local docker image of the RPC: +- Build a local docker image of the RPC. Check the hive [Dockerfile](docker/hive/Dockerfile) + for the values for `xxx` and `yyy`: ```shell - docker build --build-arg APIBARA_STARKNET_BIN_DIR=f7va4mjqww1kkpp4il6y295dgcwq147v --build-arg APIBARA_SINK_BIN_DIR=5p0wgpyfsk19v8rrprnykiv5inzx8zag -t hive . -f docker/hive/Dockerfile + docker build --build-arg APIBARA_STARKNET_BIN_DIR=xxx --build-arg APIBARA_SINK_BIN_DIR=yyy -t hive . -f docker/hive/Dockerfile ``` - Checkout the Kakarot fork of hive: `git clone https://github.com/kkrt-labs/hive` @@ -462,3 +463,5 @@ Thanks goes to these wonderful people This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! + + diff --git a/docker/hive/Dockerfile b/docker/hive/Dockerfile index 9fa30d654..6605fa4c7 100644 --- a/docker/hive/Dockerfile +++ b/docker/hive/Dockerfile @@ -8,9 +8,10 @@ FROM ghcr.io/dojoengine/dojo:v0.6.0-alpha.6 as katana FROM quay.io/apibara/starknet:1.4.1 as apibara FROM quay.io/apibara/sink-mongo:0.7.0 as indexer FROM debian:bookworm as apibara-build -RUN apt-get update && apt-get install -y patchelf && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install --no-install-recommends -y patchelf && rm -rf /var/lib/apt/lists/* # Apibara Starknet and Sink are built with Nix, so we need to extract the binaries from the Nix store +# ⚠️ When modifying the tag of Apibara, make sure to change the Github CI workflow, and Indexer dockerfile as well # Depending on the platform, the path to the binaries will be different # These values need to be updated if the version of ApiBara Starknet or Sink change. # platform: linux/amd64: @@ -62,7 +63,7 @@ RUN curl -L https://foundry.paradigm.xyz -o foundry.sh \ && chmod +x foundry.sh \ && ./foundry.sh \ && foundryup \ - && apt-get update && apt-get install -y \ + && apt-get update && apt-get install --no-install-recommends -y \ jq \ wget \ docker.io \ @@ -119,7 +120,7 @@ RUN cargo build \ FROM debian:bookworm-slim as base # Install any necessary dependencies -RUN apt-get update && apt-get install -y tini curl jq libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install --no-install-recommends -y tini curl jq libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/* # Environment ############# diff --git a/docker/indexer/Dockerfile b/docker/indexer/Dockerfile new file mode 100644 index 000000000..d3253e0da --- /dev/null +++ b/docker/indexer/Dockerfile @@ -0,0 +1,30 @@ +FROM quay.io/apibara/sink-mongo:0.7.0 as indexer + +FROM debian:latest as apibara-build +RUN apt-get update && apt-get install --no-install-recommends -y patchelf && rm -rf /var/lib/apt/lists/* + +ARG BUILDPLATFORM +ARG APIBARA_SINK_BIN_DIR + +COPY --from=indexer /nix/store/${APIBARA_SINK_BIN_DIR}-apibara-sink-mongo-0.7.0/bin/apibara-sink-mongo /usr/local/bin/sink-mongo + +RUN case $BUILDPLATFORM in \ + "linux/amd64") \ + patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /usr/local/bin/sink-mongo; \ + ;; \ + "linux/arm64") \ + patchelf --set-interpreter /lib/ld-linux-aarch64.so.1 /usr/local/bin/sink-mongo; \ + ;; \ + *) \ + echo "Unknown BUILDPLATFORM: $BUILDPLATFORM"; \ + exit 1; \ + ;; \ + esac + + +FROM debian:latest + +COPY ./indexer /usr/src/app/code +COPY --from=apibara-build /usr/local/bin/sink-mongo /usr/local/bin/sink-mongo + +CMD ["sink-mongo", "run", "/usr/src/app/code/src/main.ts"] diff --git a/docker/rpc/Dockerfile b/docker/rpc/Dockerfile index aa5d29abb..2db3f9015 100644 --- a/docker/rpc/Dockerfile +++ b/docker/rpc/Dockerfile @@ -13,7 +13,7 @@ COPY . . # Install system dependencies RUN apt-get update && \ apt-get -y upgrade && \ - apt-get install -y libclang-dev + apt-get install --no-install-recommends -y libclang-dev RUN cargo build --release --bin kakarot-rpc FROM debian:bookworm-slim AS runtime @@ -38,7 +38,7 @@ HEALTHCHECK --interval=3s --timeout=5s --start-period=1s --retries=5 \ RUN apt-get update && \ apt-get -y upgrade && \ - apt-get install -y libssl-dev ca-certificates tini curl && \ + apt-get install --no-install-recommends -y libssl-dev ca-certificates tini curl && \ rm -rf /var/lib/apt/lists/* # Copy the indexer code into the RPC diff --git a/docker/rpc/Dockerfile.cross b/docker/rpc/Dockerfile.cross index b93148b66..3494e4d97 100644 --- a/docker/rpc/Dockerfile.cross +++ b/docker/rpc/Dockerfile.cross @@ -7,7 +7,7 @@ ARG TARGETARCH # Install any necessary dependencies RUN apt-get update && \ apt-get -y upgrade && \ - apt-get install -y libssl-dev ca-certificates tini curl && \ + apt-get install --no-install-recommends -y libssl-dev ca-certificates tini curl && \ rm -rf /var/lib/apt/lists/* # Copy the built binary. This assumes that the binary @@ -29,7 +29,7 @@ HEALTHCHECK --interval=3s --timeout=5s --start-period=1s --retries=5 \ RUN apt-get update && \ apt-get -y upgrade && \ - apt-get install -y libssl-dev ca-certificates tini curl && \ + apt-get install --no-install-recommends -y libssl-dev ca-certificates tini curl && \ rm -rf /var/lib/apt/lists/* # Copy the indexer code into the RPC