Commit b839c259 authored by Gilles Filippini's avatar Gilles Filippini
Browse files

Docker image: add entrypoint script

First of all, this script moves the duniter configuration file 'conf.json'
into the '/etc/duniter' volume, so that one could delete the '/var/lib/duniter'
volume without losing the configuration.

A symbolic link is set up into /var/lib/duniter/duniter_default to point to
the new path:
 /var/lib/duniter/duniter_default/conf.json -> /etc/duniter/conf.json

Then, this script enables the folowing environment variables:

* DUNITER_MANUAL_CONFIG (boolean, default = false)

  When set to 'true' (or 'yes', or '1'), the script waits until the file
  '/etc/duniter/conf.json.orig' is present before starting the duniter
  service. Here is the workflow when enabled:
  1. wait for '/etc/duniter/conf.json.orig'
  2. if this file was changed since the previous startup:
    2.1. Save 'conf.json' to 'conf.json.old'
    2.2. Replace 'conf.json' with 'conf.json.orig'
    2.3. Save the new file's checksum to compare with at next startup
  3. continue the startup sequence

  When set to false, the startup sequence continues.

* DUNITER_AUTO_SYNC (boolean, default = false)
  Requires 'DUNITER_SYNC_HOST'.

  When set to 'true' (or 'yes', or '1') and the folder
  '/var/lib/duniter/duniter_default/data' doesn't exist, a 'duniter sync'
  command will be issued before starting the service.

  When set to false, the service is started directly.

* DUNITER_SYNC_HOST (hostname, default = "")

  This is the 'host:port' parameter to use with 'duniter sync' when
  'DUNITER_AUTO_SYNC' is enabled.

  The synchronization won't be launched when the wariable is not defined
  or empty.
parent 5a35a676
......@@ -49,6 +49,9 @@ RUN cp /duniter/duniter/docker.sh /usr/bin/duniter && \
chmod +x /usr/bin/duniter && \
chown duniter:duniter /usr/bin/duniter
# copy entrypoint
COPY docker-entrypoint.sh /
# create volumes
VOLUME /var/lib/duniter
VOLUME /etc/duniter
......@@ -60,5 +63,5 @@ EXPOSE 9220 10901 20901
USER duniter
WORKDIR /duniter
ENTRYPOINT ["/usr/bin/duniter"]
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD []
#!/bin/sh
home=/var/lib/duniter
config=/etc/duniter
home_default=$home/duniter_default
function boolean () {
echo "$1" | sed -E 's/^(true|yes|1)$/true/i'
}
manual_config="$(boolean "${DUNITER_MANUAL_CONFIG:-false}")"
auto_sync="$(boolean "${DUNITER_AUTO_SYNC:-false}")"
# Use path /etc/duniter/conf.json
if ! [ -f "$config/conf.json" ] && [ -f "$home_default/conf.json" ]; then
mv "$home_default/conf.json" "$conf/conf.json"
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'"
sleep 10
done
echo "Configuration file found. Continuing..."
# Use new conf.json.orig when changed
md5_file="$config/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
fi
echo "Installing new configuration file..."
cp "$config/conf.json.orig" "$config/conf.json"
md5sum "$config/conf.json.orig" >"$md5_file"
fi
fi
# Auto start synchronization when enabled and starting from scratch
if [ "$auto_sync" = true ]; then
if ! [ -d "$home_default/data" ]; then
echo "No 'data' folder. "
if [ -z "$DUNITER_SYNC_HOST" ]; then
echo "DUNITER_SYNC_HOST undefined. Can't start synchronization!"
else
echo "Starting synchronization..."
/usr/bin/duniter sync --home "$home" "$DUNITER_SYNC_HOST"
fi
fi
fi
# Start duniter
echo Starting duniter with:
echo /usr/bin/duniter "$@"
/usr/bin/duniter "$@"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment