From 1bb9b0dae34da341a2477572b4f9da8ab0831a8d Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Sun, 26 Feb 2023 21:22:29 +0100 Subject: [PATCH] docker: simplify duniter subcommand run When the first argument of the entrypoint is '--' then bypass the default configuration via environment variables and directly run duniter with the given parameters (after removing the '--'). The affected scripts and documentation were updated. --- docker/README.md | 8 ++++++++ docker/docker-entrypoint | 9 +++++++++ docs/dev/launch-a-live-network.md | 6 +++--- scripts/create-live-network.sh | 3 +-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docker/README.md b/docker/README.md index e93db2e0f..d93229797 100644 --- a/docker/README.md +++ b/docker/README.md @@ -80,3 +80,11 @@ You can pass any other option to duniter using the `command` docker-compose elem # https://github.com/paritytech/substrate/issues/12073 - "--wasm-execution=interpreted-i-know-what-i-do" ``` + +# Running duniter subcommands or custom set of options + +To run duniter from the command line without the default configuration detailed in the "Environment variables" section use `--` as the first argument. For example: +``` +$ docker run --rm duniter/duniter-v2s:latest -- key generate +$ docker run --rm duniter/duniter-v2s:latest -- --chain gdev ... +``` diff --git a/docker/docker-entrypoint b/docker/docker-entrypoint index 8e751d47b..88bcac05a 100755 --- a/docker/docker-entrypoint +++ b/docker/docker-entrypoint @@ -1,5 +1,14 @@ #!/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 + exec duniter "$@" +fi + +# Normal startup function boolean () { echo "$1" | sed -E 's/^(true|yes|1)$/true/i' } diff --git a/docs/dev/launch-a-live-network.md b/docs/dev/launch-a-live-network.md index c6392efc6..833edeb3d 100644 --- a/docs/dev/launch-a-live-network.md +++ b/docs/dev/launch-a-live-network.md @@ -21,7 +21,7 @@ docker image that you have chosen. Generate a random secret phrase: ```bash -$ docker run --rm -it --entrypoint duniter duniter/duniter-v2s:TAG key generate +$ docker run --rm duniter/duniter-v2s:TAG -- key generate Secret phrase: noble stay fury mean poverty delay stadium organ evil east vague can Secret seed: 0xb39c31fb10c5080721738880c2ea45412cb3df33df022bf8d9a51483b3a9b7a6 Public key (hex): 0x90a0c2866034db9d05f8193a95fe5af8d5e12ab295a501c17c95cdbeaf226d62 @@ -35,7 +35,7 @@ Keep this secret phrase **carefully**, it will be used **several** times later. Then, generate the session keys: ```bash -$ docker run --rm -it --entrypoint duniter duniter/duniter-v2s:TAG key generate-session-keys --chain CURRENCY_local --suri "<your secret phrase>" +$ docker run --rm duniter/duniter-v2s:TAG -- key generate-session-keys --chain CURRENCY_local --suri "<your secret phrase>" Session Keys: 0x87189d723e1b2826c243bc433c718ac26ba60526932216a09102a254d54462b890a0c2866034db9d05f8193a95fe5af8d5e12ab295a501c17c95cdbeaf226d6290a0c2866034db9d05f8193a95fe5af8d5e12ab295a501c17c95cdbeaf226d6290a0c2866034db9d05f8193a95fe5af8d5e12ab295a501c17c95cdbeaf226d62 ``` @@ -46,7 +46,7 @@ An example of genesis configuration file: `resources/gdev.json` ## 5. Generate raw spec ```docker -docker run -v $HOME/dev/duniter-v2s/resources:/var/lib/duniter/resources -e DUNITER_GENESIS_CONFIG=/var/lib/duniter/resources/gdev.json --rm -it --entrypoint duniter duniter/duniter-v2s:TAG build-spec -lerror --chain=gdev-gl --raw > name-raw.json +docker run -v $HOME/dev/duniter-v2s/resources:/var/lib/duniter/resources -e DUNITER_GENESIS_CONFIG=/var/lib/duniter/resources/gdev.json --rm duniter/duniter-v2s:TAG -- build-spec -lerror --chain=gdev-gl --raw > name-raw.json ``` ```bash diff --git a/scripts/create-live-network.sh b/scripts/create-live-network.sh index 5e9bd62b8..dbf0c86c5 100755 --- a/scripts/create-live-network.sh +++ b/scripts/create-live-network.sh @@ -31,8 +31,7 @@ mkdir -p $WORK_DIR/duniter-validator/chains/$CURRENCY # Helper to execute a duniter subcommand in docker function duniter_tmp () { - docker rm duniter-tmp > /dev/null - OUTPUT=$(docker run --name duniter-tmp -it --entrypoint duniter duniter/duniter-v2s:$DUNITER_IMAGE_TAG "$@") + OUTPUT=$(docker run --rm --name duniter-tmp duniter/duniter-v2s:$DUNITER_IMAGE_TAG -- "$@") echo "${OUTPUT::-1}" } -- GitLab