Skip to content
Snippets Groups Projects
Commit b27e8a2c authored by Gilles Filippini's avatar Gilles Filippini
Browse files

ref(docker): drop volume /etc/duniter

Moving `conf.json` from volume `/var/lib/duniter` to volume `/etc/duniter`
creates to much unwanted corner cases where one can lose their configuration
file.

Instead, this commit move the configuration back into `/var/lib/duniter`
and drop volume `/etc/duniter` now useless.
parent 904a098b
Branches
Tags v1.2.0
No related merge requests found
...@@ -41,7 +41,7 @@ RUN apk add jq ...@@ -41,7 +41,7 @@ RUN apk add jq
# create group and user duniter # create group and user duniter
RUN addgroup -S -g 1111 duniter && \ RUN addgroup -S -g 1111 duniter && \
adduser -SD -h /duniter -G duniter -u 1111 duniter adduser -SD -h /duniter -G duniter -u 1111 duniter
RUN mkdir -p /var/lib/duniter /etc/duniter && chown duniter:duniter /var/lib/duniter /etc/duniter RUN mkdir -p /var/lib/duniter && chown duniter:duniter /var/lib/duniter
# copy the build artifact from the build stage # copy the build artifact from the build stage
COPY --from=build --chown=duniter:duniter /duniter/work /duniter COPY --from=build --chown=duniter:duniter /duniter/work /duniter
...@@ -54,7 +54,6 @@ COPY release/docker/docker-entrypoint.sh / ...@@ -54,7 +54,6 @@ COPY release/docker/docker-entrypoint.sh /
# create volumes # create volumes
VOLUME /var/lib/duniter VOLUME /var/lib/duniter
VOLUME /etc/duniter
# expose ports # expose ports
EXPOSE 9220 10901 20901 30901 EXPOSE 9220 10901 20901 30901
......
...@@ -29,64 +29,43 @@ if [ "$DEBUG_ENTRYPOINT" = true ]; then ...@@ -29,64 +29,43 @@ if [ "$DEBUG_ENTRYPOINT" = true ]; then
fi fi
home=/var/lib/duniter home=/var/lib/duniter
config=/etc/duniter
home_default=$home/duniter_default home_default=$home/duniter_default
manual_config="$(boolean "${DUNITER_MANUAL_CONFIG:-false}")" manual_config="$(boolean "${DUNITER_MANUAL_CONFIG:-false}")"
auto_sync="$(boolean "${DUNITER_AUTO_SYNC:-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" mkdir -p "$home/duniter_default"
ln -fs "$config/conf.json" "$home_default/conf.json"
# Manual config when enabled # Manual config when enabled
if [ "$manual_config" = true ]; then if [ "$manual_config" = true ]; then
# Do not start until a configuration file was initialized # Do not start until a configuration file was initialized
while ! [ -f "$config/conf.json.orig" ]; do while ! [ -f "$home_default/conf.json.orig" ]; do
echo "Waiting for initial configuration file... Please copy your configuration file to '$config/conf.json.orig'" echo "Waiting for initial configuration file... Please copy your configuration file to '$home_default/conf.json.orig'"
sleep 10 sleep 10
done done
echo "Configuration file found. Continuing..." echo "Configuration file found. Continuing..."
# Use new conf.json.orig when changed # 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 ! md5sum -c "$md5_file"; then
if [ -f "$config/conf.json" ]; then if [ -f "$home_default/conf.json" ]; then
echo "Backing up old configuration file to '$config/conf.json.old'..." echo "Backing up old configuration file to '$home_default/conf.json.old'..."
mv $config/conf.json $config/conf.json.old mv $home_default/conf.json $home_default/conf.json.old
fi fi
echo "Installing new configuration file..." echo "Installing new configuration file..."
cp "$config/conf.json.orig" "$config/conf.json" cp "$home_default/conf.json.orig" "$home_default/conf.json"
md5sum "$config/conf.json.orig" >"$md5_file" md5sum "$home_default/conf.json.orig" >"$md5_file"
fi fi
# Log differences between initial, old and current conf file # 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 . "$home_default/conf.json.orig" >"$home_default/conf.json.orig.sorted"
jq --sort-keys -r . "$config/conf.json" >"$config/conf.json.sorted" jq --sort-keys -r . "$home_default/conf.json" >"$home_default/conf.json.sorted"
if [ -f "$config/conf.json.old" ]; then if [ -f "$home_default/conf.json.old" ]; then
jq --sort-keys -r . "$config/conf.json.old" >"$config/conf.json.old.sorted" jq --sort-keys -r . "$home_default/conf.json.old" >"$home_default/conf.json.old.sorted"
if ! diff -q "$config/conf.json.old.sorted" "$config/conf.json.orig.sorted"; then if ! diff -q "$home_default/conf.json.old.sorted" "$home_default/conf.json.orig.sorted"; then
diff -u "$config/conf.json.old.sorted" "$config/conf.json.orig.sorted" diff -u "$home_default/conf.json.old.sorted" "$home_default/conf.json.orig.sorted"
fi fi
fi fi
if ! diff -q "$config/conf.json.orig.sorted" "$config/conf.json.sorted"; then if ! diff -q "$home_default/conf.json.orig.sorted" "$home_default/conf.json.sorted"; then
diff -u "$config/conf.json.orig.sorted" "$config/conf.json.sorted" diff -u "$home_default/conf.json.orig.sorted" "$home_default/conf.json.sorted"
fi fi
fi fi
...@@ -120,8 +99,8 @@ if [ -n "${conf_vars:-}" ]; then ...@@ -120,8 +99,8 @@ if [ -n "${conf_vars:-}" ]; then
done done
# Apply # Apply
echo "Applying configuration: $conf_json" echo "Applying configuration: $conf_json"
if jq -r ". += $conf_json" "$config/conf.json" >"$config/conf.json.new"; then if jq -r ". += $conf_json" "$home_default/conf.json" >"$home_default/conf.json.new"; then
mv "$config/conf.json.new" "$config/conf.json" mv "$home_default/conf.json.new" "$home_default/conf.json"
echo "=> Success." echo "=> Success."
else else
echo -e "$big_fat_warning Failed. Keeping previous configuration." echo -e "$big_fat_warning Failed. Keeping previous configuration."
...@@ -144,10 +123,6 @@ fi ...@@ -144,10 +123,6 @@ fi
# Set --home option # Set --home option
set -- --home "$home" "$@" set -- --home "$home" "$@"
# Define DUNITER_CONF_HOME
DUNITER_CONF_HOME="/etc/duniter"
export DUNITER_CONF_HOME
# Start duniter # Start duniter
echo Starting duniter with: echo Starting duniter with:
echo /usr/bin/duniter "$@" echo /usr/bin/duniter "$@"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment