From 671420bd8417d6a583245540501b02c8b1b09fa2 Mon Sep 17 00:00:00 2001 From: Arya Date: Fri, 24 Mar 2023 03:10:40 -0400 Subject: [PATCH] feat(release): create Docker hub binary with mining enabled on release (#6228) * Duplicates Dockerfile * updates mining-testnet Dockerfile with getblocktemplate-rpcs feature, Testnet by default, and an RPC port * renames mining-testnet.Dockerfile and adds workflow for publishing images on release * replaces space-seperated features with commas * Adds .experimental tag suffix, removes new dockerfile, makes lightwalletd tests conditional * updates build-args to pass on features directly * adds "lightwalletd-grpc-tests" as default test_features in build-docker-image * Apply suggestions from code review Co-authored-by: teor * adds tag suffix to cache keys --------- Co-authored-by: teor --- .github/workflows/build-docker-image.yml | 26 +++++++++++++++++++++--- .github/workflows/release-binaries.yml | 23 ++++++++++++++++++++- docker/Dockerfile | 19 +++++++++++------ 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 0344602d..4200bab7 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -37,6 +37,20 @@ on: required: false type: string default: info + features: + required: false + type: string + test_features: + required: false + default: "lightwalletd-grpc-tests" + type: string + rpc_port: + required: false + type: string + tag_suffix: + required: false + type: string + outputs: image_digest: description: 'The image digest to be used on a caller workflow' @@ -72,6 +86,9 @@ jobs: images: | us-docker.pkg.dev/zealous-zebra/zebra/${{ inputs.image_name }} zfnd/zebra,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }} + # appends inputs.tag_suffix to image tags/names + flavor: | + suffix=${{ inputs.tag_suffix }} # generate Docker tags based on the following events/attributes tags: | type=schedule @@ -145,6 +162,9 @@ jobs: ZEBRA_SKIP_IPV6_TESTS=${{ inputs.zebra_skip_ipv6_tests }} CHECKPOINT_SYNC=${{ inputs.checkpoint_sync }} RUST_LOG=${{ inputs.rust_log }} + FEATURES=${{ inputs.features }} + TEST_FEATURES=${{ inputs.test_features }} + RPC_PORT=${{ inputs.rpc_port }} push: true # To improve build speeds, for each branch we push an additional image to the registry, # to be used as the caching layer, using the `max` caching mode. @@ -157,7 +177,7 @@ jobs: # The caches are tried in top-down order, the first available cache is used: # https://github.com/moby/moby/pull/26839#issuecomment-277383550 cache-from: | - type=registry,ref=us-docker.pkg.dev/zealous-zebra/zebra-caching/${{ inputs.image_name }}:${{ env.GITHUB_REF_SLUG_URL }}-cache - type=registry,ref=us-docker.pkg.dev/zealous-zebra/zebra-caching/${{ inputs.image_name }}:main-cache + type=registry,ref=us-docker.pkg.dev/zealous-zebra/zebra-caching/${{ inputs.image_name }}${{ inputs.tag_suffix }}:${{ env.GITHUB_REF_SLUG_URL }}-cache + type=registry,ref=us-docker.pkg.dev/zealous-zebra/zebra-caching/${{ inputs.image_name }}${{ inputs.tag_suffix }}:main-cache cache-to: | - type=registry,ref=us-docker.pkg.dev/zealous-zebra/zebra-caching/${{ inputs.image_name }}:${{ env.GITHUB_REF_SLUG_URL }}-cache,mode=max + type=registry,ref=us-docker.pkg.dev/zealous-zebra/zebra-caching/${{ inputs.image_name }}${{ inputs.tag_suffix }}:${{ env.GITHUB_REF_SLUG_URL }}-cache,mode=max diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml index 71373cca..35a777e0 100644 --- a/.github/workflows/release-binaries.yml +++ b/.github/workflows/release-binaries.yml @@ -17,7 +17,7 @@ on: jobs: # Each time this workflow is executed, a build will be triggered to create a new image # with the corresponding tags using information from git - # + # The image will be named `zebrad:` build: name: Build Release Docker @@ -33,3 +33,24 @@ jobs: rust_log: info # This step needs access to Docker Hub secrets to run successfully secrets: inherit + + # The image will be named `zebrad-mining-rpcs-testnet:.experimental` + build-mining-testnet: + name: Build Release Testnet Mining Docker + uses: ./.github/workflows/build-docker-image.yml + with: + dockerfile_path: ./docker/Dockerfile + dockerfile_target: runtime + image_name: zebrad-mining-rpcs-testnet + # TODO: change this to `-experimental` when we release Zebra `1.0.0` + tag_suffix: .experimental + network: Testnet + rpc_port: '18232' + features: "getblocktemplate-rpcs" + test_features: "" + checkpoint_sync: true + rust_backtrace: '1' + zebra_skip_ipv6_tests: '1' + rust_log: info + # This step needs access to Docker Hub secrets to run successfully + secrets: inherit diff --git a/docker/Dockerfile b/docker/Dockerfile index c2c0c3d6..caa9a538 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -79,6 +79,10 @@ ENV ZEBRA_SKIP_IPV6_TESTS ${ZEBRA_SKIP_IPV6_TESTS:-1} ARG CHECKPOINT_SYNC ENV CHECKPOINT_SYNC ${CHECKPOINT_SYNC:-true} +# Build zebrad with these features +ARG FEATURES +ARG TEST_FEATURES="lightwalletd-grpc-tests" + ARG NETWORK ENV NETWORK ${NETWORK:-Mainnet} @@ -100,10 +104,10 @@ COPY --from=us-docker.pkg.dev/zealous-zebra/zebra/lightwalletd /opt/lightwalletd # This is the caching Docker layer for Rust! # # TODO: is it faster to use --tests here? -RUN cargo chef cook --release --features sentry,lightwalletd-grpc-tests --workspace --recipe-path recipe.json +RUN cargo chef cook --release --features "sentry ${TEST_FEATURES} ${FEATURES}" --workspace --recipe-path recipe.json COPY . . -RUN cargo test --locked --release --features lightwalletd-grpc-tests --workspace --no-run +RUN cargo test --locked --release --features "${TEST_FEATURES} ${FEATURES}" --workspace --no-run RUN cp /opt/zebrad/target/release/zebrad /usr/local/bin COPY ./docker/entrypoint.sh / @@ -118,11 +122,11 @@ ENTRYPOINT [ "/entrypoint.sh" ] # `test` stage. This step is a dependency for the `runtime` stage, which uses the resulting # zebrad binary from this step. FROM deps AS release -RUN cargo chef cook --release --features sentry --recipe-path recipe.json +RUN cargo chef cook --release --features "sentry ${FEATURES}" --recipe-path recipe.json COPY . . # Build zebra -RUN cargo build --locked --release --features sentry --package zebrad --bin zebrad +RUN cargo build --locked --release --features "sentry ${FEATURES}" --package zebrad --bin zebrad # This stage is only used when deploying nodes or when only the resulting zebrad binary is needed # @@ -138,6 +142,7 @@ RUN apt-get update && \ ARG CHECKPOINT_SYNC=true ARG NETWORK=Mainnet +ARG RPC_PORT # Use a configurable dir and file for the zebrad configuration file ARG ZEBRA_CONF_DIR=/etc/zebra @@ -169,12 +174,13 @@ RUN set -ex; \ { \ echo "[network]"; \ echo "network = '${NETWORK}'"; \ + echo "listen_addr = '127.0.0.1'"; \ echo "[consensus]"; \ echo "checkpoint_sync = ${CHECKPOINT_SYNC}"; \ echo "[state]"; \ echo "cache_dir = '/zebrad-cache'"; \ echo "[rpc]"; \ - echo "#listen_addr = '127.0.0.1:8232'"; \ + [ -n "$RPC_PORT" ] && echo "listen_addr = '127.0.0.1:${RPC_PORT}'"; \ echo "parallel_cpu_threads = 0"; \ echo "[metrics]"; \ echo "#endpoint_addr = '127.0.0.1:9999'"; \ @@ -182,7 +188,8 @@ RUN set -ex; \ echo "#endpoint_addr = '127.0.0.1:3000'"; \ } > "${ZEBRA_CONF_PATH}" -EXPOSE 8233 18233 + +EXPOSE 8233 18233 $RPC_PORT ARG SHORT_SHA ENV SHORT_SHA $SHORT_SHA