From 31a128833da19f1ded62a73296c9e1764d97ac13 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 24 Nov 2022 04:00:19 +1100 Subject: [PATCH] feat(ping/rust): Add dummy main to allow for caching of built dependencies (#78) --- ping/rust/Dockerfile | 10 +++++++++- ping/rust/src/main.rs | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 ping/rust/src/main.rs diff --git a/ping/rust/Dockerfile b/ping/rust/Dockerfile index 655160c..9406109 100644 --- a/ping/rust/Dockerfile +++ b/ping/rust/Dockerfile @@ -4,7 +4,12 @@ WORKDIR /usr/src/testplan RUN apt-get update && apt-get install -y cmake protobuf-compiler ARG PLAN_PATH="./" -COPY ./plan/${PLAN_PATH} ./plan + +RUN mkdir -p ./plan/src +COPY ./plan/${PLAN_PATH}/src/main.rs ./plan/src/main.rs +COPY ./plan/${PLAN_PATH}/Cargo.toml ./plan/Cargo.toml +COPY ./plan/${PLAN_PATH}/Cargo.lock ./plan/Cargo.lock + RUN cd ./plan/ && cargo build # Initial build acts as a cache. ARG GIT_TARGET="" @@ -13,6 +18,9 @@ RUN if [ ! -z "${GIT_TARGET}" ]; then sed -i "s,^git.*,git = \"https://${GIT_TAR ARG GIT_REF="" RUN if [ "master" = "${GIT_REF}" ]; then sed -i "s/^rev.*/branch= \"master\"/" ./plan/Cargo.toml; elif [ ! -z "${GIT_REF}" ]; then sed -i "s/^rev.*/rev = \"${GIT_REF}\"/" ./plan/Cargo.toml; fi +COPY ./plan/${PLAN_PATH}/src/lib.rs ./plan/src/lib.rs +COPY ./plan/${PLAN_PATH}/src/bin/ ./plan/src/bin/ + # Build the requested binary: Cargo will update lockfile on changed manifest (i.e. if one of the above `sed`s patched it). ARG BINARY_NAME RUN cd ./plan/ \ diff --git a/ping/rust/src/main.rs b/ping/rust/src/main.rs new file mode 100644 index 0000000..8f55947 --- /dev/null +++ b/ping/rust/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("This is a dummy main file that is used for creating a cache layer inside the docker container.") +}