mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 04:48:06 +00:00
docker: auto-detect image upgrades and include install stage
Without version tracking, if a new image requires the install stage (e.g. new package versions), the default configure,activate will skip it and potentially fail silently. At build time, the git hash is written to /etc/chatmail-image-version. At runtime, setup_chatmail_docker.sh compares it against the persisted /home/.chatmail-running-version (survives container restarts via the /home volume). If they differ, the install stage is automatically prepended to CMDEPLOY_STAGES. After a successful deploy, the running version is updated. Files: docker/chatmail_relay.dockerfile:68-69, docker/files/setup_chatmail_docker.sh:27-48
This commit is contained in:
@@ -61,6 +61,9 @@ RUN CMDEPLOY_STAGES=install \
|
|||||||
RUN cp -a www/ /opt/chatmail-www/
|
RUN cp -a www/ /opt/chatmail-www/
|
||||||
|
|
||||||
RUN rm -f /tmp/chatmail.ini
|
RUN rm -f /tmp/chatmail.ini
|
||||||
|
|
||||||
|
# Record image version for upgrade detection at runtime
|
||||||
|
RUN git rev-parse HEAD > /etc/chatmail-image-version 2>/dev/null || echo "unknown" > /etc/chatmail-image-version
|
||||||
# --- End build-time install ---
|
# --- End build-time install ---
|
||||||
|
|
||||||
ENV CHATMAIL_INI=/etc/chatmail/chatmail.ini
|
ENV CHATMAIL_INI=/etc/chatmail/chatmail.ini
|
||||||
|
|||||||
@@ -24,9 +24,33 @@ if [ ! -f "$CHATMAIL_INI" ]; then
|
|||||||
$CMDEPLOY init --config "$CHATMAIL_INI" "$MAIL_DOMAIN"
|
$CMDEPLOY init --config "$CHATMAIL_INI" "$MAIL_DOMAIN"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export CMDEPLOY_STAGES="${CMDEPLOY_STAGES:-configure,activate}"
|
# Auto-detect image upgrades: if the image version changed since last run,
|
||||||
|
# include the install stage so new packages/binaries are picked up.
|
||||||
|
IMAGE_VERSION_FILE="/etc/chatmail-image-version"
|
||||||
|
RUNNING_VERSION_FILE="/home/.chatmail-running-version"
|
||||||
|
CMDEPLOY_STAGES="${CMDEPLOY_STAGES:-configure,activate}"
|
||||||
|
if [ -f "$IMAGE_VERSION_FILE" ]; then
|
||||||
|
image_ver=$(cat "$IMAGE_VERSION_FILE")
|
||||||
|
running_ver=""
|
||||||
|
if [ -f "$RUNNING_VERSION_FILE" ]; then
|
||||||
|
running_ver=$(cat "$RUNNING_VERSION_FILE")
|
||||||
|
fi
|
||||||
|
if [ "$image_ver" != "$running_ver" ]; then
|
||||||
|
echo "[INFO] Image version changed ($running_ver -> $image_ver), adding install stage."
|
||||||
|
case "$CMDEPLOY_STAGES" in
|
||||||
|
*install*) ;; # already includes install
|
||||||
|
*) CMDEPLOY_STAGES="install,$CMDEPLOY_STAGES" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
export CMDEPLOY_STAGES
|
||||||
$CMDEPLOY run --config "$CHATMAIL_INI" --ssh-host @local
|
$CMDEPLOY run --config "$CHATMAIL_INI" --ssh-host @local
|
||||||
|
|
||||||
|
# Record successful version after deploy
|
||||||
|
if [ -f "$IMAGE_VERSION_FILE" ]; then
|
||||||
|
cp "$IMAGE_VERSION_FILE" "$RUNNING_VERSION_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
# Journald: forward to console for docker logs (idempotent)
|
# Journald: forward to console for docker logs (idempotent)
|
||||||
grep -q '^ForwardToConsole=yes' /etc/systemd/journald.conf \
|
grep -q '^ForwardToConsole=yes' /etc/systemd/journald.conf \
|
||||||
|| echo "ForwardToConsole=yes" >> /etc/systemd/journald.conf
|
|| echo "ForwardToConsole=yes" >> /etc/systemd/journald.conf
|
||||||
|
|||||||
Reference in New Issue
Block a user