2022-05-10 14:00:09 -07:00
|
|
|
# We are using five stages:
|
2022-02-08 16:50:13 -08:00
|
|
|
# - chef: installs cargo-chef
|
|
|
|
# - planner: computes the recipe file
|
2022-05-10 14:00:09 -07:00
|
|
|
# - deps: caches our dependencies and sets the needed variables
|
|
|
|
# - tests: builds tests
|
|
|
|
# - release: builds release binary
|
2022-02-08 16:50:13 -08:00
|
|
|
# - runtime: is our runtime environment
|
2022-05-10 14:00:09 -07:00
|
|
|
#
|
|
|
|
# This stage implements cargo-chef for docker layer caching
|
2022-02-08 16:50:13 -08:00
|
|
|
FROM rust:bullseye as chef
|
|
|
|
RUN cargo install cargo-chef --locked
|
|
|
|
WORKDIR /app
|
|
|
|
|
2022-05-11 07:06:58 -07:00
|
|
|
# Analyze the current project to determine the minimum subset of files
|
2022-05-10 14:00:09 -07:00
|
|
|
# (Cargo.lock and Cargo.toml manifests) required to build it and cache dependencies
|
|
|
|
#
|
|
|
|
# The recipe.json is the equivalent of the Python requirements.txt file
|
2022-02-08 16:50:13 -08:00
|
|
|
FROM chef AS planner
|
|
|
|
COPY . .
|
|
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
|
2022-05-10 14:00:09 -07:00
|
|
|
# In this stage we download all system requirements to build the project
|
|
|
|
#
|
|
|
|
# It also captures all the build arguments to be used as environment variables.
|
|
|
|
# We set defaults for the arguments, in case the build does not include this information.
|
|
|
|
FROM chef AS deps
|
2022-03-02 16:39:41 -08:00
|
|
|
SHELL ["/bin/bash", "-xo", "pipefail", "-c"]
|
2022-02-08 16:50:13 -08:00
|
|
|
COPY --from=planner /app/recipe.json recipe.json
|
|
|
|
|
|
|
|
# Install zebra build deps
|
|
|
|
RUN apt-get -qq update && \
|
|
|
|
apt-get -qq install -y --no-install-recommends \
|
|
|
|
llvm \
|
|
|
|
libclang-dev \
|
|
|
|
clang \
|
|
|
|
ca-certificates \
|
2022-04-27 16:06:11 -07:00
|
|
|
protobuf-compiler \
|
2022-02-08 16:50:13 -08:00
|
|
|
; \
|
|
|
|
rm -rf /var/lib/apt/lists/* /tmp/*
|
|
|
|
|
2022-05-10 14:00:09 -07:00
|
|
|
# Install google OS Config agent to be able to get information from the VMs being deployed
|
|
|
|
# into GCP for integration testing purposes, and as Mainnet nodes
|
2022-05-15 22:33:08 -07:00
|
|
|
# TODO: this shouldn't be a hardcoded requirement for everyone
|
2022-03-02 16:39:41 -08:00
|
|
|
RUN if [ "$(uname -m)" != "aarch64" ]; then \
|
|
|
|
apt-get -qq update && \
|
|
|
|
apt-get -qq install -y --no-install-recommends \
|
|
|
|
curl \
|
|
|
|
lsb-release \
|
|
|
|
&& \
|
|
|
|
echo "deb http://packages.cloud.google.com/apt google-compute-engine-$(lsb_release -cs)-stable main" > /etc/apt/sources.list.d/google-compute-engine.list && \
|
|
|
|
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
|
|
|
|
apt-get -qq update && \
|
|
|
|
apt-get -qq install -y --no-install-recommends google-osconfig-agent; \
|
|
|
|
fi \
|
|
|
|
&& \
|
2022-02-08 16:50:13 -08:00
|
|
|
rm -rf /var/lib/apt/lists/* /tmp/*
|
|
|
|
|
2022-05-10 14:00:09 -07:00
|
|
|
# Build arguments and variables set to change how tests are run, tracelog levels,
|
|
|
|
# and Network to be used (Mainnet or Testnet)
|
|
|
|
#
|
|
|
|
# We set defaults to all variables.
|
2022-03-02 06:15:24 -08:00
|
|
|
ARG RUST_BACKTRACE
|
2022-03-08 07:09:41 -08:00
|
|
|
ENV RUST_BACKTRACE ${RUST_BACKTRACE:-0}
|
|
|
|
|
|
|
|
ARG RUST_LIB_BACKTRACE
|
|
|
|
ENV RUST_LIB_BACKTRACE ${RUST_LIB_BACKTRACE:-0}
|
|
|
|
|
|
|
|
ARG COLORBT_SHOW_HIDDEN
|
|
|
|
ENV COLORBT_SHOW_HIDDEN ${COLORBT_SHOW_HIDDEN:-0}
|
2022-03-02 06:15:24 -08:00
|
|
|
|
2022-05-05 02:27:07 -07:00
|
|
|
ARG RUST_LOG
|
|
|
|
ENV RUST_LOG ${RUST_LOG:-info}
|
|
|
|
|
2022-03-02 06:15:24 -08:00
|
|
|
# Skip IPv6 tests by default, as some CI environment don't have IPv6 available
|
|
|
|
ARG ZEBRA_SKIP_IPV6_TESTS
|
|
|
|
ENV ZEBRA_SKIP_IPV6_TESTS ${ZEBRA_SKIP_IPV6_TESTS:-1}
|
|
|
|
|
|
|
|
# Use default checkpoint sync and network values if none is provided
|
|
|
|
ARG CHECKPOINT_SYNC
|
|
|
|
ENV CHECKPOINT_SYNC ${CHECKPOINT_SYNC:-true}
|
|
|
|
|
|
|
|
ARG NETWORK
|
|
|
|
ENV NETWORK ${NETWORK:-Mainnet}
|
|
|
|
|
2022-05-10 14:00:09 -07:00
|
|
|
ENV CARGO_HOME /app/.cargo/
|
2020-11-18 11:41:47 -08:00
|
|
|
|
2022-05-10 14:00:09 -07:00
|
|
|
# In this stage we build tests (without running then)
|
|
|
|
#
|
|
|
|
# We also download needed dependencies for tests to work, from other images.
|
|
|
|
# An entrypoint.sh is only available in this step for easier test handling with variables.
|
|
|
|
FROM deps AS tests
|
2022-02-08 16:50:13 -08:00
|
|
|
# TODO: do not hardcode the user /root/ even though is a safe assumption
|
2022-05-10 14:00:09 -07:00
|
|
|
# Pre-download Zcash Sprout, Sapling parameters and Lightwalletd binary
|
2022-02-08 16:50:13 -08:00
|
|
|
COPY --from=us-docker.pkg.dev/zealous-zebra/zebra/zcash-params /root/.zcash-params /root/.zcash-params
|
2022-03-02 01:00:55 -08:00
|
|
|
COPY --from=us-docker.pkg.dev/zealous-zebra/zebra/lightwalletd /lightwalletd /usr/local/bin
|
2020-12-03 19:51:42 -08:00
|
|
|
|
2022-05-10 14:00:09 -07:00
|
|
|
# Re-hydrate the minimum project skeleton identified by `cargo chef prepare` in the planner stage,
|
2022-05-11 07:06:58 -07:00
|
|
|
# and build it to cache all possible sentry and test dependencies.
|
|
|
|
#
|
2022-05-10 14:00:09 -07:00
|
|
|
# This is the caching Docker layer for Rust!
|
2022-05-11 07:06:58 -07:00
|
|
|
#
|
|
|
|
# TODO: is it faster to use --tests here?
|
2022-06-16 12:56:40 -07:00
|
|
|
RUN cargo chef cook --release --features sentry,lightwalletd-grpc-tests --workspace --recipe-path recipe.json
|
2022-05-10 14:00:09 -07:00
|
|
|
|
|
|
|
COPY . .
|
2022-05-11 07:06:58 -07:00
|
|
|
RUN cargo test --locked --release --features lightwalletd-grpc-tests --workspace --no-run
|
2020-11-18 11:41:47 -08:00
|
|
|
|
2022-03-02 06:15:24 -08:00
|
|
|
COPY ./docker/entrypoint.sh /
|
|
|
|
RUN chmod u+x /entrypoint.sh
|
|
|
|
|
2022-05-11 16:41:33 -07:00
|
|
|
# By default, runs the entrypoint tests specified by the environmental variables (if any are set)
|
2022-03-02 06:15:24 -08:00
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
|
CMD [ "cargo"]
|
2020-11-18 11:41:47 -08:00
|
|
|
|
2022-05-10 14:00:09 -07:00
|
|
|
# In this stage we build a release (generate the zebrad binary)
|
|
|
|
#
|
2022-05-11 07:06:58 -07:00
|
|
|
# This step also adds `cargo chef` as this stage is completely independent from the
|
2022-05-10 14:00:09 -07:00
|
|
|
# `test` stage. This step is a dependency for the `runtime` stage, which uses the resulting
|
|
|
|
# zebrad binary from this step.
|
|
|
|
FROM deps AS release
|
2022-06-16 12:56:40 -07:00
|
|
|
RUN cargo chef cook --release --features sentry --recipe-path recipe.json
|
2022-05-10 14:00:09 -07:00
|
|
|
|
|
|
|
COPY . .
|
|
|
|
# Build zebra
|
2022-06-16 12:56:40 -07:00
|
|
|
RUN cargo build --locked --release --features sentry --package zebrad --bin zebrad
|
2022-05-10 14:00:09 -07:00
|
|
|
|
|
|
|
# This stage is only used when deploying nodes or when only the resulting zebrad binary is needed
|
|
|
|
#
|
|
|
|
# To save space, this step starts from scratch using debian, and only adds the resulting
|
|
|
|
# binary from the `release` stage, and the Zcash Sprout & Sapling parameters from ZCash
|
2022-02-08 16:50:13 -08:00
|
|
|
FROM debian:bullseye-slim AS runtime
|
2022-05-10 14:00:09 -07:00
|
|
|
COPY --from=release /app/target/release/zebrad /usr/local/bin
|
2022-02-08 16:50:13 -08:00
|
|
|
COPY --from=us-docker.pkg.dev/zealous-zebra/zebra/zcash-params /root/.zcash-params /root/.zcash-params
|
2020-11-18 11:41:47 -08:00
|
|
|
|
2020-12-04 02:54:18 -08:00
|
|
|
RUN apt-get update && \
|
2022-02-08 16:50:13 -08:00
|
|
|
apt-get install -y --no-install-recommends \
|
|
|
|
ca-certificates
|
2020-11-18 11:41:47 -08:00
|
|
|
|
2022-05-10 14:00:09 -07:00
|
|
|
ARG CHECKPOINT_SYNC=true
|
|
|
|
ARG NETWORK=Mainnet
|
|
|
|
|
|
|
|
# Build the `zebrad.toml` before starting the container, using the arguments from build
|
|
|
|
# time, or using the default values set just above.
|
2022-02-08 16:50:13 -08:00
|
|
|
RUN set -ex; \
|
|
|
|
{ \
|
|
|
|
echo "[consensus]"; \
|
|
|
|
echo "checkpoint_sync = ${CHECKPOINT_SYNC}"; \
|
|
|
|
echo "[metrics]"; \
|
|
|
|
echo "endpoint_addr = '0.0.0.0:9999'"; \
|
|
|
|
echo "[network]"; \
|
|
|
|
echo "network = '${NETWORK}'"; \
|
|
|
|
echo "[state]"; \
|
|
|
|
echo "cache_dir = '/zebrad-cache'"; \
|
|
|
|
echo "[tracing]"; \
|
|
|
|
echo "endpoint_addr = '0.0.0.0:3000'"; \
|
|
|
|
} > "zebrad.toml"
|
2021-11-19 15:02:56 -08:00
|
|
|
|
2020-11-18 11:41:47 -08:00
|
|
|
EXPOSE 3000 8233 18233
|
|
|
|
|
2022-02-08 16:50:13 -08:00
|
|
|
ARG SHORT_SHA
|
|
|
|
ENV SHORT_SHA $SHORT_SHA
|
|
|
|
|
|
|
|
ARG SENTRY_DSN
|
|
|
|
ENV SENTRY_DSN ${SENTRY_DSN}
|
2020-11-22 18:19:08 -08:00
|
|
|
|
2022-02-08 16:50:13 -08:00
|
|
|
CMD [ "zebrad", "-c", "zebrad.toml", "start" ]
|