malt666 commited on
Commit
39ef865
·
verified ·
1 Parent(s): 25a9f24

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +180 -160
Dockerfile CHANGED
@@ -73,163 +73,183 @@ RUN chown -R node:node ${APP_HOME}
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"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  EXPOSE 8000
75
 
76
+ # Entrypoint: Read config from environment variable CONFIG_YAML if set, copy default if not, configure git, then run node server.js directly
77
+ ENTRYPOINT ["tini", "--", "sh", "-c", " \
78
+ # --- BEGIN: Update SillyTavern Core at Runtime --- \
79
+ echo '--- Attempting to update SillyTavern Core from GitHub (staging branch) ---'; \
80
+ if [ -d \".git\" ] && [ \"$(git rev-parse --abbrev-ref HEAD)\" = \"staging\" ]; then \
81
+ echo 'Existing staging branch found. Resetting and pulling latest changes...'; \
82
+ git reset --hard HEAD && \
83
+ git pull origin staging || echo 'WARN: git pull failed, continuing with code from build time.'; \
84
+ echo '--- SillyTavern Core update check finished. ---'; \
85
+ else \
86
+ echo 'WARN: .git directory not found or not on staging branch. Skipping runtime update. Code from build time will be used.'; \
87
+ fi; \
88
+ # --- END: Update SillyTavern Core at Runtime --- \
89
+
90
+ echo '--- Checking for CONFIG_YAML environment variable ---'; \
91
+ # Ensure the CWD has correct permissions for writing config.yaml
92
+ # mkdir -p ./config && chown node:node ./config; # Removed mkdir
93
+ if [ -n \"$CONFIG_YAML\" ]; then \
94
+ echo 'Environment variable CONFIG_YAML found. Writing to ./config.yaml (root directory)...'; \
95
+ # Write directly to ./config.yaml in the CWD
96
+ printf '%s\n' \"$CONFIG_YAML\" > ./config.yaml && \
97
+ chown node:node ./config.yaml && \
98
+ echo 'Config written to ./config.yaml and permissions set successfully.'; \
99
+ # --- BEGIN DEBUG: Print the written config file ---
100
+ echo '--- Verifying written ./config.yaml ---'; \
101
+ cat ./config.yaml; \
102
+ echo '--- End of ./config.yaml ---'; \
103
+ # --- END DEBUG ---
104
+ else \
105
+ echo 'Warning: Environment variable CONFIG_YAML is not set or empty. Attempting to copy default config...'; \
106
+ # Copy default if ENV VAR is missing and the example exists
107
+ if [ -f \"./public/config.yaml.example\" ]; then \
108
+ # Copy default to ./config.yaml in the CWD
109
+ cp \"./public/config.yaml.example\" \"./config.yaml\" && \
110
+ chown node:node ./config.yaml && \
111
+ echo 'Copied default config to ./config.yaml'; \
112
+ else \
113
+ echo 'Warning: Default config ./public/config.yaml.example not found.'; \
114
+ fi; \
115
+ fi; \
116
+
117
+ # --- BEGIN: Configure Git default identity at Runtime --- \
118
+ echo '--- Configuring Git default user identity at runtime ---'; \
119
+ git config --global user.name \"SillyTavern Sync\" && \
120
+ git config --global user.email \"[email protected]\"; \
121
+ echo '--- Git identity configured for runtime user. ---'; \
122
+ # --- END: Configure Git default identity at Runtime --- \
123
+
124
+ # --- BEGIN: Dynamically Install Plugins at Runtime --- \
125
+ echo '--- Checking for PLUGINS environment variable ---'; \
126
+ if [ -n \"$PLUGINS\" ]; then \
127
+ echo \"*** Installing Plugins specified in PLUGINS environment variable: $PLUGINS ***\" && \
128
+ # Ensure plugins directory exists
129
+ mkdir -p ./plugins && chown node:node ./plugins && \
130
+ # Set comma as delimiter
131
+ IFS=',' && \
132
+ # Loop through each plugin URL
133
+ for plugin_url in $PLUGINS; do \
134
+ # Trim leading/trailing whitespace
135
+ plugin_url=$(echo \"$plugin_url\" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') && \
136
+ if [ -z \"$plugin_url\" ]; then continue; fi && \
137
+ # Extract plugin name
138
+ plugin_name_git=$(basename \"$plugin_url\") && \
139
+ plugin_name=${plugin_name_git%.git} && \
140
+ plugin_dir=\"./plugins/$plugin_name\" && \
141
+ echo \"--- Installing plugin: $plugin_name from $plugin_url into $plugin_dir ---\" && \
142
+ # Remove existing dir if it exists
143
+ rm -rf \"$plugin_dir\" && \
144
+ # Clone the plugin (run as root, fix perms later)
145
+ git clone --depth 1 \"$plugin_url\" \"$plugin_dir\" && \
146
+ if [ -f \"$plugin_dir/package.json\" ]; then \
147
+ echo \"--- Installing dependencies for $plugin_name ---\" && \
148
+ (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\"; \
149
+ else \
150
+ echo \"--- No package.json found for $plugin_name, skipping dependency install. ---\"; \
151
+ fi || echo \"WARN: Failed to clone $plugin_name from $plugin_url, skipping...\"; \
152
+ done && \
153
+ # Reset IFS
154
+ unset IFS && \
155
+ # Fix permissions for plugins directory after installation
156
+ echo \"--- Setting permissions for plugins directory ---\" && \
157
+ chown -R node:node ./plugins && \
158
+ echo \"*** Plugin installation finished. ***\"; \
159
+ else \
160
+ echo 'PLUGINS environment variable is not set or empty, skipping runtime plugin installation.'; \
161
+ fi; \
162
+ # --- END: Dynamically Install Plugins at Runtime --- \
163
+
164
+ # --- BEGIN: Auto-configure cloud-saves plugin if secrets provided --- \
165
+ echo '--- Checking for cloud-saves plugin auto-configuration ---'; \
166
+ if [ -d \"./plugins/cloud-saves\" ] && [ -n \"$REPO_URL\" ] && [ -n \"$GITHUB_TOKEN\" ]; then \
167
+ echo \"*** Auto-configuring cloud-saves plugin with provided secrets ***\" && \
168
+ config_file=\"./plugins/cloud-saves/config.json\" && \
169
+ echo \"--- Creating config.json for cloud-saves plugin at $config_file ---\" && \
170
+ 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\" && \
171
+ chown node:node \"$config_file\" && \
172
+ echo \"*** cloud-saves plugin auto-configuration completed ***\"; \
173
+ else \
174
+ if [ ! -d \"./plugins/cloud-saves\" ]; then \
175
+ echo 'cloud-saves plugin not found, skipping auto-configuration.'; \
176
+ elif [ -z \"$REPO_URL\" ] || [ -z \"$GITHUB_TOKEN\" ]; then \
177
+ echo 'REPO_URL or GITHUB_TOKEN environment variables not provided, skipping cloud-saves auto-configuration.'; \
178
+ fi; \
179
+ fi; \
180
+ # --- END: Auto-configure cloud-saves plugin --- \
181
+
182
+ # --- BEGIN: Dynamically Install Extensions at Runtime --- \
183
+ echo '--- Checking for EXTENSIONS environment variable ---'; \
184
+ if [ -n \"$EXTENSIONS\" ]; then \
185
+ echo \"*** Installing Extensions specified in EXTENSIONS environment variable: $EXTENSIONS ***\" && \
186
+ # Determine extension installation directory based on INSTALL_FOR_ALL_USERS
187
+ if [ \"$INSTALL_FOR_ALL_USERS\" = \"true\" ]; then \
188
+ ext_install_dir=\"./public/scripts/extensions/third-party\" && \
189
+ echo \"--- Installing extensions for all users (system-wide) to $ext_install_dir ---\"; \
190
+ else \
191
+ ext_install_dir=\"./data/default-user/extensions\" && \
192
+ echo \"--- Installing extensions for default user only to $ext_install_dir ---\"; \
193
+ fi && \
194
+ # Ensure extension directory exists
195
+ mkdir -p \"$ext_install_dir\" && chown node:node \"$ext_install_dir\" && \
196
+ # Set comma as delimiter
197
+ IFS=',' && \
198
+ # Loop through each extension URL
199
+ for ext_url in $EXTENSIONS; do \
200
+ # Trim leading/trailing whitespace
201
+ ext_url=$(echo \"$ext_url\" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') && \
202
+ if [ -z \"$ext_url\" ]; then continue; fi && \
203
+ # Extract extension name
204
+ ext_name_git=$(basename \"$ext_url\") && \
205
+ ext_name=${ext_name_git%.git} && \
206
+ ext_dir=\"$ext_install_dir/$ext_name\" && \
207
+ echo \"--- Installing extension: $ext_name from $ext_url into $ext_dir ---\" && \
208
+ # Remove existing dir if it exists
209
+ rm -rf \"$ext_dir\" && \
210
+ # Clone the extension (run as root, fix perms later)
211
+ git clone --depth 1 \"$ext_url\" \"$ext_dir\" && \
212
+ if [ -f \"$ext_dir/package.json\" ]; then \
213
+ echo \"--- Installing dependencies for extension $ext_name ---\" && \
214
+ (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\"; \
215
+ else \
216
+ echo \"--- No package.json found for extension $ext_name, skipping dependency install. ---\"; \
217
+ fi || echo \"WARN: Failed to clone extension $ext_name from $ext_url, skipping...\"; \
218
+ done && \
219
+ # Reset IFS
220
+ unset IFS && \
221
+ # Fix permissions for extensions directory after installation
222
+ echo \"--- Setting permissions for extensions directory ---\" && \
223
+ chown -R node:node \"$ext_install_dir\" && \
224
+ echo \"*** Extension installation finished. ***\"; \
225
+ else \
226
+ echo 'EXTENSIONS environment variable is not set or empty, skipping runtime extension installation.'; \
227
+ fi; \
228
+ # --- END: Dynamically Install Extensions at Runtime --- \
229
+
230
+ echo 'Starting SillyTavern server directly...'; \
231
+
232
+ # --- BEGIN: Cleanup before start --- \
233
+ # Remove .gitignore
234
+ echo 'Attempting final removal of .gitignore...' && \
235
+ rm -f .gitignore && \
236
+ if [ ! -e .gitignore ]; then \
237
+ echo '.gitignore successfully removed.'; \
238
+ else \
239
+ # This case is unlikely with rm -f unless permissions prevent removal
240
+ echo 'WARN: .gitignore could not be removed or reappeared.'; \
241
+ fi; \
242
+ # Remove .git directory
243
+ echo 'Attempting final removal of .git directory...' && \
244
+ rm -rf .git && \
245
+ if [ ! -d .git ]; then \
246
+ echo '.git directory successfully removed.'; \
247
+ else \
248
+ # This case usually indicates a permission issue
249
+ echo 'WARN: .git directory could not be removed.'; \
250
+ fi; \
251
+ # --- END: Cleanup before start --- \
252
+
253
+ # Execute node server directly, bypassing docker-entrypoint.sh
254
+ exec node server.js; \
255
+ "]