From 4870d8f5c10bcf782cf1b9591a3bcff102106858 Mon Sep 17 00:00:00 2001 From: Artem Makhortov <13339874+artmakh@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:25:12 +0700 Subject: [PATCH] feat(ci): Add Makefile for easy local build (#2985) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Add Makefile for easier local build of all components ## Why ❔ ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. --- README.md | 1 + docker/Makefile | 104 ++++++++++++++++++++++++++++++++++++ docs/guides/build-docker.md | 46 ++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 docker/Makefile create mode 100644 docs/guides/build-docker.md diff --git a/README.md b/README.md index 013d932aa1a..ce73242f11e 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ The following questions will be answered by the following resources: | What do I need to develop the project locally? | [development.md](docs/guides/development.md) | | How can I set up my dev environment? | [setup-dev.md](docs/guides/setup-dev.md) | | How can I run the project? | [launch.md](docs/guides/launch.md) | +| How can I build Docker images? | [build-docker.md](docs/guides/build-docker.md) | | What is the logical project structure and architecture? | [architecture.md](docs/guides/architecture.md) | | Where can I find protocol specs? | [specs.md](docs/specs/README.md) | | Where can I find developer docs? | [docs](https://docs.zksync.io) | diff --git a/docker/Makefile b/docker/Makefile new file mode 100644 index 00000000000..72189902aa1 --- /dev/null +++ b/docker/Makefile @@ -0,0 +1,104 @@ +DOCKER_BUILD_CMD=docker build +PROTOCOL_VERSION=2.0 +CONTEXT=../ +# Additional package versions +DOCKER_VERSION_MIN=27.1.2 +NODE_VERSION_MIN=20.17.0 +YARN_VERSION_MIN=1.22.19 +RUST_VERSION=nightly-2024-08-01 +SQLX_CLI_VERSION=0.8.1 +FORGE_MIN_VERSION=0.2.0 + +# Versions and packages checks +check-nodejs: + @command -v node >/dev/null 2>&1 || { echo >&2 "Node.js is not installed. Please install Node.js v$(NODE_VERSION_MIN) or higher."; exit 1; } + @NODE_VERSION=$$(node --version | sed 's/v//'); \ + if [ "$$(echo $$NODE_VERSION $(NODE_VERSION_MIN) | tr " " "\n" | sort -V | head -n1)" != "$(NODE_VERSION_MIN)" ]; then \ + echo "Node.js version $$NODE_VERSION is too low. Please update to v$(NODE_VERSION_MIN)."; exit 1; \ + fi + +check-yarn: + @command -v yarn >/dev/null 2>&1 || { echo >&2 "Yarn is not installed. Please install Yarn v$(YARN_VERSION_MIN) or higher."; exit 1; } + @YARN_VERSION=$$(yarn --version); \ + if [ "$$(echo $$YARN_VERSION $(YARN_VERSION_MIN) | tr " " "\n" | sort -V | head -n1)" != "$(YARN_VERSION_MIN)" ]; then \ + echo "Yarn version $$YARN_VERSION is too low. Please update to v$(YARN_VERSION_MIN)."; exit 1; \ + fi + +check-rust: + @command -v rustc >/dev/null 2>&1 || { echo >&2 "Rust is not installed. Please install Rust v$(RUST_VERSION)."; exit 1; } + @command rustup install $(RUST_VERSION) >/dev/null 2>&1 + +check-sqlx-cli: + @command -v sqlx >/dev/null 2>&1 || { echo >&2 "sqlx-cli is not installed. Please install sqlx-cli v$(SQLX_CLI_VERSION)"; exit 1; } + @SQLX_CLI_VERSION_LOCAL=$$(sqlx --version | cut -d' ' -f2); \ + if [ "$$(echo $$SQLX_CLI_VERSION_LOCAL $(SQLX_CLI_VERSION) | tr " " "\n" | sort -V | head -n1)" != "$(SQLX_CLI_VERSION)" ]; then \ + echo "sqlx-cli version $$SQLX_CLI_VERSION is wrong. Please update to v$(SQLX_CLI_VERSION)"; exit 1; \ + fi + +check-docker: + @command -v docker >/dev/null 2>&1 || { echo >&2 "Docker is not installed. Please install Docker v$(DOCKER_VERSION_MIN) or higher."; exit 1; } + @DOCKER_VERSION=$$(docker --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+'); \ + if [ "$$(echo $$DOCKER_VERSION $(DOCKER_VERSION_MIN) | tr " " "\n" | sort -V | head -n1)" != "$(DOCKER_VERSION_MIN)" ]; then \ + echo "Docker version $$DOCKER_VERSION is too low. Please update to v$(DOCKER_VERSION_MIN) or higher."; exit 1; \ + fi + +check-foundry: + @command -v forge --version >/dev/null 2>&1 || { echo >&2 "Foundry is not installed. Please install Foundry"; exit 1; } + @FORGE_VERSION=$$(forge --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+'); \ + if [ "$$(echo $$FORGE_VERSION $(FORGE_MIN_VERSION) | tr " " "\n" | sort -V | head -n1)" != "$(FORGE_MIN_VERSION)" ]; then \ + echo "Forge version $$FORGE_VERSION is too low. Please update to v$(FORGE_MIN_VERSION) or higher."; exit 1; \ + fi + +# Check for all required tools +check-tools: check-nodejs check-yarn check-rust check-sqlx-cli check-docker check-foundry + @echo "All required tools are installed." + +# Check that contracts are checkout properly +check-contracts: + @if [ ! -d ../contracts/l1-contracts/lib/forge-std/foundry.toml ] || [ -z "$$(ls -A ../contracts/l1-contracts/lib/forge-std/foundry.toml)" ]; then \ + echo "l1-contracts git submodule is missing. Please re-download repo with `git clone --recurse-submodules https://github.com/matter-labs/zksync-era.git`"; \ + exit 1; \ + fi + +# Build and download needed contracts +prepare-contracts: check-tools check-contracts + @cd ../ && \ + export ZKSYNC_HOME=$$(pwd) && \ + export PATH=$$PATH:$${ZKSYNC_HOME}/bin && \ + zkt || true && \ + zk_supervisor contracts + +# Download setup-key +prepare-keys: + @cd ../ && \ + curl -LO https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2\^26.key + +# Targets for building each container +build-contract-verifier: check-tools prepare-contracts prepare-keys + $(DOCKER_BUILD_CMD) --file contract-verifier/Dockerfile --load \ + --tag contract-verifier:$(PROTOCOL_VERSION) $(CONTEXT) + +build-server-v2: check-tools prepare-contracts prepare-keys + $(DOCKER_BUILD_CMD) --file server-v2/Dockerfile --load \ + --tag server-v2:$(PROTOCOL_VERSION) $(CONTEXT) + +build-circuit-prover-gpu: check-tools prepare-keys + $(DOCKER_BUILD_CMD) --file circuit-prover-gpu/Dockerfile --load \ + --platform linux/amd64 \ + --tag prover:$(PROTOCOL_VERSION) $(CONTEXT) + +build-witness-generator: check-tools prepare-keys + $(DOCKER_BUILD_CMD) --file witness-generator/Dockerfile --load \ + --tag witness-generator:$(PROTOCOL_VERSION) $(CONTEXT) + + +# Build all containers +build-all: build-contract-verifier build-server-v2 build-witness-generator build-circuit-prover-gpu cleanup + +# Clean generated images +clean-all: + @git submodule update --recursive + docker rmi contract-verifier:$(PROTOCOL_VERSION) >/dev/null 2>&1 + docker rmi server-v2:$(PROTOCOL_VERSION) >/dev/null 2>&1 + docker rmi prover:$(PROTOCOL_VERSION) >/dev/null 2>&1 + docker rmi witness-generator:$(PROTOCOL_VERSION) >/dev/null 2>&1 diff --git a/docs/guides/build-docker.md b/docs/guides/build-docker.md new file mode 100644 index 00000000000..a9e8f5d3e76 --- /dev/null +++ b/docs/guides/build-docker.md @@ -0,0 +1,46 @@ +# Build docker images + +This document explains how to build Docker images from the source code, instead of using prebuilt ones we distribute + +## Prerequisites + +Install prerequisites: see + +[Installing dependencies](./setup-dev.md) + +## Build docker files + +You may build all images with [Makefile](../../docker/Makefile) located in [docker](../../docker) directory in this repository + +> All commands should be run from the root directory of the repository + +```shell +make -C ./docker build-all +``` + +You will get those images: + +```shell +contract-verifier:2.0 +server-v2:2.0 +prover:2.0 +witness-generator:2.0 +``` + +Alternatively, you may build only needed components - available targets are + +```shell +make -C ./docker build-contract-verifier +make -C ./docker build-server-v2 +make -C ./docker build-circuit-prover-gpu +make -C ./docker build-witness-generator +``` + +## Building updated images + +Simply run + +```shell +make -C ./docker clean-all +make -C ./docker build-all +```