2023-05-31 02:32:34 +03:00
|
|
|
FROM debian:bullseye-slim as builder
|
2022-04-23 21:00:03 +03:00
|
|
|
|
2023-01-31 00:53:58 +03:00
|
|
|
WORKDIR /app
|
2023-02-08 22:14:30 +03:00
|
|
|
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
|
|
|
|
2023-05-31 02:32:34 +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 \
|
2023-05-31 02:32:34 +03:00
|
|
|
build-essential \
|
2023-06-26 07:26:17 +03:00
|
|
|
ca-certificates \
|
2023-06-26 02:26:54 +03:00
|
|
|
cmake \
|
2023-05-31 02:32:34 +03:00
|
|
|
curl \
|
|
|
|
git \
|
2023-06-26 02:26:54 +03:00
|
|
|
liblz4-dev \
|
|
|
|
libpthread-stubs0-dev \
|
|
|
|
libsasl2-dev \
|
|
|
|
libssl-dev \
|
|
|
|
libzstd-dev \
|
|
|
|
make \
|
2023-06-26 07:26:17 +03:00
|
|
|
pkg-config
|
|
|
|
|
2023-05-31 02:32:34 +03:00
|
|
|
|
|
|
|
# install rustup
|
2023-06-26 07:35:55 +03:00
|
|
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none --profile=minimal
|
2023-05-31 02:32:34 +03:00
|
|
|
|
2023-06-26 07:35:55 +03:00
|
|
|
# run a cargo command which install our desired version of rust
|
2023-06-26 07:26:17 +03:00
|
|
|
COPY rust-toolchain.toml ./
|
|
|
|
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
|
|
|
\
|
2023-06-26 07:35:55 +03:00
|
|
|
cargo check || [ "$?" -eq 101 ]
|
2023-05-31 02:32:34 +03:00
|
|
|
|
2023-01-31 00:53:58 +03:00
|
|
|
# a next-generation test runner for Rust projects.
|
2023-03-28 22:39:13 +03:00
|
|
|
# We only pay the installation cost once,
|
|
|
|
# it will be cached from the second build onwards
|
2023-01-31 01:51:37 +03:00
|
|
|
# TODO: more mount type cache?
|
2023-01-31 00:53:58 +03:00
|
|
|
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
2023-06-26 07:35:55 +03:00
|
|
|
cargo install cargo-nextest
|
2023-01-31 00:53:58 +03:00
|
|
|
|
|
|
|
# foundry is needed to run tests
|
2023-03-03 13:54:52 +03:00
|
|
|
# TODO: do this in a seperate FROM and COPY it in
|
2023-06-26 07:26:17 +03:00
|
|
|
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
|
|
|
\
|
|
|
|
curl -L https://foundry.paradigm.xyz | bash && foundryup
|
2023-01-31 00:53:58 +03:00
|
|
|
|
2023-06-22 03:52:16 +03:00
|
|
|
ENV WEB3_PROXY_FEATURES "rdkafka-src,connectinfo"
|
2023-05-13 01:15:32 +03:00
|
|
|
|
2023-06-26 02:09:05 +03:00
|
|
|
FROM builder as build_tests
|
|
|
|
|
2023-01-31 00:53:58 +03:00
|
|
|
# test the application with cargo-nextest
|
2023-06-26 07:26:17 +03:00
|
|
|
RUN --mount=type=bind,target=. \
|
|
|
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
2023-01-31 00:53:58 +03:00
|
|
|
--mount=type=cache,target=/app/target \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
|
|
|
RUST_LOG=web3_proxy=trace,info cargo nextest run --features "$WEB3_PROXY_FEATURES" --no-default-features && \
|
|
|
|
touch /test_success
|
2022-04-23 21:00:03 +03:00
|
|
|
|
2023-06-26 07:26:17 +03:00
|
|
|
# TODO: does this split of build_tests and build_app actually do anything if they both mount the same cache?
|
2023-06-26 02:09:05 +03:00
|
|
|
FROM builder as build_app
|
|
|
|
|
2023-01-31 00:53:58 +03:00
|
|
|
# build the application
|
2023-05-31 02:32:34 +03:00
|
|
|
# using a "release" profile (which install does by default) is **very** important
|
2023-06-13 05:02:18 +03:00
|
|
|
# TODO: use the "faster_release" profile which builds with `codegen-units = 1`
|
2023-06-26 07:26:17 +03:00
|
|
|
RUN --mount=type=bind,target=.,rw \
|
|
|
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
2023-01-31 00:53:58 +03:00
|
|
|
--mount=type=cache,target=/app/target \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
2023-03-01 21:53:56 +03:00
|
|
|
cargo install \
|
2023-05-13 01:15:32 +03:00
|
|
|
--features "$WEB3_PROXY_FEATURES" \
|
2023-03-01 21:53:56 +03:00
|
|
|
--locked \
|
|
|
|
--no-default-features \
|
2023-05-31 07:37:58 +03:00
|
|
|
--path ./web3_proxy \
|
2023-04-21 06:00:54 +03:00
|
|
|
--root /usr/local/bin \
|
|
|
|
;
|
2022-05-06 04:25:49 +03:00
|
|
|
|
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
|
|
|
|
|
2023-01-19 13:30:58 +03:00
|
|
|
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
|
2023-06-23 08:45:43 +03:00
|
|
|
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_tests /test_success /
|
2023-06-26 02:09:05 +03:00
|
|
|
COPY --from=build_app /usr/local/bin/* /usr/local/bin/
|
2023-05-31 02:32:34 +03:00
|
|
|
|
|
|
|
# make sure the app works
|
2023-05-31 03:38:45 +03:00
|
|
|
RUN web3_proxy_cli --help
|