From 2c0b4c222484d5f7660e2fe9622a5710cb3c6438 Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Sun, 9 May 2021 02:56:56 +0200 Subject: [PATCH 1/6] ref(docker): move duniter.sh code into entrypoint And link duniter binary as /usr/bin/duniter. --- release/docker/Dockerfile | 7 ++----- release/docker/docker-entrypoint.sh | 21 +++++++++++++++++++++ release/docker/duniter.sh | 24 ------------------------ 3 files changed, 23 insertions(+), 29 deletions(-) delete mode 100644 release/docker/duniter.sh diff --git a/release/docker/Dockerfile b/release/docker/Dockerfile index af4de2ec1..a702099db 100644 --- a/release/docker/Dockerfile +++ b/release/docker/Dockerfile @@ -27,7 +27,6 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y RUN PATH=${HOME}/.cargo/bin:${PATH} \ RUSTFLAGS="-C target-feature=-crt-static" \ make -C release ADD_DEBUG=N server-gui clean \ - && cp release/docker/duniter.sh work/docker.sh \ && rm -rf work/extra # ------------------------------------------------------------------------------ @@ -47,10 +46,8 @@ RUN mkdir -p /var/lib/duniter /etc/duniter && chown duniter:duniter /var/lib/dun # copy the build artifact from the build stage COPY --from=build --chown=duniter:duniter /duniter/work /duniter/duniter -# copy bootstrap script -RUN cp /duniter/duniter/docker.sh /usr/bin/duniter && \ - chmod +x /usr/bin/duniter && \ - chown duniter:duniter /usr/bin/duniter +# install duniter executable symlink +RUN ln -s /duniter/duniter/bin/duniter /usr/bin/duniter # copy entrypoint COPY release/docker/docker-entrypoint.sh / diff --git a/release/docker/docker-entrypoint.sh b/release/docker/docker-entrypoint.sh index 4bf845b0b..1cef9442d 100755 --- a/release/docker/docker-entrypoint.sh +++ b/release/docker/docker-entrypoint.sh @@ -86,7 +86,28 @@ if [ "$auto_sync" = true ]; then fi fi +# Network interface to listen to +export DUNITER_WEB_UI_HOST="0.0.0.0" + +# Key file found +if [ -f /etc/duniter/key.yml ]; then + export DUNITER_KEYFILE="/etc/duniter/keys.yml" +fi + +# Without parameters, start with web interface +if [ $# = 0 ]; then + set -- direct_webstart +fi + +# Set --home option +set -- --home "$home" "$@" + +# Define DUNITER_CONF_HOME +DUNITER_CONF_HOME="/etc/duniter" +export DUNITER_CONF_HOME + # Start duniter +cd /duniter/duniter echo Starting duniter with: echo /usr/bin/duniter "$@" /usr/bin/duniter "$@" diff --git a/release/docker/duniter.sh b/release/docker/duniter.sh deleted file mode 100644 index f98ce5933..000000000 --- a/release/docker/duniter.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -# Without parameters, start with web interface -if [[ -z ${1} ]]; then - set -- direct_webstart -fi - -# Define DUNITER_WEB_UI_HOST -DUNITER_WEB_UI_HOST="0.0.0.0" -export DUNITER_WEB_UI_HOST - -# Define DUNITER_CONF_HOME -DUNITER_CONF_HOME="/etc/duniter" -export DUNITER_CONF_HOME - -# Key file found -if [[ -f /etc/duniter/key.yml ]]; then - DUNITER_KEYFILE="/etc/duniter/keys.yml" - export DUNITER_KEYFILE -fi - -# Start duniter -cd /duniter/duniter/ -bin/duniter --home /var/lib/duniter "$@" -- GitLab From 1426872ff2895b079e0c06906c9e2c875aea7f4c Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Sun, 9 May 2021 03:01:56 +0200 Subject: [PATCH 2/6] build(docker): add .dockerignore file --- .dockerignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..ab8aaa028 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.cargo +.git* +doc +gui +test -- GitLab From 23b11afaeb95a2d1a890ca765e02b80b1aa0d50c Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Sun, 9 May 2021 03:05:18 +0200 Subject: [PATCH 3/6] doc(dev): fix commit naming example --- doc/dev/git-conventions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/git-conventions.md b/doc/dev/git-conventions.md index d9dffd0ef..e24449d05 100644 --- a/doc/dev/git-conventions.md +++ b/doc/dev/git-conventions.md @@ -28,7 +28,7 @@ The **action** must be a verb in imperative form, the **subject** a noun. For example, we rename the trait `Foo` to `Fii` in the `toto` module: - [ref] toto: rename Foo -> Fii + ref(toto): rename Foo -> Fii Commits must be lowercase. -- GitLab From 8e200e5ba38224d42f7f7cfaff0f11472efabc5b Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Sun, 9 May 2021 03:08:27 +0200 Subject: [PATCH 4/6] build(docker): entrypoint: run duniter with exec Spare one process. --- release/docker/docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release/docker/docker-entrypoint.sh b/release/docker/docker-entrypoint.sh index 1cef9442d..aae22339e 100755 --- a/release/docker/docker-entrypoint.sh +++ b/release/docker/docker-entrypoint.sh @@ -110,4 +110,4 @@ export DUNITER_CONF_HOME cd /duniter/duniter echo Starting duniter with: echo /usr/bin/duniter "$@" -/usr/bin/duniter "$@" +exec /usr/bin/duniter "$@" -- GitLab From 3a6f4eaa001229fc149a35984eb756af19ace94a Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Sun, 9 May 2021 09:50:06 +0200 Subject: [PATCH 5/6] build(docker): install into /duniter Was /duniter/duniter. --- release/docker/Dockerfile | 4 ++-- release/docker/docker-entrypoint.sh | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/release/docker/Dockerfile b/release/docker/Dockerfile index a702099db..10e3a137f 100644 --- a/release/docker/Dockerfile +++ b/release/docker/Dockerfile @@ -44,10 +44,10 @@ RUN addgroup -S -g 1111 duniter && \ RUN mkdir -p /var/lib/duniter /etc/duniter && chown duniter:duniter /var/lib/duniter /etc/duniter # copy the build artifact from the build stage -COPY --from=build --chown=duniter:duniter /duniter/work /duniter/duniter +COPY --from=build --chown=duniter:duniter /duniter/work /duniter # install duniter executable symlink -RUN ln -s /duniter/duniter/bin/duniter /usr/bin/duniter +RUN ln -s /duniter/bin/duniter /usr/bin/duniter # copy entrypoint COPY release/docker/docker-entrypoint.sh / diff --git a/release/docker/docker-entrypoint.sh b/release/docker/docker-entrypoint.sh index aae22339e..c7c1971d9 100755 --- a/release/docker/docker-entrypoint.sh +++ b/release/docker/docker-entrypoint.sh @@ -107,7 +107,6 @@ DUNITER_CONF_HOME="/etc/duniter" export DUNITER_CONF_HOME # Start duniter -cd /duniter/duniter echo Starting duniter with: echo /usr/bin/duniter "$@" exec /usr/bin/duniter "$@" -- GitLab From c90624710df993c53b668232a893866e6ceffc6f Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Sun, 9 May 2021 21:27:08 +0200 Subject: [PATCH 6/6] ref(docker): move back config to /var/lib/duniter Moving `conf.json` from volume `/var/lib/duniter` to volume `/etc/duniter` was a mistake. It creates to much many corner cases where one can lose their configuration file. This commit partly reverts fd0bbe6 by bringing conf.json back into volume `/var/lib/duniter`. --- release/docker/docker-entrypoint.sh | 57 ++++++++--------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/release/docker/docker-entrypoint.sh b/release/docker/docker-entrypoint.sh index c7c1971d9..33fea165a 100755 --- a/release/docker/docker-entrypoint.sh +++ b/release/docker/docker-entrypoint.sh @@ -12,64 +12,43 @@ if [ "$DEBUG_ENTRYPOINT" = true ]; then fi home=/var/lib/duniter -config=/etc/duniter home_default=$home/duniter_default manual_config="$(boolean "${DUNITER_MANUAL_CONFIG:-false}")" auto_sync="$(boolean "${DUNITER_AUTO_SYNC:-false}")" -# Use new path /etc/duniter/conf.json -if ! [ -f "$config/conf.json" ]; then - if [ "$(readlink "$home_default/conf.json")" = "$config/conf.json" ]; then - # The configuration file was moved already but the link is dangling - # It is likely that '/etc/duniter' is an anonymous volume - echo -e "$big_fat_warning Your configuration file didn't survive the restart!" - echo -e "$big_fat_warning Make sure that '/etc/duniter' is explicitely mounted as a persistent volume or you'll lose it again." - if [ -f "$home_default/conf.json.backup" ]; then - echo -e "$big_fat_warning Found backup file '$home_default/conf.json.backup'; using it..." - mv "$home_default/conf.json.backup" "$home_default/conf.json" - fi - fi - if [ -f "$home_default/conf.json" ]; then - echo "Moving existing configuration file '$home_default/conf.json' to its new location: '$config/conf.json'" - echo "A backup is kept at '$home_default/conf.json.backup'" - cp "$home_default/conf.json" "$home_default/conf.json.backup" - mv "$home_default/conf.json" "$config/conf.json" - fi -fi mkdir -p "$home/duniter_default" -ln -fs "$config/conf.json" "$home_default/conf.json" # Manual config when enabled if [ "$manual_config" = true ]; then # Do not start until a configuration file was initialized - while ! [ -f "$config/conf.json.orig" ]; do - echo "Waiting for initial configuration file... Please copy your configuration file to '$config/conf.json.orig'" + while ! [ -f "$home_default/conf.json.orig" ]; do + echo "Waiting for initial configuration file... Please copy your configuration file to '$home_default/conf.json.orig'" sleep 10 done echo "Configuration file found. Continuing..." # Use new conf.json.orig when changed - md5_file="$config/conf.json.orig.md5" + md5_file="$home_default/conf.json.orig.md5" if ! md5sum -c "$md5_file"; then - if [ -f "$config/conf.json" ]; then - echo "Backing up old configuration file to '$config/conf.json.old'..." - mv $config/conf.json $config/conf.json.old + if [ -f "$home_default/conf.json" ]; then + echo "Backing up old configuration file to '$home_default/conf.json.old'..." + mv $home_default/conf.json $home_default/conf.json.old fi echo "Installing new configuration file..." - cp "$config/conf.json.orig" "$config/conf.json" - md5sum "$config/conf.json.orig" >"$md5_file" + cp "$home_default/conf.json.orig" "$home_default/conf.json" + md5sum "$home_default/conf.json.orig" >"$md5_file" fi # Log differences between initial, old and current conf file - jq --sort-keys -r . "$config/conf.json.orig" >"$config/conf.json.orig.sorted" - jq --sort-keys -r . "$config/conf.json" >"$config/conf.json.sorted" - if [ -f "$config/conf.json.old" ]; then - jq --sort-keys -r . "$config/conf.json.old" >"$config/conf.json.old.sorted" - if ! diff -q "$config/conf.json.old.sorted" "$config/conf.json.orig.sorted"; then - diff -u "$config/conf.json.old.sorted" "$config/conf.json.orig.sorted" + jq --sort-keys -r . "$home_default/conf.json.orig" >"$home_default/conf.json.orig.sorted" + jq --sort-keys -r . "$home_default/conf.json" >"$home_default/conf.json.sorted" + if [ -f "$home_default/conf.json.old" ]; then + jq --sort-keys -r . "$home_default/conf.json.old" >"$home_default/conf.json.old.sorted" + if ! diff -q "$home_default/conf.json.old.sorted" "$home_default/conf.json.orig.sorted"; then + diff -u "$home_default/conf.json.old.sorted" "$home_default/conf.json.orig.sorted" fi fi - if ! diff -q "$config/conf.json.orig.sorted" "$config/conf.json.sorted"; then - diff -u "$config/conf.json.orig.sorted" "$config/conf.json.sorted" + if ! diff -q "$home_default/conf.json.orig.sorted" "$home_default/conf.json.sorted"; then + diff -u "$home_default/conf.json.orig.sorted" "$home_default/conf.json.sorted" fi fi @@ -102,10 +81,6 @@ fi # Set --home option set -- --home "$home" "$@" -# Define DUNITER_CONF_HOME -DUNITER_CONF_HOME="/etc/duniter" -export DUNITER_CONF_HOME - # Start duniter echo Starting duniter with: echo /usr/bin/duniter "$@" -- GitLab