Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 4e806dc

Browse files
authored
feat(docker): new dockerfile (#18)
1 parent 79e6eaa commit 4e806dc

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

Dockerfile

+34-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
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
25

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
77

8-
COPY target/aarch64-unknown-linux-gnu/release/zenith-builder-example /usr/local/bin/zenith-builder-example
8+
WORKDIR /app
99

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

Comments
 (0)