-
Notifications
You must be signed in to change notification settings - Fork 13
/
Dockerfile
58 lines (42 loc) · 1.64 KB
/
Dockerfile
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
51
52
53
54
55
56
57
58
# Stage 1: Base compiler image with necessary dependencies
FROM rust:1.81.0-slim-bullseye AS base
# Install cargo-chef for dependency caching
RUN cargo install cargo-chef
# Set the working directory to /app
WORKDIR /app
# Stage 2: Planner (generating the recipe)
FROM base AS planner
# Copy only Cargo files to cache dependencies
COPY Cargo.toml Cargo.lock ./
# Copy the main.rs file to allow cargo do detect a binary
COPY src/main.rs ./src/main.rs
# Prepare the recipe for caching dependencies (Cargo.toml/Cargo.lock)
RUN cargo chef prepare --recipe-path recipe.json
# Stage 3: Builder with necessary dependencies for OpenSSL
FROM base AS builder
# Install required dependencies for building Rust projects (OpenSSL, pkg-config)
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
build-essential \
protobuf-compiler
# Copy the generated recipe from the planner stage
COPY --from=planner /app/recipe.json recipe.json
# Cache the dependencies using the cargo-chef recipe
RUN cargo chef cook --release --recipe-path recipe.json
# Copy the source code and build the project
COPY . .
RUN cargo build --release
# Stage 4: Final runtime image (lean image)
FROM debian:bullseye-slim AS runtime
# Set the working directory for the final container
WORKDIR /usr/local/bin
# Install necessary runtime dependencies (OpenSSL and CA certificates)
RUN apt-get update && apt-get install -y \
libssl-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copy the compiled binary from the builder stage
COPY --from=builder /app/target/release/bolt /usr/local/bin/bolt
# Define the entrypoint for the container
ENTRYPOINT ["/usr/local/bin/bolt"]