From ccc97e92dbdaea841c56827fe477698aa652cf54 Mon Sep 17 00:00:00 2001
From: Gilles Filippini <pini@debian.org>
Date: Sun, 16 Jan 2022 02:07:44 +0100
Subject: [PATCH] build (docker): build only when no duniter binary

exists in the 'build' directory.

This allow to use this Dockerfile at CI time (where 'build/duniter' exists)
or for a full build from the source tree.
---
 docker/Dockerfile | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/docker/Dockerfile b/docker/Dockerfile
index 08a77ab1b..cc930872f 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -6,6 +6,7 @@
 # with the image paritytech/ci-linux:production (currently based on
 # debian:buster-slim) used by the gitlab CI
 FROM rust:1-buster as build
+WORKDIR /root
 
 RUN apt-get update && \
     DEBIAN_FRONTEND=noninteractive apt-get install -y \
@@ -16,8 +17,13 @@ COPY . .
 
 # build duniter
 ARG threads=1
-RUN CARGO_PROFILE_RELEASE_LTO="true" \
-        cargo build --release -j $threads
+RUN test -x build/duniter || \
+    ( \
+        CARGO_PROFILE_RELEASE_LTO="true" \
+            cargo build --release -j $threads && \
+        mkdir -p build && \
+        mv target/release/duniter build/ \
+    )
 
 # ------------------------------------------------------------------------------
 # Final Stage
@@ -30,7 +36,7 @@ LABEL version="0.0.0"
 LABEL description="Crypto-currency software (based on Substrate framework) to operate Äž1 libre currency"
 
 # Intall
-COPY --from=build /target/release/duniter /usr/local/bin/duniter
+COPY --from=build /root/build/duniter /usr/local/bin/duniter
 COPY docker/docker-entrypoint /usr/local/bin/
 
 # Configuration
-- 
GitLab