-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
50 lines (46 loc) · 1.28 KB
/
Dockerfile
File metadata and controls
50 lines (46 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
FROM lukemathwalker/cargo-chef:latest-rust-1.88-bookworm AS chef
WORKDIR /app
# The generated recipe.json should only change if the dependencies changed
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
ARG BUILD_TYPE=release
ENV SQLX_OFFLINE=true
# Build dependencies - this is cached
COPY --from=planner /app/recipe.json recipe.json
RUN <<EOF
if [ "$BUILD_TYPE" = "release" ]; then
cargo chef cook --release --recipe-path recipe.json;
else
cargo chef cook --recipe-path recipe.json;
fi
EOF
# Build application
COPY . .
RUN <<EOF
if [ "$BUILD_TYPE" = "release" ]; then
cargo build --release;
else
cargo build;
fi
EOF
# Copy it to the same location regardless of build type
RUN <<EOF
if [ "$BUILD_TYPE" = "release" ]; then
cp /app/target/release/chat-backend /app/target;
else
cp /app/target/debug/chat-backend /app/target;
fi
EOF
# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm-slim AS runtime
WORKDIR /app
# Required by AWS-SDK which in turn needs rustls to verify the certificates
RUN <<EOF
apt-get update
apt-get install -y ca-certificates
rm -rf /var/lib/apt/lists/*
EOF
COPY --from=builder /app/target/chat-backend /usr/local/bin
ENTRYPOINT ["/usr/local/bin/chat-backend"]