Skip to content

Commit d76484f

Browse files
authored
dockerfile: cache deps via cargo-chef (#4072)
1 parent f0d00fe commit d76484f

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

.dockerignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
.git
21
target
2+
docker/data
3+
node_modules
4+
.dockerignore
5+
.git
6+
.gitignore

docker/Dockerfile

+35-12
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,51 @@ FROM golang:bullseye as envsubst
88

99
# v1.2.0
1010
ARG ENVSUBST_COMMIT_SHA=16035fe3571ad42c7796bf554f978bb2df64231b
11-
11+
# We ship `envsubst` with the final image to facilitate env. var. templating in
12+
# the configuration file.
1213
RUN go install github.com/a8m/envsubst/cmd/envsubst@$ENVSUBST_COMMIT_SHA \
1314
&& strip -g /go/bin/envsubst
1415

15-
FROM rust:slim-bullseye as graph-node-build
16+
FROM rust:bullseye AS cargo-chef
17+
18+
WORKDIR /app
19+
# Best thing in life after sliced bread.
20+
# <https://github.com/LukeMathWalker/cargo-chef>
21+
# We're not using cargo-chef's prebuilt image for security reasons (not that
22+
# there's anything wrong with it per se). The version is pinned to minimize the
23+
# risk of supply chain attacks.
24+
RUN cargo install cargo-chef --version 0.1.45
25+
26+
FROM cargo-chef AS cargo-chef-plan
27+
28+
COPY . .
29+
RUN cargo chef prepare --recipe-path recipe.json
30+
31+
FROM cargo-chef AS graph-node-build
32+
33+
WORKDIR /graph-node
1634

1735
ARG COMMIT_SHA=unknown
1836
ARG REPO_NAME=unknown
1937
ARG BRANCH_NAME=unknown
2038
ARG TAG_NAME=unknown
2139

22-
ADD . /graph-node
40+
COPY --from=cargo-chef-plan /app/recipe.json cargo-chef-recipe.json
41+
42+
RUN apt-get update \
43+
&& apt-get install -y cmake
44+
RUN RUSTFLAGS="-g" cargo chef cook --release --recipe-path cargo-chef-recipe.json
45+
46+
ADD . .
2347

24-
RUN cd /graph-node \
25-
&& apt-get update && apt-get install -y cmake \
26-
&& rustup component add rustfmt \
27-
&& RUSTFLAGS="-g" cargo install --locked --path node \
48+
RUN RUSTFLAGS="-g" cargo build --release \
49+
&& cp target/release/graph-node /usr/local/bin/graph-node \
50+
&& cp target/release/graphman /usr/local/bin/graphman \
2851
&& cargo clean \
29-
&& objcopy --only-keep-debug /usr/local/cargo/bin/graph-node /usr/local/cargo/bin/graph-node.debug \
30-
&& strip -g /usr/local/cargo/bin/graph-node \
31-
&& strip -g /usr/local/cargo/bin/graphman \
32-
&& cd /usr/local/cargo/bin \
52+
&& objcopy --only-keep-debug /usr/local/bin/graph-node /usr/local/bin/graph-node.debug \
53+
&& strip -g /usr/local/bin/graph-node \
54+
&& strip -g /usr/local/bin/graphman \
55+
&& cd /usr/local/bin \
3356
&& objcopy --add-gnu-debuglink=graph-node.debug graph-node \
3457
&& echo "REPO_NAME='$REPO_NAME'" > /etc/image-info \
3558
&& echo "TAG_NAME='$TAG_NAME'" >> /etc/image-info \
@@ -94,7 +117,7 @@ RUN apt-get update \
94117
&& apt-get install -y libpq-dev ca-certificates netcat
95118

96119
ADD docker/wait_for docker/start /usr/local/bin/
97-
COPY --from=graph-node-build /usr/local/cargo/bin/graph-node /usr/local/cargo/bin/graphman /usr/local/bin/
120+
COPY --from=graph-node-build /usr/local/bin/graph-node /usr/local/bin/graphman /usr/local/bin/
98121
COPY --from=graph-node-build /etc/image-info /etc/image-info
99122
COPY --from=envsubst /go/bin/envsubst /usr/local/bin/
100123
COPY docker/Dockerfile /Dockerfile

0 commit comments

Comments
 (0)