web3-proxy/Dockerfile

136 lines
4.6 KiB
Docker
Raw Normal View History

FROM debian:bullseye-slim as rust
2022-04-23 21:00:03 +03:00
2023-01-31 00:53:58 +03:00
WORKDIR /app
2023-06-27 22:06:43 +03:00
ENV CARGO_UNSTABLE_SPARSE_REGISTRY true
ENV CARGO_TERM_COLOR always
2023-06-26 07:26:17 +03:00
ENV PATH "/root/.foundry/bin:/root/.cargo/bin:${PATH}"
2023-01-31 00:53:58 +03:00
# install rustup dependencies
2023-06-26 02:26:54 +03:00
# also install web3-proxy system dependencies. most things are rust-only, but not everything
2023-06-26 07:26:17 +03:00
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
\
apt-get update && \
apt-get install --no-install-recommends --yes \
build-essential \
2023-06-26 07:26:17 +03:00
ca-certificates \
2023-06-26 02:26:54 +03:00
cmake \
curl \
git \
2023-06-26 02:26:54 +03:00
liblz4-dev \
libpthread-stubs0-dev \
libsasl2-dev \
libzstd-dev \
make \
2023-06-26 07:26:17 +03:00
pkg-config
# install rustup
2023-06-27 09:21:05 +03:00
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
\
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none --profile=minimal
# run a cargo command which install our desired version of rust
2023-06-26 07:26:17 +03:00
COPY rust-toolchain.toml ./
2023-06-27 09:21:05 +03:00
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
2023-06-26 07:26:17 +03:00
\
cargo check || [ "$?" -eq 101 ]
# chef splits up the rust build to hopefully cache better
# hakari manages a 'workspace-hack' to hopefully build faster
# nextest runs tests in parallel
# We only pay the installation cost once, it will be cached from the second build onwards
2023-06-27 09:21:05 +03:00
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
2023-06-26 07:26:17 +03:00
\
cargo install --locked cargo-chef cargo-hakari cargo-nextest
2023-01-31 00:53:58 +03:00
# foundry/anvil are needed to run tests
2023-06-27 09:21:05 +03:00
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
2023-06-26 07:26:17 +03:00
\
curl -L https://foundry.paradigm.xyz | bash && foundryup
2023-01-31 00:53:58 +03:00
# changing our features doesn't change any of the steps above
2023-06-22 03:52:16 +03:00
ENV WEB3_PROXY_FEATURES "rdkafka-src,connectinfo"
# check hakari and chef prep
2023-06-27 22:13:14 +03:00
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target \
\
cargo hakari generate --diff && \
cargo hakari manage-deps --dry-run && \
2023-06-27 22:13:14 +03:00
cargo chef prepare --recipe-path recipe.json
FROM rust as build_tests
# chef cook the test app
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target,sharing=private \
\
2023-06-27 22:13:14 +03:00
cargo chef cook --recipe-path recipe.json
2023-01-31 00:53:58 +03:00
# test the application with cargo-nextest
2023-06-27 22:13:14 +03:00
RUN --mount=type=cache,target=/usr/local/cargo/git \
2023-06-26 07:26:17 +03:00
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target,sharing=private \
2023-06-26 07:26:17 +03:00
\
2023-06-27 22:00:53 +03:00
RUST_LOG=web3_proxy=trace,info cargo --locked nextest run --features "$WEB3_PROXY_FEATURES" --no-default-features && \
2023-06-26 07:26:17 +03:00
touch /test_success
2022-04-23 21:00:03 +03:00
FROM rust as build_app
2023-06-27 22:14:02 +03:00
# chef cook the release app
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target,sharing=private \
\
2023-06-27 22:13:14 +03:00
cargo chef cook --release --recipe-path recipe.json
2023-06-27 22:14:02 +03:00
# build the release application
# using a "release" profile (which install does by default) is **very** important
# TODO: use the "faster_release" profile which builds with `codegen-units = 1`
2023-06-27 22:13:14 +03:00
RUN --mount=type=cache,target=/usr/local/cargo/git \
2023-06-26 07:26:17 +03:00
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target,sharing=private \
2023-06-26 07:26:17 +03:00
\
cargo install \
--features "$WEB3_PROXY_FEATURES" \
--locked \
--no-default-features \
--path ./web3_proxy \
--root /usr/local \
&& [ -e /usr/local/bin/web3_proxy_cli ];
2022-05-06 04:25:49 +03:00
2023-06-27 19:45:16 +03:00
# copy this file so that docker actually creates the build_tests container
# without this, the runtime container doesn't need build_tests and so docker build skips it
COPY --from=build_tests /test_success /
2023-01-31 00:53:58 +03:00
#
# We do not need the Rust toolchain to run the binary!
#
FROM debian:bullseye-slim AS runtime
2023-01-18 08:26:10 +03:00
2023-02-07 00:46:45 +03:00
# Create llama user to avoid running container with root
RUN mkdir /llama \
&& adduser --home /llama --shell /sbin/nologin --gecos '' --no-create-home --disabled-password --uid 1001 llama \
&& chown -R llama /llama
USER llama
ENTRYPOINT ["web3_proxy_cli"]
2023-01-19 13:32:24 +03:00
CMD [ "--config", "/web3-proxy.toml", "proxyd" ]
2022-05-12 22:58:26 +03:00
# TODO: lower log level when done with prototyping
ENV RUST_LOG "warn,ethers_providers::rpc=off,web3_proxy=debug,web3_proxy::rpcs::consensus=info,web3_proxy_cli=debug"
2023-01-31 00:53:58 +03:00
2023-06-26 07:26:17 +03:00
# we copy something from build_tests just so that docker actually builds it
COPY --from=build_app /usr/local/bin/* /usr/local/bin/
# make sure the app works
2023-05-31 03:38:45 +03:00
RUN web3_proxy_cli --help