1
- FROM arm64v8/ubuntu:latest
1
+ # syntax=docker/dockerfile:1.7-labs
2
+ # ## STAGE 0: Create base chef image for building
3
+ # ## cargo chef is used to speed up the build process by caching dependencies using docker
4
+ FROM --platform=$TARGETPLATFORM lukemathwalker/cargo-chef:latest-rust-latest as chef
2
5
3
- RUN apt-get update && apt-get install -y curl unzip
4
- RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
5
- RUN unzip awscliv2.zip
6
- RUN ./aws/install
6
+ RUN cargo install cargo-chef
7
7
8
- COPY target/aarch64-unknown-linux-gnu/release/zenith-builder-example /usr/local/bin/zenith-builder-example
8
+ WORKDIR /app
9
9
10
- # Run the server
11
- CMD ["/usr/local/bin/zenith-builder-example" ]
10
+ # ## Stage 1: cargo chef prepare
11
+ # ## Creates the recipe.json file which is a manifest of Cargo.toml files and
12
+ # ## the relevant Cargo.lock file
13
+ FROM chef as planner
14
+ COPY --exclude=target . .
15
+ RUN cargo chef prepare
16
+
17
+ # ## Stage 2: Build the project
18
+ # ## This stage builds the deps of the project (not the code) using cargo chef cook
19
+ # ## and then it copies the source code and builds the actual crates
20
+ # ## this takes advantage of docker layer caching to the max
21
+ FROM chef as builder
22
+ COPY --from=planner /app/recipe.json recipe.json
23
+ RUN apt-get update && apt-get -y upgrade && apt-get install -y gcc libclang-dev pkg-config libssl-dev
24
+ RUN rustup target add x86_64-unknown-linux-gnu
25
+ RUN rustup toolchain install stable-x86_64-unknown-linux-gnu
26
+
27
+ RUN cargo chef cook --release --target x86_64-unknown-linux-gnu --recipe-path recipe.json --bin zenith-builder-example
28
+ COPY --exclude=target . .
29
+
30
+ RUN cargo build --release --target x86_64-unknown-linux-gnu --bin zenith-builder-example
31
+
32
+ # Stage 3: Final image for running in the env
33
+ FROM --platform=$TARGETPLATFORM debian:bookworm-slim
34
+
35
+ COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/zenith-builder-example /usr/local/bin/zenith-builder-example
36
+
37
+ ENTRYPOINT [ "/usr/local/bin/zenith-builder-example" ]
0 commit comments