zebra/docker/Dockerfile.build

103 lines
3.2 KiB
Docker

# This steps implement cargo-chef for docker layer caching
# We are using four stages:
# - chef: installs cargo-chef
# - planner: computes the recipe file
# - builder: caches our dependencies and builds the binary
# - tester: builds and run tests
# - runtime: is our runtime environment
FROM rust:bullseye as chef
RUN cargo install cargo-chef --locked
WORKDIR /app
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
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 \
; \
rm -rf /var/lib/apt/lists/* /tmp/*
# Install google OS Config agent
RUN 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 && \
rm -rf /var/lib/apt/lists/* /tmp/*
# Optimize builds. In particular, regenerate-stateful-test-disks.yml was reaching the
# GitHub Actions time limit (6 hours), so we needed to make it faster.
ENV RUSTFLAGS -O
ENV CARGO_HOME /app/.cargo/
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --features enable-sentry --recipe-path recipe.json
ARG RUST_BACKTRACE=1
ENV RUST_BACKTRACE ${RUST_BACKTRACE}
COPY . .
# Build zebra
RUN cargo build --locked --release --features enable-sentry --bin zebrad
FROM builder AS tester
# Pre-download Zcash Sprout and Sapling parameters
# TODO: do not hardcode the user /root/ even though is a safe assumption
COPY --from=us-docker.pkg.dev/zealous-zebra/zebra/zcash-params /root/.zcash-params /root/.zcash-params
# Skip IPv6 tests by default, as some CI environment don't have IPv6 available
ARG ZEBRA_SKIP_IPV6_TESTS=1
ENV ZEBRA_SKIP_IPV6_TESTS ${ZEBRA_SKIP_IPV6_TESTS}
RUN cargo test --locked --release --features enable-sentry --workspace --no-run
CMD ["cargo" "test" "--locked" "--release" "--features" "enable-sentry" "--workspace"]
# Runner image
FROM debian:bullseye-slim AS runtime
COPY --from=builder /app/target/release/zebrad /usr/local/bin
COPY --from=us-docker.pkg.dev/zealous-zebra/zebra/zcash-params /root/.zcash-params /root/.zcash-params
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates
ARG CHECKPOINT_SYNC=true
ARG NETWORK=Mainnet
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"
EXPOSE 3000 8233 18233
ARG SHORT_SHA
ENV SHORT_SHA $SHORT_SHA
ARG SENTRY_DSN
ENV SENTRY_DSN ${SENTRY_DSN}
CMD [ "zebrad", "-c", "zebrad.toml", "start" ]