diff --git a/.github/workflows/_rust-crates-checks.yml b/.github/workflows/_rust-crates-checks.yml index 9f06f5d9..a905b478 100644 --- a/.github/workflows/_rust-crates-checks.yml +++ b/.github/workflows/_rust-crates-checks.yml @@ -100,18 +100,8 @@ jobs: contract-suite version: nightly-31dd1f77fd9156d09836486d97963cec7f555343 - # TODO: tmp - # - name: Run tmate - # uses: mxschmitt/action-tmate@v2 - - name: Run tests for shielder-relayer - run: make deps && cd crates/shielder-relayer && make test - - # - name: Install npm deps - # run: make deps && cd crates/shielder-relayer && make test - - # - name: Build relayer image - # run: crates/shielder-relayer && make build-image + run: make deps && cd crates/shielder-relayer && BUILD=client make test - name: Run e2e tooling tests run: | diff --git a/crates/shielder-relayer/Makefile b/crates/shielder-relayer/Makefile index 352701e5..708ac7ce 100644 --- a/crates/shielder-relayer/Makefile +++ b/crates/shielder-relayer/Makefile @@ -2,8 +2,8 @@ SHELL := /bin/bash CARGO_FILES = ../../Cargo.toml ../../Cargo.lock Cargo.toml +BUILD ?= docker DOCKER_USER = "$(id -u):$(id -g)" -DOCKERFILE_PATH = docker/Dockerfile RELAYER_CONTAINER_NAME = shielder-relayer RELAYER_DOCKER_IMAGE = shielder-relayer @@ -26,8 +26,13 @@ lint: ## Run linter @cargo +nightly fmt --all .PHONY: build-image -build-image: build ## Builds a Docker image with the Relayer service binary - @cd ../.. && DOCKER_BUILDKIT=1 docker build --ssh default --tag "${RELAYER_DOCKER_IMAGE}" -f "crates/shielder-relayer/$(DOCKERFILE_PATH)" . +build-image: ## Builds a Docker image with the Relayer service binary +ifeq ($(BUILD), client) + @cargo build --release + @cd ../.. && docker build --tag "${RELAYER_DOCKER_IMAGE}" -f "crates/shielder-relayer/docker/Dockerfile.docker" . +else + @cd ../.. && DOCKER_BUILDKIT=1 docker build --ssh default --tag "${RELAYER_DOCKER_IMAGE}" -f "crates/shielder-relayer/docker/Dockerfile.docker" . +endif .PHONY: run run: build-image stop ## Start the Relayer service in a local Docker container diff --git a/crates/shielder-relayer/docker/Dockerfile b/crates/shielder-relayer/docker/Dockerfile deleted file mode 100644 index 80890036..00000000 --- a/crates/shielder-relayer/docker/Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -# # syntax=docker/dockerfile:experimental - -# FROM debian:bookworm-slim AS build - -# RUN apt-get update && \ -# apt-get install -y \ -# curl \ -# libssl-dev \ -# ca-certificates \ -# build-essential \ -# pkg-config \ -# openssh-client && \ -# rm -rf /tmp/* /var/{tmp,cache}/* /var/lib/{apt,dpkg}/ - -# RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none -# ENV PATH="/root/.cargo/bin:${PATH}" - -# COPY ./crates ./zkos/crates -# COPY ./Cargo.toml ./zkos/Cargo.toml -# COPY ./Cargo.lock ./zkos/Cargo.lock -# COPY ./rust-toolchain.toml ./zkos/rust-toolchain.toml - -# # download public key for github.com -# RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts - -# # RUN cd zkos && cargo build --release -p shielder-relayer \ -# # --config "patch.'ssh://git@github.com/Cardinal-Cryptography/poseidon-gadget'.halo2_poseidon.git='https://github.com/privacy-scaling-explorations/poseidon-gadget'" - -# RUN --mount=type=ssh cd zkos && cargo build --release -p shielder-relayer - -FROM debian:bookworm-slim - -RUN apt-get update && \ - apt-get install -y \ - libssl-dev \ - ca-certificates && \ - rm -rf /tmp/* /var/{tmp,cache}/* /var/lib/{apt,dpkg}/ - -# COPY --from=build /zkos/target/release/shielder-relayer /usr/local/bin -COPY ./target/release/shielder-relayer /usr/local/bin -RUN chmod +x /usr/local/bin/shielder-relayer - -RUN useradd server -USER server - -ENTRYPOINT ["shielder-relayer"] diff --git a/crates/shielder-relayer/docker/Dockerfile.client b/crates/shielder-relayer/docker/Dockerfile.client new file mode 100644 index 00000000..c4b7ff00 --- /dev/null +++ b/crates/shielder-relayer/docker/Dockerfile.client @@ -0,0 +1,15 @@ +FROM debian:bookworm-slim + +RUN apt-get update && \ + apt-get install -y \ + libssl-dev \ + ca-certificates && \ + rm -rf /tmp/* /var/{tmp,cache}/* /var/lib/{apt,dpkg}/ + +COPY ./target/release/shielder-relayer /usr/local/bin +RUN chmod +x /usr/local/bin/shielder-relayer + +RUN useradd server +USER server + +ENTRYPOINT ["shielder-relayer"] diff --git a/crates/shielder-relayer/docker/Dockerfile.docker b/crates/shielder-relayer/docker/Dockerfile.docker new file mode 100644 index 00000000..bfceddd3 --- /dev/null +++ b/crates/shielder-relayer/docker/Dockerfile.docker @@ -0,0 +1,42 @@ +# syntax=docker/dockerfile:experimental + +FROM debian:bookworm-slim AS build + +RUN apt-get update && \ + apt-get install -y \ + curl \ + libssl-dev \ + ca-certificates \ + build-essential \ + pkg-config \ + openssh-client && \ + rm -rf /tmp/* /var/{tmp,cache}/* /var/lib/{apt,dpkg}/ + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none +ENV PATH="/root/.cargo/bin:${PATH}" + +COPY ./crates ./zkos/crates +COPY ./Cargo.toml ./zkos/Cargo.toml +COPY ./Cargo.lock ./zkos/Cargo.lock +COPY ./rust-toolchain.toml ./zkos/rust-toolchain.toml + +# download public key for github.com +RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts + +RUN --mount=type=ssh cd zkos && cargo build --release -p shielder-relayer + +FROM debian:bookworm-slim + +RUN apt-get update && \ + apt-get install -y \ + libssl-dev \ + ca-certificates && \ + rm -rf /tmp/* /var/{tmp,cache}/* /var/lib/{apt,dpkg}/ + +COPY --from=build /zkos/target/release/shielder-relayer /usr/local/bin +RUN chmod +x /usr/local/bin/shielder-relayer + +RUN useradd server +USER server + +ENTRYPOINT ["shielder-relayer"]