Created
April 12, 2023 19:22
-
-
Save laundmo/a6557032236a84da93a13e8b69d26131 to your computer and use it in GitHub Desktop.
Rust dockerfile caching
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
FROM rust:1.65 as rust-builder | |
WORKDIR /usr/src/gt_bot | |
# Copy cargo | |
COPY ./Cargo.toml . | |
COPY ./Cargo.lock . | |
# Create fake main.rs file in src and build for dependencies | |
RUN mkdir ./src && echo 'fn main() { println!("Dummy!"); }' >./src/main.rs | |
RUN cargo build --release | |
# Copy source files over | |
RUN rm -rf ./src | |
COPY . . | |
# The last modified attribute of main.rs needs to be updated manually, | |
# otherwise cargo won't rebuild it. | |
RUN touch -a -m ./src/main.rs | |
RUN cargo build --release | |
# Actual final image with only the binary | |
FROM rust:1.65 | |
COPY --from=rust-builder /usr/src/gt_bot/target/release/gt_bot /usr/local/bin/ | |
WORKDIR /usr/local/bin | |
CMD ["gt_bot"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment