Spaces:
Running
Running
Upload Dockerfile
Browse files- Dockerfile +160 -214
Dockerfile
CHANGED
@@ -73,217 +73,163 @@ RUN chown -R node:node ${APP_HOME}
|
|
73 |
|
74 |
EXPOSE 8000
|
75 |
|
76 |
-
#
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
#
|
235 |
-
|
236 |
-
echo "Starting SillyTavern keep-alive script..."
|
237 |
-
|
238 |
-
# Give the main server a moment to start
|
239 |
-
sleep 10
|
240 |
-
|
241 |
-
while true; do
|
242 |
-
echo "Sending keep-alive request to http://localhost:8000/..."
|
243 |
-
# Use --silent and --output /dev/null to avoid spamming logs with curl output
|
244 |
-
curl --silent --output /dev/null http://localhost:8000/
|
245 |
-
if [ $? -eq 0 ]; then
|
246 |
-
echo "Keep-alive request successful."
|
247 |
-
else
|
248 |
-
# Only print warning on failure
|
249 |
-
echo "Warning: Keep-alive request failed. SillyTavern might not be running or accessible."
|
250 |
-
fi
|
251 |
-
# Wait for 30 minutes (1800 seconds)
|
252 |
-
sleep 1800
|
253 |
-
done
|
254 |
-
|
255 |
-
echo "SillyTavern keep-alive script finished." # Should not be reached
|
256 |
-
EOF_LOVE_SCRIPT
|
257 |
-
\
|
258 |
-
chmod +x ./love.sh && \
|
259 |
-
echo 'Running love.sh in background...' && \
|
260 |
-
./love.sh & \
|
261 |
-
echo '--- Keep-alive script started in background. ---'; \
|
262 |
-
# --- END: Create and run keep-alive script --- \
|
263 |
-
|
264 |
-
echo 'Starting SillyTavern server directly...'; \
|
265 |
-
|
266 |
-
# --- BEGIN: Cleanup before start --- \
|
267 |
-
# Remove .gitignore
|
268 |
-
echo 'Attempting final removal of .gitignore...' && \
|
269 |
-
rm -f .gitignore && \
|
270 |
-
if [ ! -e .gitignore ]; then \
|
271 |
-
echo '.gitignore successfully removed.'; \
|
272 |
-
else \
|
273 |
-
# This case is unlikely with rm -f unless permissions prevent removal
|
274 |
-
echo 'WARN: .gitignore could not be removed or reappeared.'; \
|
275 |
-
fi; \
|
276 |
-
# Remove .git directory
|
277 |
-
echo 'Attempting final removal of .git directory...' && \
|
278 |
-
rm -rf .git && \
|
279 |
-
if [ ! -d .git ]; then \
|
280 |
-
echo '.git directory successfully removed.'; \
|
281 |
-
else \
|
282 |
-
# This case usually indicates a permission issue
|
283 |
-
echo 'WARN: .git directory could not be removed.'; \
|
284 |
-
fi; \
|
285 |
-
# --- END: Cleanup before start --- \
|
286 |
-
|
287 |
-
# Execute node server directly, bypassing docker-entrypoint.sh
|
288 |
-
exec node server.js; \
|
289 |
-
"]
|
|
|
73 |
|
74 |
EXPOSE 8000
|
75 |
|
76 |
+
# Create love.sh script with keep-alive logic
|
77 |
+
RUN printf '%s\n' '\
|
78 |
+
#!/bin/sh\n\n\
|
79 |
+
# Original ENTRYPOINT logic\n\
|
80 |
+
echo \'--- Attempting to update SillyTavern Core from GitHub (staging branch) ---\'; \\n\
|
81 |
+
if [ -d \".git\" ] && [ \"$(git rev-parse --abbrev-ref HEAD)\" = \"staging\" ]; then \\n\
|
82 |
+
echo \'Existing staging branch found. Resetting and pulling latest changes...\'; \\n\
|
83 |
+
git reset --hard HEAD && \\n\
|
84 |
+
git pull origin staging || echo \'WARN: git pull failed, continuing with code from build time.\'; \\n\
|
85 |
+
echo \'--- SillyTavern Core update check finished. ---\'; \\n\
|
86 |
+
else \\n\
|
87 |
+
echo \'WARN: .git directory not found or not on staging branch. Skipping runtime update. Code from build time will be used.\'; \\n\
|
88 |
+
fi; \\n\
|
89 |
+
\n\
|
90 |
+
echo \'--- Checking for CONFIG_YAML environment variable ---\'; \\n\
|
91 |
+
if [ -n \"$CONFIG_YAML\" ]; then \\n\
|
92 |
+
echo \'Environment variable CONFIG_YAML found. Writing to ./config.yaml (root directory)...\'; \\n\
|
93 |
+
printf \'%s\\n\' \"$CONFIG_YAML\" > ./config.yaml && \\n\
|
94 |
+
chown node:node ./config.yaml && \\n\
|
95 |
+
echo \'Config written to ./config.yaml and permissions set successfully.\'; \\n\
|
96 |
+
echo \'--- Verifying written ./config.yaml ---\'; \\n\
|
97 |
+
cat ./config.yaml; \\n\
|
98 |
+
echo \'--- End of ./config.yaml ---\'; \\n\
|
99 |
+
else \\n\
|
100 |
+
echo \'Warning: Environment variable CONFIG_YAML is not set or empty. Attempting to copy default config...\'; \\n\
|
101 |
+
if [ -f \"./public/config.yaml.example\" ]; then \\n\
|
102 |
+
cp \"./public/config.yaml.example\" \"./config.yaml\" && \\n\
|
103 |
+
chown node:node ./config.yaml && \\n\
|
104 |
+
echo \'Copied default config to ./config.yaml\'; \\n\
|
105 |
+
else \\n\
|
106 |
+
echo \'Warning: Default config ./public/config.yaml.example not found.\'; \\n\
|
107 |
+
fi; \\n\
|
108 |
+
fi; \\n\
|
109 |
+
\n\
|
110 |
+
echo \'--- Configuring Git default user identity at runtime ---\'; \\n\
|
111 |
+
git config --global user.name \"SillyTavern Sync\" && \\n\
|
112 |
+
git config --global user.email \"[email protected]\"; \\n\
|
113 |
+
echo \'--- Git identity configured for runtime user. ---\'; \\n\
|
114 |
+
\n\
|
115 |
+
echo \'--- Checking for PLUGINS environment variable ---\'; \\n\
|
116 |
+
if [ -n \"$PLUGINS\" ]; then \\n\
|
117 |
+
echo \"*** Installing Plugins specified in PLUGINS environment variable: $PLUGINS ***\" && \\n\
|
118 |
+
mkdir -p ./plugins && chown node:node ./plugins && \\n\
|
119 |
+
IFS=',' && \\n\
|
120 |
+
for plugin_url in $PLUGINS; do \\n\
|
121 |
+
plugin_url=$(echo \"$plugin_url\" | sed \'s/^[[:space:]]*//;s/[[:space:]]*$//\') && \\n\
|
122 |
+
if [ -z \"$plugin_url\" ]; then continue; fi && \\n\
|
123 |
+
plugin_name_git=$(basename \"$plugin_url\") && \\n\
|
124 |
+
plugin_name=${plugin_name_git%.git} && \\n\
|
125 |
+
plugin_dir=\"./plugins/$plugin_name\" && \\n\
|
126 |
+
echo \"--- Installing plugin: $plugin_name from $plugin_url into $plugin_dir ---\" && \\n\
|
127 |
+
rm -rf \"$plugin_dir\" && \\n\
|
128 |
+
git clone --depth 1 \"$plugin_url\" \"$plugin_dir\" && \\n\
|
129 |
+
if [ -f \"$plugin_dir/package.json\" ]; then \\n\
|
130 |
+
echo \"--- Installing dependencies for $plugin_name ---\" && \\n\
|
131 |
+
(cd \"$plugin_dir\" && npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force) || echo \"WARN: Failed to install dependencies for $plugin_name\"; \\n\
|
132 |
+
else \\n\
|
133 |
+
echo \"--- No package.json found for $plugin_name, skipping dependency install. ---\"; \\n\
|
134 |
+
fi || echo \"WARN: Failed to clone $plugin_name from $plugin_url, skipping...\"; \\n\
|
135 |
+
done && \\n\
|
136 |
+
unset IFS && \\n\
|
137 |
+
echo \"--- Setting permissions for plugins directory ---\" && \\n\
|
138 |
+
chown -R node:node ./plugins && \\n\
|
139 |
+
echo \"*** Plugin installation finished. ***\"; \\n\
|
140 |
+
else \\n\
|
141 |
+
echo \'PLUGINS environment variable is not set or empty, skipping runtime plugin installation.\'; \\n\
|
142 |
+
fi; \\n\
|
143 |
+
\n\
|
144 |
+
echo \'--- Checking for cloud-saves plugin auto-configuration ---\'; \\n\
|
145 |
+
if [ -d \"./plugins/cloud-saves\" ] && [ -n \"$REPO_URL\" ] && [ -n \"$GITHUB_TOKEN\" ]; then \\n\
|
146 |
+
*** Auto-configuring cloud-saves plugin with provided secrets ***\" && \\n\
|
147 |
+
config_file=\"./plugins/cloud-saves/config.json\" && \\n\
|
148 |
+
echo \"--- Creating config.json for cloud-saves plugin at $config_file ---\" && \\n\
|
149 |
+
printf \'{\\n \"repo_url\": \\"%s\\\",\\n \"branch\\\": \\"main\\\",\\n \"username\\\": \\"\\\",\\n \"github_token\\\": \\"%s\\\",\\n \"display_name\\\": \\"user\\\",\\n \"is_authorized\\\": true,\\n \"last_save\\\": null,\\n \"current_save\\\": null,\\n \"has_temp_stash\\\": false,\\n \"autoSaveEnabled\\\": false,\\n \"autoSaveInterval\\\": %s,\\n \"autoSaveTargetTag\\\": \\"%s\\\"\\n}\\n\' \"$REPO_URL\" \"$GITHUB_TOKEN\" \"${AUTOSAVE_INTERVAL:-30}\" \"${AUTOSAVE_TARGET_TAG:-}\" > \"$config_file\" && \\n\
|
150 |
+
chown node:node \"$config_file\" && \\n\
|
151 |
+
echo \"*** cloud-saves plugin auto-configuration completed ***\"; \\n\
|
152 |
+
else \\n\
|
153 |
+
if [ ! -d \"./plugins/cloud-saves\" ]; then \\n\
|
154 |
+
echo \'cloud-saves plugin not found, skipping auto-configuration.\'; \\n\
|
155 |
+
elif [ -z \"$REPO_URL\" ] || [ -z \"$GITHUB_TOKEN\" ]; then \\n\
|
156 |
+
echo \'REPO_URL or GITHUB_TOKEN environment variables not provided, skipping cloud-saves auto-configuration.\'; \\n\
|
157 |
+
fi; \\n\
|
158 |
+
fi; \\n\
|
159 |
+
\n\
|
160 |
+
echo \'--- Checking for EXTENSIONS environment variable ---\'; \\n\
|
161 |
+
if [ -n \"$EXTENSIONS\" ]; then \\n\
|
162 |
+
echo \"*** Installing Extensions specified in EXTENSIONS environment variable: $EXTENSIONS ***\" && \\n\
|
163 |
+
if [ \"$INSTALL_FOR_ALL_USERS\" = \"true\" ]; then \\n\
|
164 |
+
ext_install_dir=\"./public/scripts/extensions/third-party\" && \\n\
|
165 |
+
echo \"--- Installing extensions for all users (system-wide) to $ext_install_dir ---\"; \\n\
|
166 |
+
else \\n\
|
167 |
+
ext_install_dir=\"./data/default-user/extensions\" && \\n\
|
168 |
+
echo \"--- Installing extensions for default user only to $ext_install_dir ---\"; \\n\
|
169 |
+
fi && \\n\
|
170 |
+
mkdir -p \"$ext_install_dir\" && chown node:node \"$ext_install_dir\" && \\n\
|
171 |
+
IFS=',' && \\n\
|
172 |
+
for ext_url in $EXTENSIONS; do \\n\
|
173 |
+
ext_url=$(echo \"$ext_url\" | sed \'s/^[[:space:]]*//;s/[[:space:]]*$//\') && \\n\
|
174 |
+
if [ -z \"$ext_url\" ]; then continue; fi && \\n\
|
175 |
+
ext_name_git=$(basename \"$ext_url\") && \\n\
|
176 |
+
ext_name=${ext_name_git%.git} && \\n\
|
177 |
+
ext_dir=\"$ext_install_dir/$ext_name\" && \\n\
|
178 |
+
echo \"--- Installing extension: $ext_name from $ext_url into $ext_dir ---\" && \\n\
|
179 |
+
rm -rf \"$ext_dir\" && \\n\
|
180 |
+
git clone --depth 1 \"$ext_url\" \"$ext_dir\" && \\n\
|
181 |
+
if [ -f \"$ext_dir/package.json\" ]; then \\n\
|
182 |
+
echo \"--- Installing dependencies for extension $ext_name ---\" && \\n\
|
183 |
+
(cd \"$ext_dir\" && npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force) || echo \"WARN: Failed to install dependencies for extension $ext_name\"; \\n\
|
184 |
+
else \\n\
|
185 |
+
echo \"--- No package.json found for extension $ext_name, skipping dependency install. ---\"; \\n\
|
186 |
+
fi || echo \"WARN: Failed to clone extension $ext_name from $ext_url, skipping...\"; \\n\
|
187 |
+
done && \\n\
|
188 |
+
unset IFS && \\n\
|
189 |
+
echo \"--- Setting permissions for extensions directory ---\" && \\n\
|
190 |
+
chown -R node:node \"$ext_install_dir\" && \\n\
|
191 |
+
echo \"*** Extension installation finished. ***\"; \\n\
|
192 |
+
else \\n\
|
193 |
+
echo \'EXTENSIONS environment variable is not set or empty, skipping runtime extension installation.\'; \\n\
|
194 |
+
fi; \\n\
|
195 |
+
\n\
|
196 |
+
echo \'--- Cleanup before start ---\'; \\n\
|
197 |
+
echo \'Attempting final removal of .gitignore...\' && \\n\
|
198 |
+
rm -f .gitignore && \\n\
|
199 |
+
if [ ! -e .gitignore ]; then \\n\
|
200 |
+
echo \'.gitignore successfully removed.\'; \\n\
|
201 |
+
else \\n\
|
202 |
+
echo \'WARN: .gitignore could not be removed or reappeared.\'; \\n\
|
203 |
+
fi; \\n\
|
204 |
+
echo \'Attempting final removal of .git directory...\' && \\n\
|
205 |
+
rm -rf .git && \\n\
|
206 |
+
if [ ! -d .git ]; then \\n\
|
207 |
+
echo \'.git directory successfully removed.\'; \\n\
|
208 |
+
else \\n\
|
209 |
+
echo \'WARN: .git directory could not be removed.\'; \\n\
|
210 |
+
fi; \\n\
|
211 |
+
\n\
|
212 |
+
# Start SillyTavern in the background\n\
|
213 |
+
echo \'Starting SillyTavern server in the background...\'; \\n\
|
214 |
+
node server.js & \\n\
|
215 |
+
\n\
|
216 |
+
# Wait for SillyTavern to be responsive (Health Check)\n\
|
217 |
+
echo \'Waiting for SillyTavern to become responsive on port 8000...\'; \\n\
|
218 |
+
until curl --output /dev/null --silent --head --fail http://localhost:8000/; do \\n\
|
219 |
+
echo \'SillyTavern is still starting or not responding, waiting 5 seconds...\'; \\n\
|
220 |
+
sleep 5 \\n\
|
221 |
+
done \\n\
|
222 |
+
echo \'SillyTavern started successfully!\'; \\n\
|
223 |
+
\n\
|
224 |
+
# Start the keep-alive loop\n\
|
225 |
+
echo \'Starting periodic keep-alive (every 30 minutes)...\'; \\n\
|
226 |
+
while true; do \\n\
|
227 |
+
echo \'Sending keep-alive request...\'; \\n\
|
228 |
+
curl http://localhost:8000/; \\n\
|
229 |
+
echo \'Keep-alive request sent.\'; \\n\
|
230 |
+
sleep 1800; \\n\
|
231 |
+
done\n' > love.sh && \
|
232 |
+
chmod +x love.sh
|
233 |
+
|
234 |
+
# Entrypoint: Execute the love.sh script using tini
|
235 |
+
ENTRYPOINT ["tini", "--", "./love.sh"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|