From 3a4af960b69bfe119687f1d0b1257fc07348d07a Mon Sep 17 00:00:00 2001 From: Nick Volynkin Date: Tue, 8 Aug 2023 13:29:46 +0300 Subject: [PATCH] draft --- docker-compose.yml | 45 ++++++++++++++++++++++++++++ scripts/run.sh | 75 ++++++++++++---------------------------------- 2 files changed, 64 insertions(+), 56 deletions(-) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..adfa4d4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +version: '3.5' + +services: + zkllvm: + build: + context: . + dockerfile_inline: | + ARG user_id + ARG group_id + FROM ghcr.io/nilfoundation/zkllvm-template:0.0.86 + RUN useradd nil -u $user_id -g $group_id + args: + user_id: ${user_id} + group_id: ${group_id} + platform: linux/amd64 + user: "${user_id}:${group_id}" + volumes: + - ./:/opt/zkllvm-template + command: bash -c "while true; do sleep 60; done" + tty: true + + toolchain: + # Proof Market toolchain + image: ghcr.io/nilfoundation/proof-market-toolchain:0.0.37 + platform: linux/amd64 + user: "${user_id}:${group_id}" + volumes: + - ./:/opt/zkllvm-template + - ./.config:/.config/ + - ./.config:/root/.config/ + - ./.config/.user:/proof-market-toolchain/scripts/.user + - ./.config/.secret:/proof-market-toolchain/scripts/.secret + command: bash -c "while true; do sleep 60; done" + tty: true + + verifier: + image: ghcr.io/nilfoundation/evm-placeholder-verification:latest + platform: linux/amd64 + user: "${user_id}:${group_id}" + volumes: + - ./:/opt/zkllvm-template + - ./build/template:/opt/evm-placeholder-verification/contracts/zkllvm/template + command: bash -c "while true; do sleep 60; done" + tty: true + diff --git a/scripts/run.sh b/scripts/run.sh index 4299257..76e0c49 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -21,14 +21,8 @@ REPO_ROOT="$SCRIPT_DIR/.." echo "using nilfoundation/zkllvm-template:${ZKLLVM_VERSION:=0.0.86}" echo "using nilfoundation/proof-market-toolchain:${TOOLCHAIN_VERSION:=0.0.37}" -# podman is a safer option for using on CI machines -if ! command -v podman; then - DOCKER="docker" - DOCKER_OPTS="" -else - DOCKER="podman" - DOCKER_OPTS='--detach-keys= --userns=keep-id' -fi +DOCKER="docker" +DOCKER_OPTS="" # checking files that should be produced # on all steps of the pipeline @@ -44,6 +38,15 @@ check_file_exists() { fi } +init() { + touch .config/.user + touch .config/.secret + mkdir -p build/template + export user_id=$(id -u) + export group_id=$(id -g) + docker compose up -d +} + run_zkllvm() { cd $REPO_ROOT # silently stop the existing container if it's running already @@ -78,17 +81,11 @@ run_proof_market_toolchain() { compile() { if [ "$USE_DOCKER" = true ] ; then cd "$REPO_ROOT" - $DOCKER run $DOCKER_OPTS \ - --rm \ - --platform=linux/amd64 \ - --user $(id -u ${USER}):$(id -g ${USER}) \ - --volume $(pwd):/opt/zkllvm-template \ - ghcr.io/nilfoundation/zkllvm-template:${ZKLLVM_VERSION} \ - sh -c "bash ./scripts/run.sh compile" + $DOCKER compose exec zkllvm bash ./scripts/run.sh compile cd - else rm -rf "$REPO_ROOT/build" - mkdir -p "$REPO_ROOT/build" + mkdir -p "$REPO_ROOT/build/template" cd "$REPO_ROOT/build" cmake -DCIRCUIT_ASSEMBLY_OUTPUT=TRUE .. VERBOSE=1 make template @@ -103,13 +100,7 @@ compile() { build_constraint() { if [ "$USE_DOCKER" = true ] ; then cd "$REPO_ROOT" - $DOCKER run $DOCKER_OPTS \ - --rm \ - --platform=linux/amd64 \ - --user $(id -u ${USER}):$(id -g ${USER}) \ - --volume $(pwd):/opt/zkllvm-template \ - ghcr.io/nilfoundation/zkllvm-template:${ZKLLVM_VERSION} \ - sh -c "bash ./scripts/run.sh build_constraint" + $DOCKER compose exec zkllvm bash ./scripts/run.sh build_constraint cd - else cd "$REPO_ROOT/build" @@ -128,13 +119,7 @@ build_constraint() { build_circuit_params() { if [ "$USE_DOCKER" = true ] ; then cd "$REPO_ROOT" - $DOCKER run $DOCKER_OPTS \ - --rm \ - --platform=linux/amd64 \ - --user $(id -u ${USER}):$(id -g ${USER}) \ - --volume $(pwd):/opt/zkllvm-template \ - ghcr.io/nilfoundation/zkllvm-template:${ZKLLVM_VERSION} \ - sh -c "bash ./scripts/run.sh build_circuit_params" + $DOCKER compose exec zkllvm bash ./scripts/run.sh build_circuit_params cd - else cd "$REPO_ROOT/build" @@ -167,16 +152,7 @@ build_circuit_params() { build_statement() { if [ "$USE_DOCKER" = true ] ; then cd "$REPO_ROOT" - $DOCKER run $DOCKER_OPTS \ - --rm \ - --platform=linux/amd64 \ - --user $(id -u ${USER}):$(id -g ${USER}) \ - --volume $(pwd):/opt/zkllvm-template \ - --volume $(pwd)/.config:/.config/ \ - --volume $(pwd)/.config:/root/.config/ \ - --volume $(pwd)/.config:/proof-market-toolchain/.config/ \ - ghcr.io/nilfoundation/proof-market-toolchain:${TOOLCHAIN_VERSION} \ - sh -c "bash /opt/zkllvm-template/scripts/run.sh build_statement" + $DOCKER compose exec toolchain bash /opt/zkllvm-template/scripts/run.sh build_statement cd - else cd /opt/zkllvm-template/ @@ -203,16 +179,7 @@ prove() { # workaround for https://github.com/NilFoundation/proof-market-toolchain/issues/61 mkdir -p .config touch .config/config.ini - $DOCKER run $DOCKER_OPTS \ - --rm \ - --platform=linux/amd64 \ - --user $(id -u ${USER}):$(id -g ${USER}) \ - --volume $(pwd):/opt/zkllvm-template \ - --volume $(pwd)/.config:/.config/ \ - --volume $(pwd)/.config:/root/.config/ \ - --volume $(pwd)/.config:/proof-market-toolchain/.config/ \ - ghcr.io/nilfoundation/proof-market-toolchain:${TOOLCHAIN_VERSION} \ - sh -c "bash /opt/zkllvm-template/scripts/run.sh prove" + $DOCKER compose exec toolchain bash /opt/zkllvm-template/scripts/run.sh prove cd - else cd "$REPO_ROOT" @@ -227,12 +194,7 @@ prove() { verify() { if [ "$USE_DOCKER" = true ] ; then cd "$REPO_ROOT" - $DOCKER run $DOCKER_OPTS \ - --rm \ - --volume $(pwd):/opt/zkllvm-template \ - --volume $(pwd)/build/template:/opt/evm-placeholder-verification/contracts/zkllvm/template \ - ghcr.io/nilfoundation/evm-placeholder-verification:latest \ - sh -c "bash /opt/zkllvm-template/scripts/run.sh verify" + $DOCKER compose exec verifier bash /opt/zkllvm-template/scripts/run.sh verify cd - else cd /opt/evm-placeholder-verification @@ -264,6 +226,7 @@ while [[ "$#" -gt 0 ]]; do build_statement) SUBCOMMAND=build_statement ;; prove) SUBCOMMAND=prove ;; verify) SUBCOMMAND=verify ;; + init) SUBCOMMAND=init ;; run_zkllvm) SUBCOMMAND=run_zkllvm ;; run_proof_market_toolchain) SUBCOMMAND=run_proof_market_toolchain ;; *) echo "Unknown parameter passed: $1"; exit 1 ;;