soxogvv commited on
Commit
0e74aba
Β·
verified Β·
1 Parent(s): 3be42aa

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -8
Dockerfile CHANGED
@@ -125,28 +125,52 @@ RUN printf '%s\n' \
125
  '' \
126
  'mkdir -p /data/persist' \
127
  '' \
128
- '# ── Step 1: RESTORE β€” /data/persist β†’ /root/ (on restart) ───────────' \
129
- '# Only syncs what is missing in /root/, never overwrites existing files' \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  'if [ -d "/data/persist/venv" ]; then' \
131
  ' echo "β–Ά Restoring venv from backup..."' \
132
  ' rsync -a --ignore-existing /data/persist/venv/ /root/venv/' \
 
 
133
  'fi' \
134
  'if [ -d "/data/persist/cache" ]; then' \
135
  ' echo "β–Ά Restoring cache from backup..."' \
136
  ' rsync -a --ignore-existing /data/persist/cache/ /root/.cache/' \
137
  'fi' \
138
  '' \
139
- '# ── Step 2: Fix pip ─────────────────────────────────────────────────' \
140
  'rm -f /root/venv/lib/python*/EXTERNALLY-MANAGED' \
141
  '' \
142
- '# ── Step 3: BACKUP β€” /root/ β†’ /data/persist/ (sync any changes) ─────' \
143
- '# rsync only copies what changed, very fast' \
144
  'echo "β–Ά Syncing /root/venv to backup..."' \
145
  'rsync -a --delete /root/venv/ /data/persist/venv/' \
146
  'rsync -a --delete /root/.cache/ /data/persist/cache/' \
147
  '' \
148
- '# ── Step 4: Background sync every 60s (root β†’ data) ─────────────────' \
149
- '# Catches any pip installs or changes made while server is running' \
150
  '(' \
151
  ' while true; do' \
152
  ' sleep 60' \
@@ -155,7 +179,7 @@ RUN printf '%s\n' \
155
  ' done' \
156
  ') &' \
157
  '' \
158
- '# ── Step 5: apt.txt reinstall ────────────────────────────────────────' \
159
  'APT_FILE="/data/apt.txt"' \
160
  'if [ ! -f "$APT_FILE" ]; then touch "$APT_FILE"; fi' \
161
  'if [ -s "$APT_FILE" ]; then' \
 
125
  '' \
126
  'mkdir -p /data/persist' \
127
  '' \
128
+ '# ── HELPER: auto-detect and fix /data/persist dir ────────────────────' \
129
+ 'fix_backup() {' \
130
+ ' DEST="$1"' \
131
+ ' if [ -L "$DEST" ]; then' \
132
+ ' # Old broken symlink from previous method β€” remove it' \
133
+ ' echo "β–Ά Old symlink detected at $DEST, removing..."' \
134
+ ' rm -f "$DEST"' \
135
+ ' elif [ -d "$DEST" ]; then' \
136
+ ' # Real folder but may have bad permissions β€” try to fix' \
137
+ ' chmod -R u+rwX "$DEST" 2>/dev/null || {' \
138
+ ' # Cannot fix permissions β€” rebuild it' \
139
+ ' echo "β–Ά Bad permissions at $DEST, rebuilding..."' \
140
+ ' rm -rf "$DEST"' \
141
+ ' }' \
142
+ ' fi' \
143
+ '}' \
144
+ '' \
145
+ '# ── Step 1: AUTO-FIX any bad backup state ────────────────────────────' \
146
+ 'fix_backup /data/persist/venv' \
147
+ 'fix_backup /data/persist/cache' \
148
+ '' \
149
+ '# ── Step 2: RESTORE β€” /data/persist β†’ /root/ ────────────────────────' \
150
+ '# /root/ is always the real live directory' \
151
+ '# Restore from backup only what is missing in /root/' \
152
  'if [ -d "/data/persist/venv" ]; then' \
153
  ' echo "β–Ά Restoring venv from backup..."' \
154
  ' rsync -a --ignore-existing /data/persist/venv/ /root/venv/' \
155
+ 'else' \
156
+ ' echo "β–Ά No venv backup found, using image default"' \
157
  'fi' \
158
  'if [ -d "/data/persist/cache" ]; then' \
159
  ' echo "β–Ά Restoring cache from backup..."' \
160
  ' rsync -a --ignore-existing /data/persist/cache/ /root/.cache/' \
161
  'fi' \
162
  '' \
163
+ '# ── Step 3: Fix pip ──────────────────────────────────────────────────' \
164
  'rm -f /root/venv/lib/python*/EXTERNALLY-MANAGED' \
165
  '' \
166
+ '# ── Step 4: BACKUP β€” /root/ β†’ /data/persist/ ────────────────────────' \
167
+ '# Sync current /root/ state into backup (only changed files)' \
168
  'echo "β–Ά Syncing /root/venv to backup..."' \
169
  'rsync -a --delete /root/venv/ /data/persist/venv/' \
170
  'rsync -a --delete /root/.cache/ /data/persist/cache/' \
171
  '' \
172
+ '# ── Step 5: Background sync every 60s ───────────────────────────────' \
173
+ '# Catches pip installs or any changes while server is running' \
174
  '(' \
175
  ' while true; do' \
176
  ' sleep 60' \
 
179
  ' done' \
180
  ') &' \
181
  '' \
182
+ '# ── Step 6: apt.txt reinstall ────────────────────────────────────────' \
183
  'APT_FILE="/data/apt.txt"' \
184
  'if [ ! -f "$APT_FILE" ]; then touch "$APT_FILE"; fi' \
185
  'if [ -s "$APT_FILE" ]; then' \