-
Notifications
You must be signed in to change notification settings - Fork 234
/
Dockerfile
72 lines (59 loc) · 3.34 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Our Dockerfile relies on the PATHFINDER_FORCE_VERSION build-time variable being set.
# This is required so that we don't have to copy the .git directory into the layer which
# might cause caches to be invalidated even if that's unnecessary.
########################################
# Stage 1: Build the pathfinder binary #
########################################
# Note that we're explicitly using the Debian bookworm image to make sure we're
# compatible with the Debian container we'll be copying the pathfinder
# executable to.
FROM --platform=$BUILDPLATFORM lukemathwalker/cargo-chef:0.1.67-rust-1.80-slim-bookworm AS cargo-chef
WORKDIR /usr/src/pathfinder
FROM --platform=$BUILDPLATFORM cargo-chef AS rust-planner
COPY . .
# carg-chef prepare examines your project and builds a recipe that captures
# the set of information required to build your dependencies.
RUN cargo chef prepare --recipe-path recipe.json
FROM --platform=$BUILDPLATFORM cargo-chef AS rust-builder
ARG CARGO_EXTRA_ARGS
ARG TARGETARCH
COPY ./build/prepare.sh prepare.sh
RUN TARGETARCH=${TARGETARCH} ./prepare.sh
# 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.
COPY --from=rust-planner /usr/src/pathfinder/recipe.json recipe.json
COPY ./build/cargo-chef-cook.sh ./cargo-chef-cook.sh
RUN TARGETARCH=${TARGETARCH} ./cargo-chef-cook.sh --profile release-lto --recipe-path recipe.json --package pathfinder --bin pathfinder ${CARGO_EXTRA_ARGS}
# Compile the actual libraries and binary now
COPY . .
ARG PATHFINDER_FORCE_VERSION
COPY ./build/cargo-build.sh ./cargo-build.sh
RUN TARGETARCH=${TARGETARCH} \
PATHFINDER_FORCE_VERSION=${PATHFINDER_FORCE_VERSION} \
./cargo-build.sh --locked --profile release-lto --package pathfinder --bin pathfinder ${CARGO_EXTRA_ARGS} \
&& cp target/*-unknown-linux-gnu/release-lto/pathfinder pathfinder-${TARGETARCH}
#######################
# Final Stage: Runner #
#######################
# Note that we're explicitly using the Debian bookworm image to make sure we're
# compatible with the Rust builder we've built the pathfinder executable in.
FROM debian:bookworm-slim AS runner
ARG TARGETARCH
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates libzstd1 libgmp10 tini && rm -rf /var/lib/apt/lists/*
RUN groupadd --gid 1000 pathfinder && useradd --no-log-init --uid 1000 --gid pathfinder --no-create-home pathfinder
COPY --from=rust-builder /usr/src/pathfinder/pathfinder-${TARGETARCH} /usr/local/bin/pathfinder
# Create directory and volume for persistent data
RUN install --owner 1000 --group 1000 --mode 0755 -d /usr/share/pathfinder/data
VOLUME /usr/share/pathfinder/data
USER 1000:1000
EXPOSE 9545
WORKDIR /usr/share/pathfinder/data
# this is required to have exposing ports work from docker, the default is not this.
ENV PATHFINDER_HTTP_RPC_ADDRESS="0.0.0.0:9545"
# this has been changed in #335 to follow docker best practices example; every
# time it is changed it will be a breaking change. this allows `docker run
# eqlabs/pathfinder --help` to give an introductory path to configuration.
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/pathfinder"]
# empty CMD is needed and cannot be --help because otherwise configuring from
# environment variables only would be impossible and require a workaround.
CMD []