diff --git a/bolt-cli/Dockerfile b/bolt-cli/Dockerfile new file mode 100644 index 000000000..a2b7d8683 --- /dev/null +++ b/bolt-cli/Dockerfile @@ -0,0 +1,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"] diff --git a/bolt-cli/rust-toolchain.toml b/bolt-cli/rust-toolchain.toml new file mode 100644 index 000000000..bbf217f21 --- /dev/null +++ b/bolt-cli/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.81.0" +profile = "default"