From eb7c0c1989d1b054ef7c5b32416b9995374934a3 Mon Sep 17 00:00:00 2001 From: crebsy <121096251+crebsy@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:47:31 +0200 Subject: [PATCH 1/5] feat: add a second Dockerfile.bundled which bundles third-party binaries to run with rindexer --- .github/workflows/docker.yml | 11 +++++++++-- Dockerfile | 29 ++++++++--------------------- Dockerfile.bundled | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 Dockerfile.bundled diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 11d665df..6f715274 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -9,7 +9,6 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} jobs: build: @@ -18,6 +17,13 @@ jobs: permissions: contents: read packages: write + strategy: + matrix: + include: + - dockerfile: Dockerfile + image: ghcr.io/joshstevens19/rindexer + - dockerfile: Dockerfile.bundled + image: ghcr.io/joshstevens19/rindexer-bundled steps: - name: Checkout repository @@ -38,7 +44,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: ${{ matrix.image }} tags: | type=sha type=sha,format=long @@ -51,6 +57,7 @@ jobs: uses: docker/build-push-action@v6 with: context: . + file: ${{ matrix.dockerfile }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index d0a7af4c..73861727 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,13 @@ -FROM --platform=linux/amd64 rust:1.79-slim-bookworm as builder +FROM --platform=linux/amd64 clux/muslrust:stable as builder ENV CARGO_NET_GIT_FETCH_WITH_CLI=true -RUN apt update && apt install -y libssl-dev binutils libc-dev libstdc++6 pkg-config - +RUN mkdir /app WORKDIR /app COPY . . -RUN cargo build --release -RUN strip /app/target/release/rindexer_cli - -FROM --platform=linux/amd64 node:lts-bookworm as node-builder -RUN apt update && apt install -y ca-certificates -WORKDIR /app -COPY . . -RUN cd /app/graphql && npm i && npm run build-linux - -FROM --platform=linux/amd64 debian:bookworm-slim -RUN apt update \ - && apt install -y libssl-dev libc-dev libstdc++6 ca-certificates lsof \ - && apt-get autoremove --yes \ - && apt-get clean --yes \ - && rm -rf /var/lib/apt/lists/* +RUN rustup target add x86_64-unknown-linux-musl +RUN RUSTFLAGS='-C target-cpu=native' cargo build --release --target x86_64-unknown-linux-musl --features jemalloc +RUN strip /app/target/x86_64-unknown-linux-musl/release/rindexer_cli -COPY --from=node-builder /app/core/resources/rindexer-graphql-linux /app/resources/rindexer-graphql-linux -COPY --from=builder /app/target/release/rindexer_cli /app/rindexer +FROM --platform=linux/amd64 scratch +COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/rindexer_cli /app/rindexer -ENTRYPOINT ["/app/rindexer"] +ENTRYPOINT ["/app/rindexer"] \ No newline at end of file diff --git a/Dockerfile.bundled b/Dockerfile.bundled new file mode 100644 index 00000000..50d4bdf7 --- /dev/null +++ b/Dockerfile.bundled @@ -0,0 +1,26 @@ +FROM --platform=linux/amd64 rust:1.79-slim-bookworm as builder +ENV CARGO_NET_GIT_FETCH_WITH_CLI=true +RUN apt update && apt install -y libssl-dev pkg-config build-essential + +WORKDIR /app +COPY . . +RUN RUSTFLAGS='-C target-cpu=native' cargo build --release --features jemalloc +RUN strip /app/target/release/rindexer_cli + +FROM --platform=linux/amd64 node:lts-bookworm as node-builder +RUN apt update && apt install -y ca-certificates +WORKDIR /app +COPY . . +RUN cd /app/graphql && npm i && npm run build-linux + +FROM --platform=linux/amd64 debian:bookworm-slim +RUN apt update \ + && apt install -y libssl-dev libc-dev libstdc++6 ca-certificates lsof \ + && apt-get autoremove --yes \ + && apt-get clean --yes \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=node-builder /app/core/resources/rindexer-graphql-linux /app/resources/rindexer-graphql-linux +COPY --from=builder /app/target/release/rindexer_cli /app/rindexer + +ENTRYPOINT ["/app/rindexer"] From eb3decd2c8255f37076860faab0432d267149e0b Mon Sep 17 00:00:00 2001 From: crebsy <121096251+crebsy@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:22:58 +0200 Subject: [PATCH 2/5] fix: rename Dockerfile.bundled to bundled.Dockerfile --- .github/workflows/docker.yml | 2 +- Dockerfile.bundled => bundled.Dockerfile | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename Dockerfile.bundled => bundled.Dockerfile (100%) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6f715274..6087733b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -22,7 +22,7 @@ jobs: include: - dockerfile: Dockerfile image: ghcr.io/joshstevens19/rindexer - - dockerfile: Dockerfile.bundled + - dockerfile: bundled.Dockerfile image: ghcr.io/joshstevens19/rindexer-bundled steps: diff --git a/Dockerfile.bundled b/bundled.Dockerfile similarity index 100% rename from Dockerfile.bundled rename to bundled.Dockerfile From b7262dfa20b82a2507788c70409f17f25d51bc5d Mon Sep 17 00:00:00 2001 From: crebsy <121096251+crebsy@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:56:23 +0200 Subject: [PATCH 3/5] fix: copy ssl certs from builder --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 73861727..980c6968 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,5 +9,6 @@ RUN strip /app/target/x86_64-unknown-linux-musl/release/rindexer_cli FROM --platform=linux/amd64 scratch COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/rindexer_cli /app/rindexer +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ ENTRYPOINT ["/app/rindexer"] \ No newline at end of file From 8a330edec653f28925b389c1ef6f50bbbc1a309c Mon Sep 17 00:00:00 2001 From: crebsy <121096251+crebsy@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:20:01 +0200 Subject: [PATCH 4/5] feat: don't strip binaries --- Dockerfile | 1 - bundled.Dockerfile | 1 - 2 files changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 980c6968..fc7c4ae5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ WORKDIR /app COPY . . RUN rustup target add x86_64-unknown-linux-musl RUN RUSTFLAGS='-C target-cpu=native' cargo build --release --target x86_64-unknown-linux-musl --features jemalloc -RUN strip /app/target/x86_64-unknown-linux-musl/release/rindexer_cli FROM --platform=linux/amd64 scratch COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/rindexer_cli /app/rindexer diff --git a/bundled.Dockerfile b/bundled.Dockerfile index 50d4bdf7..390bfddf 100644 --- a/bundled.Dockerfile +++ b/bundled.Dockerfile @@ -5,7 +5,6 @@ RUN apt update && apt install -y libssl-dev pkg-config build-essential WORKDIR /app COPY . . RUN RUSTFLAGS='-C target-cpu=native' cargo build --release --features jemalloc -RUN strip /app/target/release/rindexer_cli FROM --platform=linux/amd64 node:lts-bookworm as node-builder RUN apt update && apt install -y ca-certificates From d2769a5e02ccc892efa65b948b1600f278c8797b Mon Sep 17 00:00:00 2001 From: crebsy <121096251+crebsy@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:20:22 +0200 Subject: [PATCH 5/5] fix: install foundry into image --- Dockerfile | 2 +- bundled.Dockerfile | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index fc7c4ae5..159c13aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ FROM --platform=linux/amd64 scratch COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/rindexer_cli /app/rindexer COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -ENTRYPOINT ["/app/rindexer"] \ No newline at end of file +ENTRYPOINT ["/app/rindexer"] diff --git a/bundled.Dockerfile b/bundled.Dockerfile index 390bfddf..f8971341 100644 --- a/bundled.Dockerfile +++ b/bundled.Dockerfile @@ -14,11 +14,14 @@ RUN cd /app/graphql && npm i && npm run build-linux FROM --platform=linux/amd64 debian:bookworm-slim RUN apt update \ - && apt install -y libssl-dev libc-dev libstdc++6 ca-certificates lsof \ + && apt install -y libssl-dev libc-dev libstdc++6 ca-certificates lsof curl git \ && apt-get autoremove --yes \ && apt-get clean --yes \ && rm -rf /var/lib/apt/lists/* +RUN curl -L https://foundry.paradigm.xyz | bash +RUN /root/.foundry/bin/foundryup + COPY --from=node-builder /app/core/resources/rindexer-graphql-linux /app/resources/rindexer-graphql-linux COPY --from=builder /app/target/release/rindexer_cli /app/rindexer