Closed
Description
I recently found that cargo uses file update time to determine whether to compile. Most times this works fine, but if I uses the following Dockerfile, the build output will remains the same as an bootstrap project.
FROM rust:1.27.0 AS build
WORKDIR /app
RUN USER=root cargo init
COPY Cargo.lock Cargo.toml ./
RUN rustup target add x86_64-unknown-linux-musl
RUN cargo build --release --target x86_64-unknown-linux-musl
COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl
FROM scratch
COPY --from=build /app/target/x86_64-unknown-linux-musl/release/rust-docker /app/rust-docker
ENTRYPOINT [ "/app/rust-docker" ]
The container just outputs Hello world!
as src/main.rs
is changed before the compiled binary. I think cargo should use file content diff to determine whether to compile again, instead of file update time. Using file update time creates a confusion.
To workaround this, a RUN touch src/main.rs
should be added after COPY . .
.