2023-06-27 21:59:49 +03:00
|
|
|
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-07-28 22:58:23 +03:00
|
|
|
# sccache cannot cache incrementals, but we use --mount=type=cache and import caches so it should be helpful
|
|
|
|
ENV CARGO_INCREMENTAL true
|
2023-02-08 22:14:30 +03:00
|
|
|
ENV CARGO_TERM_COLOR always
|
2023-08-19 02:39:35 +03:00
|
|
|
ENV CARGO_UNSTABLE_SPARSE_REGISTRY true
|
2023-06-26 07:26:17 +03:00
|
|
|
ENV PATH "/root/.foundry/bin:/root/.cargo/bin:${PATH}"
|
2023-08-19 02:39:35 +03:00
|
|
|
ENV SHELL /bin/bash
|
|
|
|
SHELL [ "/bin/bash", "-c" ]
|
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 \
|
2023-07-28 20:43:02 +03:00
|
|
|
set -eux -o pipefail; \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
2023-07-05 21:39:27 +03:00
|
|
|
apt-get update; \
|
2023-06-26 07:26:17 +03:00
|
|
|
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 \
|
|
|
|
libzstd-dev \
|
|
|
|
make \
|
2023-07-05 21:39:27 +03:00
|
|
|
pkg-config \
|
|
|
|
;
|
2023-06-26 07:26:17 +03:00
|
|
|
|
2023-05-31 02:32:34 +03:00
|
|
|
# install rustup
|
2023-07-05 22:44:38 +03:00
|
|
|
RUN --mount=type=cache,target=/root/.cargo/git \
|
|
|
|
--mount=type=cache,target=/root/.cargo/registry \
|
2023-07-28 20:43:02 +03:00
|
|
|
set -eux -o pipefail; \
|
2023-06-27 09:21:05 +03:00
|
|
|
\
|
|
|
|
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-07-05 22:44:38 +03:00
|
|
|
# run a cargo command to install our desired version of rust
|
|
|
|
# it is expected to exit code 101 since no Cargo.toml exists
|
2023-06-26 07:26:17 +03:00
|
|
|
COPY rust-toolchain.toml ./
|
2023-07-05 22:44:38 +03:00
|
|
|
RUN --mount=type=cache,target=/root/.cargo/git \
|
|
|
|
--mount=type=cache,target=/root/.cargo/registry \
|
2023-07-28 20:43:02 +03:00
|
|
|
set -eux -o pipefail; \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
2023-06-26 07:35:55 +03:00
|
|
|
cargo check || [ "$?" -eq 101 ]
|
2023-05-31 02:32:34 +03:00
|
|
|
|
2023-07-22 09:14:12 +03:00
|
|
|
# cargo binstall
|
|
|
|
RUN --mount=type=cache,target=/root/.cargo/git \
|
|
|
|
--mount=type=cache,target=/root/.cargo/registry \
|
2023-07-28 20:43:02 +03:00
|
|
|
set -eux -o pipefail; \
|
2023-07-22 09:14:12 +03:00
|
|
|
\
|
|
|
|
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh >/tmp/install-binstall.sh; \
|
|
|
|
bash /tmp/install-binstall.sh; \
|
|
|
|
rm -rf /tmp/*
|
|
|
|
|
2023-07-05 22:44:38 +03:00
|
|
|
# nextest runs tests in parallel (done its in own FROM so that it can run in parallel)
|
2023-07-22 09:14:12 +03:00
|
|
|
# TODO: i'd like to use binaries for these, but i had trouble with arm and binstall
|
2023-07-05 22:44:38 +03:00
|
|
|
FROM rust as rust_nextest
|
2023-07-28 20:43:02 +03:00
|
|
|
|
2023-07-05 22:44:38 +03:00
|
|
|
RUN --mount=type=cache,target=/root/.cargo/git \
|
|
|
|
--mount=type=cache,target=/root/.cargo/registry \
|
2023-07-28 20:43:02 +03:00
|
|
|
set -eux -o pipefail; \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
2023-07-28 22:58:23 +03:00
|
|
|
cargo binstall -y cargo-nextest
|
2023-01-31 00:53:58 +03:00
|
|
|
|
2023-07-05 22:44:38 +03:00
|
|
|
# foundry/anvil are needed to run tests (done its in own FROM so that it can run in parallel)
|
|
|
|
FROM rust as rust_foundry
|
2023-07-28 20:43:02 +03:00
|
|
|
|
2023-07-05 22:44:38 +03:00
|
|
|
RUN --mount=type=cache,target=/root/.cargo/git \
|
|
|
|
--mount=type=cache,target=/root/.cargo/registry \
|
2023-07-28 20:43:02 +03:00
|
|
|
set -eux -o pipefail; \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
2023-07-28 22:58:23 +03:00
|
|
|
curl -L https://foundry.paradigm.xyz | bash && foundryup
|
2023-01-31 00:53:58 +03:00
|
|
|
|
2023-07-05 22:44:38 +03:00
|
|
|
FROM rust as rust_with_env
|
|
|
|
|
2023-06-27 21:59:49 +03:00
|
|
|
# changing our features doesn't change any of the steps above
|
2023-08-03 10:16:54 +03:00
|
|
|
ENV WEB3_PROXY_FEATURES "rdkafka-src"
|
2023-05-13 01:15:32 +03:00
|
|
|
|
2023-08-19 03:12:43 +03:00
|
|
|
# fill the package caches
|
|
|
|
RUN --mount=type=bind,source=.,target=/app,rw \
|
|
|
|
--mount=type=cache,target=/root/.cargo/git \
|
|
|
|
--mount=type=cache,target=/root/.cargo/registry \
|
|
|
|
--mount=type=cache,target=/app/target \
|
|
|
|
set -eux -o pipefail; \
|
|
|
|
\
|
|
|
|
[ -e "$(pwd)/payment-contracts/src/contracts/mod.rs" ] || touch "$(pwd)/payment-contracts/build.rs"; \
|
|
|
|
cargo \
|
|
|
|
--locked \
|
|
|
|
fetch
|
|
|
|
|
2023-07-05 22:44:38 +03:00
|
|
|
# build tests (done its in own FROM so that it can run in parallel)
|
|
|
|
FROM rust_with_env as build_tests
|
2023-07-05 22:25:33 +03:00
|
|
|
|
2023-07-05 23:04:53 +03:00
|
|
|
COPY --from=rust_foundry /root/.foundry/bin/anvil /root/.foundry/bin/
|
2023-07-05 22:44:38 +03:00
|
|
|
COPY --from=rust_nextest /root/.cargo/bin/cargo-nextest* /root/.cargo/bin/
|
2023-06-27 21:59:49 +03:00
|
|
|
|
2023-06-30 23:18:37 +03:00
|
|
|
# test the application with cargo-nextest
|
2023-08-19 03:02:32 +03:00
|
|
|
RUN --mount=type=bind,source=.,target=/app,rw \
|
|
|
|
--mount=type=cache,target=/root/.cargo/git \
|
2023-07-05 22:44:38 +03:00
|
|
|
--mount=type=cache,target=/root/.cargo/registry \
|
2023-08-19 03:02:32 +03:00
|
|
|
--mount=type=cache,target=/app/target_test \
|
2023-07-28 20:43:02 +03:00
|
|
|
set -eux -o pipefail; \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
2023-08-19 03:02:32 +03:00
|
|
|
export CARGO_TARGET_DIR=target_test; \
|
2023-07-11 04:09:58 +03:00
|
|
|
[ -e "$(pwd)/payment-contracts/src/contracts/mod.rs" ] || touch "$(pwd)/payment-contracts/build.rs"; \
|
2023-07-05 22:52:10 +03:00
|
|
|
RUST_LOG=web3_proxy=trace,info \
|
|
|
|
cargo \
|
2023-08-19 03:14:15 +03:00
|
|
|
--frozen \
|
|
|
|
--offline \
|
2023-07-05 22:52:10 +03:00
|
|
|
nextest run \
|
|
|
|
--features "$WEB3_PROXY_FEATURES" --no-default-features \
|
|
|
|
; \
|
2023-08-19 03:02:32 +03:00
|
|
|
[ -d target_test/debug ]; \
|
2023-06-26 07:26:17 +03:00
|
|
|
touch /test_success
|
2022-04-23 21:00:03 +03:00
|
|
|
|
2023-07-05 22:44:38 +03:00
|
|
|
FROM rust_with_env as build_app
|
2023-06-27 21:59:49 +03:00
|
|
|
|
2023-07-28 23:06:40 +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` (but compile is SLOW)
|
2023-08-19 03:02:32 +03:00
|
|
|
RUN --mount=type=bind,source=.,target=/app,rw \
|
|
|
|
--mount=type=cache,target=/root/.cargo/git \
|
2023-07-05 22:44:38 +03:00
|
|
|
--mount=type=cache,target=/root/.cargo/registry \
|
2023-08-19 03:02:32 +03:00
|
|
|
--mount=type=cache,target=/app/target \
|
2023-07-28 20:43:02 +03:00
|
|
|
set -eux -o pipefail; \
|
2023-06-26 07:26:17 +03:00
|
|
|
\
|
2023-07-11 04:09:58 +03:00
|
|
|
[ -e "$(pwd)/payment-contracts/src/contracts/mod.rs" ] || touch "$(pwd)/payment-contracts/build.rs"; \
|
2023-03-01 21:53:56 +03:00
|
|
|
cargo install \
|
2023-05-13 01:15:32 +03:00
|
|
|
--features "$WEB3_PROXY_FEATURES" \
|
2023-08-19 03:14:15 +03:00
|
|
|
--frozen \
|
|
|
|
--offline \
|
2023-03-01 21:53:56 +03:00
|
|
|
--no-default-features \
|
2023-08-03 10:16:54 +03:00
|
|
|
--path ./web3_proxy_cli \
|
2023-07-05 21:40:43 +03:00
|
|
|
--root /usr/local \
|
|
|
|
; \
|
2023-06-27 22:57:16 +03:00
|
|
|
/usr/local/bin/web3_proxy_cli --help | grep 'Usage: web3_proxy_cli'
|
2022-05-06 04:25:49 +03:00
|
|
|
|
2023-07-05 22:57:20 +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
|
2023-06-27 19:45:16 +03:00
|
|
|
COPY --from=build_tests /test_success /
|
|
|
|
|
2023-01-31 00:53:58 +03:00
|
|
|
#
|
2023-07-05 22:57:20 +03:00
|
|
|
# We do not need the Rust toolchain or any deps to run the binary!
|
2023-01-31 00:53:58 +03:00
|
|
|
#
|
|
|
|
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
|
2023-07-05 21:39:27 +03:00
|
|
|
RUN set -eux; \
|
|
|
|
\
|
|
|
|
mkdir /llama; \
|
|
|
|
adduser --home /llama --shell /sbin/nologin --gecos '' --no-create-home --disabled-password --uid 1001 llama; \
|
2023-07-05 21:40:43 +03:00
|
|
|
chown -R llama /llama
|
2023-02-07 00:46:45 +03:00
|
|
|
|
|
|
|
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
|
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
|