Skip to content

Commit e871190

Browse files
committed
hyper: cache dependencies to reduce build time
This change reduces the time it takes to build the hyper Docker image by caching the dependency builds. This is done by building a dummy binary before copying the source code into the image.
1 parent 15c2547 commit e871190

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
FROM rust:1.85 AS hyper
22

33
WORKDIR /src
4-
COPY . .
5-
RUN RUSTFLAGS="-C target-cpu=native" cargo install --path . --locked
4+
ENV RUSTFLAGS="-C target-cpu=native"
5+
6+
# Cache dependency builds (requires passing --force-rm False to tfb command)
7+
COPY Cargo.toml Cargo.lock /src/
8+
RUN mkdir src \
9+
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs \
10+
&& cargo build --release \
11+
&& rm -rfv src/ target/release/hyper-techempower* target/release/deps/hyper_techempower*
12+
13+
COPY . /src/
14+
RUN cargo install --path . --locked
615
EXPOSE 8080
716
CMD ["hyper-techempower"]
817
HEALTHCHECK CMD curl --fail http://localhost:8080/ping || exit 1

0 commit comments

Comments
 (0)