Spaces:
Paused
Paused
Upload Dockerfile
Browse files- Dockerfile +97 -18
Dockerfile
CHANGED
|
@@ -40,29 +40,108 @@ RUN \
|
|
| 40 |
echo "No package.json found in root, skipping base npm install."; \
|
| 41 |
fi
|
| 42 |
|
| 43 |
-
# Pre-compile public libraries (only if build-lib.js exists)
|
| 44 |
-
RUN \
|
| 45 |
-
echo "*** Run Webpack (if build-lib.js exists) ***" && \
|
| 46 |
-
if [ -f "./build-lib.js" ]; then \
|
| 47 |
-
node "./build-lib.js"; \
|
| 48 |
-
else \
|
| 49 |
-
echo "build-lib.js not found, skipping Webpack build."; \
|
| 50 |
-
fi
|
| 51 |
-
|
| 52 |
# Ensure the node user owns the application directory and its contents
|
| 53 |
-
# Do this before COPYing the script as root
|
| 54 |
RUN chown -R node:node ${APP_HOME}
|
| 55 |
|
| 56 |
-
# Copy the entrypoint script and set permissions
|
| 57 |
-
COPY entrypoint.sh /home/node/app/entrypoint.sh
|
| 58 |
-
RUN chown node:node /home/node/app/entrypoint.sh && chmod +x /home/node/app/entrypoint.sh
|
| 59 |
-
# Ensure the script uses Unix line endings (LF) instead of Windows (CRLF)
|
| 60 |
-
RUN sed -i 's/\r$//' /home/node/app/entrypoint.sh
|
| 61 |
-
|
| 62 |
# Switch to non-root user
|
| 63 |
USER node
|
| 64 |
|
| 65 |
EXPOSE 8000
|
| 66 |
|
| 67 |
-
# Entrypoint:
|
| 68 |
-
ENTRYPOINT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
echo "No package.json found in root, skipping base npm install."; \
|
| 41 |
fi
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Ensure the node user owns the application directory and its contents
|
|
|
|
| 44 |
RUN chown -R node:node ${APP_HOME}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Switch to non-root user
|
| 47 |
USER node
|
| 48 |
|
| 49 |
EXPOSE 8000
|
| 50 |
|
| 51 |
+
# Entrypoint: Install plugins, Read config, Configure git, Run server
|
| 52 |
+
# Using shell form for ENTRYPOINT to avoid potential JSON parsing issues
|
| 53 |
+
ENTRYPOINT tini -- sh -c '
|
| 54 |
+
# --- BEGIN: Install Plugins at Runtime ---
|
| 55 |
+
if [ -n "$PLUGINS" ]; then
|
| 56 |
+
echo "--- Found PLUGINS environment variable, attempting to install plugins ---";
|
| 57 |
+
# Ensure plugin dir exists
|
| 58 |
+
mkdir -p plugins;
|
| 59 |
+
# Use temp var and add trailing comma for loop robustness
|
| 60 |
+
temp_plugins_var="$PLUGINS,";
|
| 61 |
+
while [ -n "$temp_plugins_var" ]; do
|
| 62 |
+
plugin_url="${temp_plugins_var%%,*}"; # Get first element
|
| 63 |
+
temp_plugins_var="${temp_plugins_var#*,}"; # Remove first element
|
| 64 |
+
|
| 65 |
+
# Trim leading/trailing whitespace using awk
|
| 66 |
+
plugin_url=$(echo "$plugin_url" | awk '''{$1=$1;print}''');
|
| 67 |
+
|
| 68 |
+
if [ -z "$plugin_url" ]; then continue; fi;
|
| 69 |
+
|
| 70 |
+
# Extract plugin name: remove .git suffix, then get basename
|
| 71 |
+
plugin_name_tmp="${plugin_url%.git}";
|
| 72 |
+
plugin_name="${plugin_name_tmp##*/}";
|
| 73 |
+
|
| 74 |
+
if [ -z "$plugin_name" ]; then
|
| 75 |
+
echo "WARN: Could not extract plugin name from URL: $plugin_url, skipping.";
|
| 76 |
+
continue;
|
| 77 |
+
fi;
|
| 78 |
+
|
| 79 |
+
plugin_dir="./plugins/$plugin_name";
|
| 80 |
+
echo "--- Processing plugin: $plugin_name from $plugin_url ---";
|
| 81 |
+
|
| 82 |
+
# Clone (remove existing first)
|
| 83 |
+
rm -rf "$plugin_dir";
|
| 84 |
+
echo "Cloning into $plugin_dir...";
|
| 85 |
+
if git clone --depth 1 "$plugin_url" "$plugin_dir"; then
|
| 86 |
+
echo "Cloned successfully.";
|
| 87 |
+
# Install dependencies if package.json exists
|
| 88 |
+
if [ -f "$plugin_dir/package.json" ]; then
|
| 89 |
+
echo "Found package.json, installing dependencies for $plugin_name...";
|
| 90 |
+
# Run npm install within the plugin directory
|
| 91 |
+
(cd "$plugin_dir" && npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force);
|
| 92 |
+
if [ $? -ne 0 ]; then
|
| 93 |
+
echo "WARN: Failed to install dependencies for $plugin_name";
|
| 94 |
+
else
|
| 95 |
+
echo "Dependencies installed for $plugin_name.";
|
| 96 |
+
fi;
|
| 97 |
+
else
|
| 98 |
+
echo "No package.json found for $plugin_name, skipping dependency install.";
|
| 99 |
+
fi;
|
| 100 |
+
else
|
| 101 |
+
echo "WARN: Failed to clone $plugin_name from $plugin_url, skipping further processing.";
|
| 102 |
+
fi;
|
| 103 |
+
done;
|
| 104 |
+
echo "--- Finished processing plugins ---";
|
| 105 |
+
else
|
| 106 |
+
echo "--- PLUGINS environment variable not set or empty, skipping plugin installation ---";
|
| 107 |
+
fi;
|
| 108 |
+
# --- END: Install Plugins at Runtime ---
|
| 109 |
+
|
| 110 |
+
# --- Original Entrypoint logic ---
|
| 111 |
+
echo "--- Checking for CONFIG_YAML environment variable ---";
|
| 112 |
+
# Ensure the CWD has correct permissions for writing config.yaml
|
| 113 |
+
# mkdir -p ./config && chown node:node ./config; # Removed mkdir
|
| 114 |
+
if [ -n "$CONFIG_YAML" ]; then
|
| 115 |
+
echo "Environment variable CONFIG_YAML found. Writing to ./config.yaml (root directory)...";
|
| 116 |
+
# Write directly to ./config.yaml in the CWD
|
| 117 |
+
# Need to ensure node user has write permission here. CWD should be owned by node due to chown and USER node.
|
| 118 |
+
printf '%s\n' "$CONFIG_YAML" > ./config.yaml &&
|
| 119 |
+
echo "Config written to ./config.yaml successfully.";
|
| 120 |
+
# --- BEGIN DEBUG: Print the written config file ---
|
| 121 |
+
echo "--- Verifying written ./config.yaml ---";
|
| 122 |
+
cat ./config.yaml;
|
| 123 |
+
echo "--- End of ./config.yaml ---";
|
| 124 |
+
# --- END DEBUG ---
|
| 125 |
+
else
|
| 126 |
+
echo "Warning: Environment variable CONFIG_YAML is not set or empty. Attempting to copy default config...";
|
| 127 |
+
# Copy default if ENV VAR is missing and the example exists
|
| 128 |
+
if [ -f "./public/config.yaml.example" ]; then
|
| 129 |
+
# Copy default to ./config.yaml in the CWD
|
| 130 |
+
cp "./public/config.yaml.example" "./config.yaml" &&
|
| 131 |
+
echo "Copied default config to ./config.yaml";
|
| 132 |
+
else
|
| 133 |
+
echo "Warning: Default config ./public/config.yaml.example not found.";
|
| 134 |
+
fi;
|
| 135 |
+
fi;
|
| 136 |
+
|
| 137 |
+
# --- BEGIN: Configure Git default identity at Runtime ---
|
| 138 |
+
echo "--- Configuring Git default user identity at runtime ---";
|
| 139 |
+
git config --global user.name "SillyTavern Sync" &&
|
| 140 |
+
git config --global user.email "sillytavern-sync@example.com";
|
| 141 |
+
echo "--- Git identity configured for runtime user. ---";
|
| 142 |
+
# --- END: Configure Git default identity at Runtime ---
|
| 143 |
+
|
| 144 |
+
echo "Starting SillyTavern server directly...";
|
| 145 |
+
# Execute node server directly. Since we used USER node, this should run as the node user.
|
| 146 |
+
exec node server.js;
|
| 147 |
+
'
|