From 9ffe66c7b6b55fd442ff4e2b0485ba91261e712c Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sat, 9 Dec 2023 15:46:52 +0100
Subject: [PATCH] feat(#157): Dockerfile update

---
 distance-oracle/README.md         | 15 ++++++++++++++-
 docker/Dockerfile                 |  6 ++++++
 docker/docker-distance-entrypoint | 21 +++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100755 docker/docker-distance-entrypoint

diff --git a/distance-oracle/README.md b/distance-oracle/README.md
index 5a4233827..b812f3d65 100644
--- a/distance-oracle/README.md
+++ b/distance-oracle/README.md
@@ -17,4 +17,17 @@ This feature is organized in multiple parts:
 - **/distance-oracle/** (here): binary executing the distance algorithm
 - **/primitives/distance/**: primitive types used both by client and runtime
 - **/client/distance/**: exposes the `create_distance_inherent_data_provider` which provides data to the runtime
-- **/pallets/distance/**: distance pallet exposing type, traits, storage/calls/hooks executing in the runtime
\ No newline at end of file
+- **/pallets/distance/**: distance pallet exposing type, traits, storage/calls/hooks executing in the runtime
+
+## Usage (with Docker)
+
+Exemple for GDev:
+
+> Supposes that you have a Docker host with a `/data/duniter-v2s` folder that is used as a mounted volume for a duniter-v2s validator node to `/var/lib/duniter`.
+
+```bash
+docker run --rm -it --entrypoint docker-distance-entrypoint \
+    -v /data/duniter-v2s/chains/gdev/distance/:/distance \
+    -e ORACLE_RPC_URL=wss://gdev.cgeek.fr:443 \
+    duniter/duniter-v2s-gdev:latest
+```
\ No newline at end of file
diff --git a/docker/Dockerfile b/docker/Dockerfile
index b35823409..b24d95334 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -84,6 +84,11 @@ LABEL maintainer="Gilles Filippini <gilles.filippini@pini.fr>"
 LABEL version="0.0.0"
 LABEL description="Crypto-currency software (based on Substrate framework) to operate Äž1 libre currency"
 
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends ca-certificates
+
+RUN update-ca-certificates
+
 RUN adduser --home /var/lib/duniter duniter
 
 # Configuration
@@ -96,3 +101,4 @@ USER duniter
 # Intall
 COPY --from=build /root/build /usr/local/bin/
 COPY docker/docker-entrypoint /usr/local/bin/
+COPY docker/docker-distance-entrypoint /usr/local/bin/
diff --git a/docker/docker-distance-entrypoint b/docker/docker-distance-entrypoint
new file mode 100755
index 000000000..0fd0dfad8
--- /dev/null
+++ b/docker/docker-distance-entrypoint
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Custom startup if a first argument is present and is equal to '--'
+# then we just run duniter with the provided arguments (but the '--')
+# without applying all the automated configuration below
+if [ "$1" = -- ]; then
+  shift
+  distance-oracle "$@"
+fi
+
+ORACLE_RESULT_DIR="${ORACLE_RESULT_DIR:-/distance}"
+ORACLE_EXECUTION_INTERVAL="${ORACLE_EXECUTION_INTERVAL:-1800}"
+ORACLE_MAX_DEPTH="${ORACLE_MAX_DEPTH:-5}"
+ORACLE_RPC_URL="${ORACLE_RPC_URL:-ws://127.0.0.1:9944}"
+ORACLE_LOG_LEVEL="${ORACLE_LOG_LEVEL:-info}"
+
+while [ true ]; do
+  distance-oracle -d "$ORACLE_RESULT_DIR" -D "$ORACLE_MAX_DEPTH" -u "$ORACLE_RPC_URL" -l "$ORACLE_LOG_LEVEL"
+  echo "Waiting $ORACLE_EXECUTION_INTERVAL seconds before next execution..."
+  sleep $ORACLE_EXECUTION_INTERVAL
+done
-- 
GitLab