Created
February 6, 2020 13:56
-
-
Save wrboyce/a23e084f4f65fefecb348b085d0a76d4 to your computer and use it in GitHub Desktop.
Dockerfile experimental syntax for properly cached cargo builds
This file contains 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
# syntax=docker/dockerfile:experimental | |
FROM rust:slim as builder | |
RUN apt-get update && \ | |
apt-get install musl-tools -y && \ | |
apt-get clean && rm -rf /var/lib/apt/lists/* && \ | |
rustup target add x86_64-unknown-linux-musl | |
COPY . . | |
RUN --mount=type=cache,target=/usr/local/cargo,from=rust:slim,source=/usr/local/cargo \ | |
--mount=type=cache,target=target \ | |
RUSTFLAGS=-Clinker=musl-gcc \ | |
cargo build \ | |
--target=x86_64-unknown-linux-musl \ | |
--release && \ | |
cp target/x86_64-unknown-linux-musl/release/foo /foo | |
FROM scratch as main | |
COPY --from=builder /foo /foo | |
ENTRYPOINT ["/foo"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment