diff --git a/build/dockerfiles/coordinator.Dockerfile b/build/dockerfiles/coordinator-api.Dockerfile similarity index 85% rename from build/dockerfiles/coordinator.Dockerfile rename to build/dockerfiles/coordinator-api.Dockerfile index 0f501f771c..4ebdb14540 100644 --- a/build/dockerfiles/coordinator.Dockerfile +++ b/build/dockerfiles/coordinator-api.Dockerfile @@ -36,7 +36,7 @@ COPY . . RUN cp -r ./common/libzkp/interface ./coordinator/internal/logic/verifier/lib COPY --from=zkp-builder /app/target/release/libzkp.so ./coordinator/internal/logic/verifier/lib/ COPY --from=zkp-builder /app/target/release/libzktrie.so ./coordinator/internal/logic/verifier/lib/ -RUN cd ./coordinator && make coordinator_skip_libzkp && mv ./build/bin/coordinator /bin/coordinator && mv internal/logic/verifier/lib /bin/ +RUN cd ./coordinator && make coordinator_api_skip_libzkp && mv ./build/bin/coordinator_api /bin/coordinator_api && mv internal/logic/verifier/lib /bin/ # Pull coordinator into a second stage deploy alpine container FROM ubuntu:20.04 @@ -44,7 +44,7 @@ ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/src/coordinator/internal/logic/verifier/li # ENV CHAIN_ID=534353 RUN mkdir -p /src/coordinator/internal/logic/verifier/lib COPY --from=builder /bin/lib /src/coordinator/internal/logic/verifier/lib -COPY --from=builder /bin/coordinator /bin/ -RUN /bin/coordinator --version +COPY --from=builder /bin/coordinator_api /bin/ +RUN /bin/coordinator_api --version -ENTRYPOINT ["/bin/coordinator"] +ENTRYPOINT ["/bin/coordinator_api"] diff --git a/build/dockerfiles/coordinator.Dockerfile.dockerignore b/build/dockerfiles/coordinator-api.Dockerfile.dockerignore similarity index 100% rename from build/dockerfiles/coordinator.Dockerfile.dockerignore rename to build/dockerfiles/coordinator-api.Dockerfile.dockerignore diff --git a/build/dockerfiles/coordinator-cron.Dockerfile b/build/dockerfiles/coordinator-cron.Dockerfile new file mode 100644 index 0000000000..29a38d7180 --- /dev/null +++ b/build/dockerfiles/coordinator-cron.Dockerfile @@ -0,0 +1,50 @@ +# Build libzkp dependency +FROM scrolltech/go-rust-builder:go-1.19-rust-nightly-2022-12-10 as chef +WORKDIR app + +FROM chef as planner +COPY ./common/libzkp/impl/ . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef as zkp-builder +COPY ./common/libzkp/impl/rust-toolchain ./ +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json + +COPY ./common/libzkp/impl . +RUN cargo build --release +RUN find ./ | grep libzktrie.so | xargs -I{} cp {} /app/target/release/ + + +# Download Go dependencies +FROM scrolltech/go-rust-builder:go-1.19-rust-nightly-2022-12-10 as base +WORKDIR /src +COPY go.work* ./ +COPY ./rollup/go.* ./rollup/ +COPY ./common/go.* ./common/ +COPY ./coordinator/go.* ./coordinator/ +COPY ./database/go.* ./database/ +COPY ./prover/go.* ./prover/ +COPY ./tests/integration-test/go.* ./tests/integration-test/ +COPY ./bridge-history-api/go.* ./bridge-history-api/ +RUN go mod download -x + + +# Build coordinator +FROM base as builder +COPY . . +RUN cp -r ./common/libzkp/interface ./coordinator/internal/logic/verifier/lib +COPY --from=zkp-builder /app/target/release/libzkp.so ./coordinator/internal/logic/verifier/lib/ +COPY --from=zkp-builder /app/target/release/libzktrie.so ./coordinator/internal/logic/verifier/lib/ +RUN cd ./coordinator && make coordinator_cron_skip_libzkp && mv ./build/bin/coordinator_cron /bin/coordinator_cron && mv internal/logic/verifier/lib /bin/ + +# Pull coordinator into a second stage deploy alpine container +FROM ubuntu:20.04 +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/src/coordinator/internal/logic/verifier/lib +# ENV CHAIN_ID=534353 +RUN mkdir -p /src/coordinator/internal/logic/verifier/lib +COPY --from=builder /bin/lib /src/coordinator/internal/logic/verifier/lib +COPY --from=builder /bin/coordinator_cron /bin/ +RUN /bin/coordinator_cron --version + +ENTRYPOINT ["/bin/coordinator_cron"] diff --git a/build/dockerfiles/coordinator-cron.Dockerfile.dockerignore b/build/dockerfiles/coordinator-cron.Dockerfile.dockerignore new file mode 100644 index 0000000000..e67a9b0efe --- /dev/null +++ b/build/dockerfiles/coordinator-cron.Dockerfile.dockerignore @@ -0,0 +1,6 @@ +assets/ +contracts/ +docs/ +l2geth/ +rpc-gateway/ +*target/* diff --git a/coordinator/Makefile b/coordinator/Makefile index b9fe1d35b6..0116da4cf8 100644 --- a/coordinator/Makefile +++ b/coordinator/Makefile @@ -1,6 +1,5 @@ .PHONY: lint docker clean coordinator coordinator_skip_libzkp mock_coordinator -IMAGE_NAME=coordinator IMAGE_VERSION=latest REPO_ROOT_DIR=./.. @@ -22,14 +21,23 @@ libzkp: rm -rf ./internal/logic/verifier/lib && cp -r ../common/libzkp/interface ./internal/logic/verifier/lib find ../common | grep libzktrie.so | xargs -I{} cp {} ./internal/logic/verifier/lib -coordinator: libzkp ## Builds the Coordinator instance. - go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator ./cmd +coordinator_api: libzkp ## Builds the Coordinator api instance. + go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator_api ./cmd/api -coordinator_skip_libzkp: - go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator ./cmd +coordinator_cron: libzkp ## Builds the Coordinator cron instance. + go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator_cron ./cmd/cron -mock_coordinator: ## Builds the mocked Coordinator instance. - go build -tags="mock_prover mock_verifier" -o $(PWD)/build/bin/coordinator ./cmd +coordinator_api_skip_libzkp: + go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator_api ./cmd/api + +coordinator_cron_skip_libzkp: + go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator_cron ./cmd/cron + +mock_coordinator_api: ## Builds the mocked Coordinator instance. + go build -tags="mock_prover mock_verifier" -o $(PWD)/build/bin/coordinator_api ./cmd/api + +mock_coordinator_cron: ## Builds the mocked Coordinator instance. + go build -tags="mock_prover mock_verifier" -o $(PWD)/build/bin/coordinator_cron ./cmd/cron test-verifier: libzkp go test -tags ffi -timeout 0 -v ./internal/logic/verifier @@ -45,7 +53,9 @@ clean: ## Empty out the bin folder @rm -rf build/bin docker: - DOCKER_BUILDKIT=1 docker build -t scrolltech/${IMAGE_NAME}:${IMAGE_VERSION} ${REPO_ROOT_DIR}/ -f ${REPO_ROOT_DIR}/build/dockerfiles/coordinator.Dockerfile + DOCKER_BUILDKIT=1 docker build -t scrolltech/coordinator-api:${IMAGE_VERSION} ${REPO_ROOT_DIR}/ -f ${REPO_ROOT_DIR}/build/dockerfiles/coordinator-api.Dockerfile + DOCKER_BUILDKIT=1 docker build -t scrolltech/coordinator-cron:${IMAGE_VERSION} ${REPO_ROOT_DIR}/ -f ${REPO_ROOT_DIR}/build/dockerfiles/coordinator-cron.Dockerfile docker_push: - docker push scrolltech/${IMAGE_NAME}:${IMAGE_VERSION} \ No newline at end of file + docker push scrolltech/coordinator-api:${IMAGE_VERSION} + docker push scrolltech/coordinator-cron:${IMAGE_VERSION} \ No newline at end of file