Why does Heroku rebuild my Docker container every time? Why does Heroku rebuild my Docker container every time? heroku heroku

Why does Heroku rebuild my Docker container every time?


Re-downloading rustc, rust-std, cargo, and rust-docs every time. Re-downloading the same, unchanged dependencies, every time

You should cache these steps.

Re-pushing a 1.02 GB layer every time

You doesn't need any of the Rust toolchains to run the compiled binary application, so you can simply use debian:8-slim or even alpine to run it.

This will reduce the image size to 84.4MB:

FROM rust:1.31 as buildRUN USER=root cargo new --bin my-appWORKDIR /my-app# Copy manifest and build it to cache your dependencies.# If you will change these files, then this step will rebuildCOPY rust-toolchain Cargo.lock Cargo.toml ./RUN cargo build --release && \    rm src/*.rs && \    rm ./target/release/deps/my_app*# Copy your source files and build them.COPY ./src ./srcCOPY ./run ./RUN cargo build --release# Use this image to reduce the final sizeFROM debian:8-slimCOPY --from=build /my-app/run ./COPY --from=build /my-app/target/release/my-app ./target/release/my-appCMD ["./run"]