Created
September 27, 2019 14:54
-
-
Save technosophos/a0d7ba3ad5d9815e3d4f3582320f5959 to your computer and use it in GitHub Desktop.
Rust Dockerfile hacks for faster builds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM rust:1.37 AS builder | |
WORKDIR /usr/src/buck | |
COPY Cargo.toml . | |
COPY Cargo.lock . | |
# Layer hack: Build an empty program to compile dependencies and place on their own layer. | |
# This cuts down build time | |
RUN mkdir -p ./src/ && \ | |
echo 'fn main() {}' > ./src/main.rs && \ | |
echo '' > ./src/lib.rs | |
RUN cargo fetch | |
RUN cargo build --release && \ | |
rm -rf ./target/release/.fingerprint/buck-* | |
# Build real binaries now | |
COPY ./src ./src | |
RUN cargo build --release | |
# Copy binary into a Debian container | |
FROM debian:stretch-slim | |
WORKDIR /usr/app | |
RUN apt-get update && apt-get install -y openssl && rm -rf /var/lib/apt/lists/* | |
COPY --from=builder /usr/src/buck/target/release/buck . | |
CMD ["./buck"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment