Spaces:
Running
Running
Z User commited on
Commit ·
272cc2c
1
Parent(s): b77d2a2
fix: persist .env and config.yaml across container rebuilds
Browse files- Add symlink for ~/.hermes/.env -> /data/hermes/.env
- Add symlink for ~/.hermes/config.yaml -> /data/hermes/config.yaml
- Keep repo copies in /app as fallback for recovery
- Fixes WeChat token/account_id lost on every restart
- Also fixes any WebUI settings changes being lost
- Dockerfile +4 -1
- start.sh +49 -0
Dockerfile
CHANGED
|
@@ -70,10 +70,13 @@ RUN git clone --depth 1 https://github.com/EKKOLearnAI/hermes-web-ui.git /tmp/he
|
|
| 70 |
# Create hermes home
|
| 71 |
RUN mkdir -p /root/.hermes/plugins/image_gen/pollinations
|
| 72 |
|
| 73 |
-
# Copy config files
|
| 74 |
COPY config.yaml /root/.hermes/config.yaml
|
| 75 |
COPY SOUL.md /root/.hermes/SOUL.md
|
| 76 |
COPY .env /root/.hermes/.env
|
|
|
|
|
|
|
|
|
|
| 77 |
COPY entry.py /app/entry.py
|
| 78 |
COPY dashboard.html /app/dashboard.html
|
| 79 |
COPY plugins/pollinations/ /root/.hermes/plugins/image_gen/pollinations/
|
|
|
|
| 70 |
# Create hermes home
|
| 71 |
RUN mkdir -p /root/.hermes/plugins/image_gen/pollinations
|
| 72 |
|
| 73 |
+
# Copy config files (to both hermes home AND /app for persistence fallback)
|
| 74 |
COPY config.yaml /root/.hermes/config.yaml
|
| 75 |
COPY SOUL.md /root/.hermes/SOUL.md
|
| 76 |
COPY .env /root/.hermes/.env
|
| 77 |
+
# Keep repo copies in /app as fallback sources for persistent storage recovery
|
| 78 |
+
COPY config.yaml /app/config.yaml
|
| 79 |
+
COPY .env /app/.env
|
| 80 |
COPY entry.py /app/entry.py
|
| 81 |
COPY dashboard.html /app/dashboard.html
|
| 82 |
COPY plugins/pollinations/ /root/.hermes/plugins/image_gen/pollinations/
|
start.sh
CHANGED
|
@@ -52,6 +52,55 @@ if [ -z "$WEIXIN_ACCOUNT_ID" ]; then
|
|
| 52 |
fi
|
| 53 |
fi
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
echo "Persistent storage ready."
|
| 56 |
|
| 57 |
# ── Persist WebUI credentials across rebuilds ──
|
|
|
|
| 52 |
fi
|
| 53 |
fi
|
| 54 |
|
| 55 |
+
# ── Persist .env across container rebuilds ──
|
| 56 |
+
# WeChat QR login + BFF credential saves write to ~/.hermes/.env
|
| 57 |
+
# Without this, WeChat tokens and other channel credentials are lost on every rebuild
|
| 58 |
+
ENV_FILE="$HERMES_HOME/.env"
|
| 59 |
+
ENV_DATA="/data/hermes/.env"
|
| 60 |
+
if [ -f "$ENV_FILE" ] && [ ! -L "$ENV_FILE" ] && [ ! -f "$ENV_DATA" ]; then
|
| 61 |
+
# First time: migrate build-time .env to persistent storage
|
| 62 |
+
cp "$ENV_FILE" "$ENV_DATA"
|
| 63 |
+
chmod 600 "$ENV_DATA"
|
| 64 |
+
echo "Migrated .env to persistent storage"
|
| 65 |
+
elif [ -L "$ENV_FILE" ] && [ ! -f "$ENV_DATA" ]; then
|
| 66 |
+
# Symlink exists but target is missing (data cleared) — recreate from repo copy
|
| 67 |
+
if [ -f "/app/.env" ]; then
|
| 68 |
+
cp "/app/.env" "$ENV_DATA"
|
| 69 |
+
chmod 600 "$ENV_DATA"
|
| 70 |
+
echo "Restored .env from repo fallback"
|
| 71 |
+
fi
|
| 72 |
+
fi
|
| 73 |
+
if [ ! -L "$ENV_FILE" ]; then
|
| 74 |
+
rm -f "$ENV_FILE"
|
| 75 |
+
ln -sf "$ENV_DATA" "$ENV_FILE"
|
| 76 |
+
echo "Symlink: .env -> $ENV_DATA"
|
| 77 |
+
else
|
| 78 |
+
echo "Symlink exists: .env"
|
| 79 |
+
fi
|
| 80 |
+
|
| 81 |
+
# ── Persist config.yaml across container rebuilds ──
|
| 82 |
+
# WebUI settings page and WeChat save flow update ~/.hermes/config.yaml at runtime
|
| 83 |
+
CFG_FILE="$HERMES_HOME/config.yaml"
|
| 84 |
+
CFG_DATA="/data/hermes/config.yaml"
|
| 85 |
+
if [ -f "$CFG_FILE" ] && [ ! -L "$CFG_FILE" ] && [ ! -f "$CFG_DATA" ]; then
|
| 86 |
+
# First time: migrate build-time config to persistent storage
|
| 87 |
+
cp "$CFG_FILE" "$CFG_DATA"
|
| 88 |
+
echo "Migrated config.yaml to persistent storage"
|
| 89 |
+
elif [ -L "$CFG_FILE" ] && [ ! -f "$CFG_DATA" ]; then
|
| 90 |
+
# Symlink exists but target missing — recreate from repo copy
|
| 91 |
+
if [ -f "/app/config.yaml" ]; then
|
| 92 |
+
cp "/app/config.yaml" "$CFG_DATA"
|
| 93 |
+
echo "Restored config.yaml from repo fallback"
|
| 94 |
+
fi
|
| 95 |
+
fi
|
| 96 |
+
if [ ! -L "$CFG_FILE" ]; then
|
| 97 |
+
rm -f "$CFG_FILE"
|
| 98 |
+
ln -sf "$CFG_DATA" "$CFG_FILE"
|
| 99 |
+
echo "Symlink: config.yaml -> $CFG_DATA"
|
| 100 |
+
else
|
| 101 |
+
echo "Symlink exists: config.yaml"
|
| 102 |
+
fi
|
| 103 |
+
|
| 104 |
echo "Persistent storage ready."
|
| 105 |
|
| 106 |
# ── Persist WebUI credentials across rebuilds ──
|