Last active
May 1, 2021 05:04
-
-
Save jbg/dc7d271f7da261e424393c73b73024a1 to your computer and use it in GitHub Desktop.
multi-stage Dockerfile for rust builds that allows building stages after `cargo fetch` without network access
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
# Example usage: | |
# docker build --target=fetcher . | |
# docker build --network=none -t "$TAG" . | |
FROM rust-builder:0.2.1 AS fetcher | |
COPY Cargo.toml Cargo.lock ./ | |
RUN mkdir src \ | |
&& touch src/main.rs \ | |
&& cargo fetch --locked | |
# The following stages can be built without network access | |
FROM rust-builder:0.2.1 AS builder | |
COPY . . | |
COPY --from=fetcher /usr/local/cargo/ /usr/local/cargo/ | |
RUN cargo lichking check \ | |
&& cargo +nightly fmt -- --check --files-with-diff \ | |
&& cargo clippy -- -D warnings \ | |
&& cargo build --release --frozen | |
FROM alpine-runtime:0.3.0 | |
COPY --from=builder /target/release/program-name /usr/local/bin/ | |
USER app | |
ENTRYPOINT ["/usr/local/bin/program-name"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment