@@ -8,28 +8,51 @@ FROM golang:bullseye as envsubst
8
8
9
9
# v1.2.0
10
10
ARG ENVSUBST_COMMIT_SHA=16035fe3571ad42c7796bf554f978bb2df64231b
11
-
11
+ # We ship `envsubst` with the final image to facilitate env. var. templating in
12
+ # the configuration file.
12
13
RUN go install github.com/a8m/envsubst/cmd/envsubst@$ENVSUBST_COMMIT_SHA \
13
14
&& strip -g /go/bin/envsubst
14
15
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
16
34
17
35
ARG COMMIT_SHA=unknown
18
36
ARG REPO_NAME=unknown
19
37
ARG BRANCH_NAME=unknown
20
38
ARG TAG_NAME=unknown
21
39
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 . .
23
47
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 \
28
51
&& 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 \
33
56
&& objcopy --add-gnu-debuglink=graph-node.debug graph-node \
34
57
&& echo "REPO_NAME='$REPO_NAME'" > /etc/image-info \
35
58
&& echo "TAG_NAME='$TAG_NAME'" >> /etc/image-info \
@@ -94,7 +117,7 @@ RUN apt-get update \
94
117
&& apt-get install -y libpq-dev ca-certificates netcat
95
118
96
119
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/
98
121
COPY --from=graph-node-build /etc/image-info /etc/image-info
99
122
COPY --from=envsubst /go/bin/envsubst /usr/local/bin/
100
123
COPY docker/Dockerfile /Dockerfile
0 commit comments