42 lines
1.7 KiB
Docker
42 lines
1.7 KiB
Docker
# Dockerfile
|
|
|
|
# ---- Planner Stage ----
|
|
# Use the official Rust Alpine image as a base for planning.
|
|
# We use the same base image for planner and builder for consistency.
|
|
FROM rust:1-alpine AS planner
|
|
WORKDIR /app
|
|
# Install cargo-chef for build caching
|
|
RUN apk add --no-cache musl-dev # Needed by chef
|
|
RUN cargo install cargo-chef --locked
|
|
COPY . .
|
|
# Compute dependencies. This output will be cached if Cargo.toml/lock haven't changed.
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
# ---- Builder Stage ----
|
|
# Use the same Rust Alpine image for building.
|
|
FROM rust:1-alpine AS builder
|
|
WORKDIR /app
|
|
# Install build dependencies for Alpine
|
|
RUN apk add --no-cache build-base openssl-dev pkgconfig
|
|
# Install cargo-chef again (could optimize but simpler this way)
|
|
RUN cargo install cargo-chef --locked
|
|
# Copy the dependency recipe from the planner stage
|
|
COPY --from=planner /app/recipe.json recipe.json
|
|
# Build dependencies based on the recipe. This layer is cached efficiently.
|
|
RUN cargo chef cook --release --recipe-path recipe.json
|
|
# Copy application code
|
|
COPY . .
|
|
# Build the application binary, linking against pre-built dependencies
|
|
# Ensure the binary name matches your package name in Cargo.toml
|
|
RUN cargo build --release --bin discord-music-bot-lavalink-rs
|
|
|
|
# ---- Runtime Stage ----
|
|
# Use a minimal Alpine image for the final runtime environment.
|
|
FROM alpine:latest
|
|
WORKDIR /app
|
|
# Install runtime dependencies needed by the binary (e.g., SSL certs)
|
|
RUN apk add --no-cache ca-certificates openssl
|
|
# Copy the compiled application binary from the builder stage
|
|
COPY --from=builder /app/target/release/discord-music-bot-lavalink-rs /app/
|
|
# Set the binary as the entrypoint
|
|
CMD ["./discord-music-bot-lavalink-rs"] |