web3-proxy/Dockerfile

88 lines
3.1 KiB
Docker
Raw Normal View History

2023-01-31 00:53:58 +03:00
#
# cargo-chef
# We only pay the installation cost once,
# it will be cached from the second build onwards
#
FROM rust:1-bullseye AS chef
2022-04-23 21:00:03 +03:00
2023-01-31 00:53:58 +03:00
WORKDIR /app
2023-01-31 01:51:37 +03:00
# # cargo binstall provides a low-complexity mechanism for installing rust binaries as an alternative to building from source (via cargo install) or manually downloading packages.
# # This is intended to work with existing CI artifacts and infrastructure, and with minimal overhead for package maintainers.
# # TODO: more mount type cache?
# # TODO: this works on some architectures, but is failing on others.
# RUN --mount=type=cache,target=/usr/local/cargo/registry \
# cargo install cargo-binstall
2023-01-31 00:53:58 +03:00
# cache the dependencies of your Rust project and speed up your Docker builds.
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-01-31 01:51:37 +03:00
cargo install cargo-chef
2023-01-31 00:53:58 +03:00
# a next-generation test runner for Rust projects.
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-01-31 01:51:37 +03:00
cargo install cargo-nextest
2023-01-31 00:53:58 +03:00
#
# prepare examines your project and builds a recipe that captures the set of information required to build your dependencies.
# The recipe.json is the equivalent of the Python requirements.txt file - it is the only input required for cargo chef cook, the command that will build out our dependencies:
#
FROM chef AS prepare
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target \
cargo chef prepare --recipe-path recipe.json
#
# test and build web3-proxy
#
FROM chef AS builder
# foundry is needed to run tests
2022-12-15 06:25:57 +03:00
ENV PATH /root/.foundry/bin:$PATH
RUN curl -L https://foundry.paradigm.xyz | bash && foundryup
2023-01-31 00:53:58 +03:00
# copy dependency config from the previous step
COPY --from=prepare /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
# TODO: if the main app does `codegen-units = 1`, how much time is this actually saving us?
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target \
cargo chef cook --release --recipe-path recipe.json
# copy the application
2022-04-23 21:00:03 +03:00
COPY . .
2023-01-31 00:53:58 +03:00
# test the application with cargo-nextest
ENV CARGO_TERM_COLOR always
2022-04-23 21:00:03 +03:00
RUN --mount=type=cache,target=/usr/local/cargo/registry \
2023-01-31 00:53:58 +03:00
--mount=type=cache,target=/app/target \
cargo nextest run
2022-04-23 21:00:03 +03:00
2023-01-31 00:53:58 +03:00
# build the application
# using a "release" profile (which install does) is **very** important
2023-01-31 00:53:58 +03:00
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target \
cargo install --locked --no-default-features --profile faster_release --root /opt/bin --path ./web3_proxy
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
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-01-25 10:21:39 +03:00
ENV RUST_LOG "warn,web3_proxy=debug,web3_proxy_cli=debug"
2023-01-31 00:53:58 +03:00
COPY --from=builder /opt/bin/* /usr/local/bin/