Skip to content

Commit

Permalink
feat(bolt-cli): add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Nov 7, 2024
1 parent 178b142 commit be2e6b0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bolt-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "bolt"
version = "0.1.0"
edition = "2021"
default-run = "bolt"

[dependencies]
# async
Expand Down Expand Up @@ -40,3 +41,7 @@ tempfile = "3.13.0"

[build-dependencies]
tonic-build = "0.12.3"

[[bin]]
name = "bolt"
path = "./src/main.rs"
55 changes: 55 additions & 0 deletions bolt-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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 ./

# 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"]
3 changes: 3 additions & 0 deletions bolt-cli/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.81.0"
profile = "default"

0 comments on commit be2e6b0

Please sign in to comment.