# https://whitfin.io/speeding-up-rust-docker-builds/ # TODO: https://stackoverflow.com/questions/57389547/how-to-define-the-context-for-a-docker-build-as-a-specific-commit-on-one-of-the # 1.47 slim-buster FROM rust@sha256:2a902de987345f126fe59daca200afae1fccb6f68e14e9a27c0fd9cf39f9743f as build #RUN apk add libseccomp-dev WORKDIR / ENV USER root # create empty shell projects RUN cargo new --bin ptth WORKDIR /ptth RUN \ cargo new --lib crates/always_equal && \ cargo new --lib crates/ptth_core && \ cargo new --bin crates/ptth_file_server_bin && \ cargo new --bin crates/ptth_relay && \ cargo new --bin crates/ptth_server # copy over your manifests COPY ./Cargo.lock ./ COPY ./Cargo.toml ./ COPY ./crates/always_equal/Cargo.toml ./crates/always_equal/ COPY ./crates/ptth_core/Cargo.toml ./crates/ptth_core/ COPY ./crates/ptth_relay/Cargo.toml ./crates/ptth_relay/ COPY ./crates/ptth_file_server_bin/Cargo.toml ./crates/ptth_file_server_bin/ COPY ./crates/ptth_server/Cargo.toml ./crates/ptth_server/ # this build step will cache your dependencies RUN cargo build --release -p ptth_relay RUN \ rm \ src/*.rs \ crates/always_equal/src/*.rs \ crates/ptth_core/src/*.rs \ crates/ptth_file_server_bin/src/*.rs \ crates/ptth_relay/src/*.rs \ crates/ptth_server/src/*.rs # Copy source tree # Yes, I tried a few variations on the syntax. Dockerfiles are just rough. COPY ./src/ ./src COPY ./crates/ ./crates COPY ./handlebars/ ./handlebars # Bug in cargo's incremental build logic, triggered by # Docker doing something funny with mtimes? Maybe? RUN touch crates/ptth_core/src/lib.rs ARG git_version RUN echo -n "$git_version" > crates/ptth_relay/src/git_version.txt # build for release # gate only on ptth_relay tests for now RUN \ cargo build --release -p ptth_relay && \ cargo test --release -p ptth_relay # buster-slim FROM debian@sha256:062bbd9a1a58c9c5b8fc9d83a206371127ef268cfcc65f1a01227c6faebdb212 RUN apt-get update \ && apt-get install -y libssl1.1 ca-certificates \ && apt-get upgrade -y COPY --from=build /ptth/target/release/ptth_relay /root/ COPY --from=build /ptth/crates/ptth_relay/src/git_version.txt /root/ COPY --from=build /ptth/handlebars /root/handlebars WORKDIR /root ENTRYPOINT ["./ptth_relay"]