Skip to content

Commit

Permalink
🐳Build a scratch docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
coreequip committed Feb 6, 2025
1 parent 7696606 commit 36bf08b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@ FROM rust:1.84.1-slim-bookworm AS builder

WORKDIR /usr/src/app

# Install musl-tools for static linking
RUN apt-get update && apt-get install -y musl-tools && rm -rf /var/lib/apt/lists/*

# Set the target to musl for static linking with ARM64
RUN rustup target add aarch64-unknown-linux-musl

# Copy the Cargo files to cache dependencies
COPY Cargo.toml Cargo.lock ./

# Create a dummy main.rs to build dependencies
RUN mkdir src && \
echo 'fn main() { println!("Dummy") }' > src/main.rs && \
cargo build --release && \
cargo build --release --target aarch64-unknown-linux-musl && \
rm src/main.rs

# Now copy the actual source code
COPY src ./src

# Build for release
RUN touch src/main.rs && cargo build --release
# Build for release with static linking
RUN touch src/main.rs && \
cargo build --release --target aarch64-unknown-linux-musl

# Runtime stage
FROM debian:bookworm-slim

# Install minimal runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
FROM scratch

# Copy the build artifact from the build stage
COPY --from=builder /usr/src/app/target/release/spf-check /usr/local/bin/
COPY --from=builder /usr/src/app/target/aarch64-unknown-linux-musl/release/spf-check /spf-check

EXPOSE 8080

# Set the startup command to run our binary
CMD ["spf-check"]
CMD ["/spf-check"]

0 comments on commit 36bf08b

Please sign in to comment.