Skip to content

Commit

Permalink
feat(release): create Docker hub binary with mining enabled on release (
Browse files Browse the repository at this point in the history
#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 <teor@riseup.net>

* adds tag suffix to cache keys

---------

Co-authored-by: teor <teor@riseup.net>
  • Loading branch information
arya2 and teor2345 authored Mar 24, 2023
1 parent 571cbfb commit 671420b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
23 changes: 22 additions & 1 deletion .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:<semver>`
build:
name: Build Release Docker
Expand All @@ -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:<semver>.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
19 changes: 13 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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 /
Expand All @@ -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
#
Expand All @@ -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
Expand Down Expand Up @@ -169,20 +174,22 @@ 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'"; \
echo "[tracing]"; \
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
Expand Down

0 comments on commit 671420b

Please sign in to comment.