Spaces:
Paused
Paused
Upload 2 files
Browse files- Dockerfile +65 -43
Dockerfile
CHANGED
|
@@ -2,11 +2,13 @@ FROM node:lts-alpine3.19
|
|
| 2 |
|
| 3 |
# Arguments
|
| 4 |
ARG APP_HOME=/home/node/app
|
|
|
|
| 5 |
|
| 6 |
# Install system dependencies
|
| 7 |
# Add unzip for extracting the application code
|
| 8 |
# Keep git for potential use by scripts or future plugin updates
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
# Create app directory
|
| 12 |
WORKDIR ${APP_HOME}
|
|
@@ -14,12 +16,13 @@ WORKDIR ${APP_HOME}
|
|
| 14 |
# Set NODE_ENV to production
|
| 15 |
ENV NODE_ENV=production
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
COPY sillytavern.zip .
|
| 19 |
RUN \
|
| 20 |
-
echo "***
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# --- BEGIN: Remove root .gitignore if exists ---
|
| 25 |
RUN \
|
|
@@ -28,28 +31,37 @@ RUN \
|
|
| 28 |
echo "*** Root .gitignore removed (if it existed). ***"
|
| 29 |
# --- END: Remove root .gitignore ---
|
| 30 |
|
| 31 |
-
# --- BEGIN: Clone
|
| 32 |
RUN \
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
else \
|
| 43 |
-
|
| 44 |
-
echo "data-sync directory not found or invalid, cloning..." && \
|
| 45 |
-
# Remove potentially incomplete/invalid directory first
|
| 46 |
-
rm -rf plugins/data-sync && \
|
| 47 |
-
mkdir -p plugins && \
|
| 48 |
-
git clone https://github.com/fuwei99/data-sync.git plugins/data-sync; \
|
| 49 |
fi
|
| 50 |
-
# --- END: Clone
|
| 51 |
|
| 52 |
-
# Install base SillyTavern dependencies (package*.json should be in the
|
| 53 |
RUN \
|
| 54 |
echo "*** Install Base npm packages ***" && \
|
| 55 |
if [ -f package.json ]; then \
|
|
@@ -59,24 +71,34 @@ RUN \
|
|
| 59 |
echo "No package.json found in root, skipping base npm install."; \
|
| 60 |
fi
|
| 61 |
|
| 62 |
-
# Install
|
| 63 |
RUN \
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
else \
|
| 76 |
-
|
| 77 |
-
echo "Error: plugins/data-sync directory not found after attempting clone."; \
|
| 78 |
-
exit 1; \
|
| 79 |
fi
|
|
|
|
| 80 |
|
| 81 |
# Go back to the main app directory (redundant but safe)
|
| 82 |
WORKDIR ${APP_HOME}
|
|
@@ -121,11 +143,11 @@ ENTRYPOINT ["tini", "--", "sh", "-c", " \
|
|
| 121 |
printf '%s\n' \"$CONFIG_YAML\" > ./config.yaml && \
|
| 122 |
chown node:node ./config.yaml && \
|
| 123 |
echo 'Config written to ./config.yaml and permissions set successfully.'; \
|
| 124 |
-
# --- BEGIN DEBUG: Print the written config file ---
|
| 125 |
echo '--- Verifying written ./config.yaml ---'; \
|
| 126 |
cat ./config.yaml; \
|
| 127 |
echo '--- End of ./config.yaml ---'; \
|
| 128 |
-
# --- END DEBUG ---
|
| 129 |
else \
|
| 130 |
echo 'Warning: Environment variable CONFIG_YAML is not set or empty. Attempting to copy default config...'; \
|
| 131 |
# Copy default if ENV VAR is missing and the example exists
|
|
@@ -138,14 +160,14 @@ ENTRYPOINT ["tini", "--", "sh", "-c", " \
|
|
| 138 |
echo 'Warning: Default config ./public/config.yaml.example not found.'; \
|
| 139 |
fi; \
|
| 140 |
fi; \
|
| 141 |
-
|
| 142 |
# --- BEGIN: Configure Git default identity at Runtime ---
|
| 143 |
echo '--- Configuring Git default user identity at runtime ---'; \
|
| 144 |
git config --global user.name \"SillyTavern Sync\" && \
|
| 145 |
git config --global user.email \"sillytavern-sync@example.com\"; \
|
| 146 |
echo '--- Git identity configured for runtime user. ---'; \
|
| 147 |
# --- END: Configure Git default identity at Runtime ---
|
| 148 |
-
|
| 149 |
echo 'Starting SillyTavern server directly...'; \
|
| 150 |
# Execute node server directly, bypassing docker-entrypoint.sh
|
| 151 |
exec node server.js; \
|
|
|
|
| 2 |
|
| 3 |
# Arguments
|
| 4 |
ARG APP_HOME=/home/node/app
|
| 5 |
+
ARG PLUGINS="" # Comma-separated list of plugin git URLs
|
| 6 |
|
| 7 |
# Install system dependencies
|
| 8 |
# Add unzip for extracting the application code
|
| 9 |
# Keep git for potential use by scripts or future plugin updates
|
| 10 |
+
# Add wget to download the zip file
|
| 11 |
+
RUN apk add --no-cache gcompat tini git unzip wget
|
| 12 |
|
| 13 |
# Create app directory
|
| 14 |
WORKDIR ${APP_HOME}
|
|
|
|
| 16 |
# Set NODE_ENV to production
|
| 17 |
ENV NODE_ENV=production
|
| 18 |
|
| 19 |
+
# --- BEGIN: Clone SillyTavern Core from GitHub (staging branch) ---
|
|
|
|
| 20 |
RUN \
|
| 21 |
+
echo "*** Cloning SillyTavern Core from GitHub (staging branch) ***" && \
|
| 22 |
+
# Clone the specific branch into the current directory
|
| 23 |
+
git clone -b staging --depth 1 https://github.com/SillyTavern/SillyTavern.git . && \
|
| 24 |
+
echo "*** Cloning complete. ***"
|
| 25 |
+
# --- END: Clone SillyTavern Core ---
|
| 26 |
|
| 27 |
# --- BEGIN: Remove root .gitignore if exists ---
|
| 28 |
RUN \
|
|
|
|
| 31 |
echo "*** Root .gitignore removed (if it existed). ***"
|
| 32 |
# --- END: Remove root .gitignore ---
|
| 33 |
|
| 34 |
+
# --- BEGIN: Dynamically Clone Plugins from PLUGINS argument ---
|
| 35 |
RUN \
|
| 36 |
+
if [ -n "$PLUGINS" ]; then \
|
| 37 |
+
echo "*** Cloning Plugins specified in PLUGINS argument: $PLUGINS ***" && \
|
| 38 |
+
apk add --no-cache --virtual .build-deps-parsing basename && \
|
| 39 |
+
# Set comma as delimiter
|
| 40 |
+
IFS=',' && \
|
| 41 |
+
# Loop through each plugin URL
|
| 42 |
+
for plugin_url in $PLUGINS; do \
|
| 43 |
+
# Trim leading/trailing whitespace (using sh compatible method)
|
| 44 |
+
plugin_url=$(echo "$plugin_url" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') && \
|
| 45 |
+
if [ -z "$plugin_url" ]; then continue; fi && \
|
| 46 |
+
# Extract plugin name (basename of the URL, removing .git suffix)
|
| 47 |
+
plugin_name=$(basename "$plugin_url" .git) && \
|
| 48 |
+
plugin_dir="plugins/$plugin_name" && \
|
| 49 |
+
echo "--- Cloning $plugin_name from $plugin_url into $plugin_dir ---" && \
|
| 50 |
+
# Remove existing dir if it exists
|
| 51 |
+
rm -rf "$plugin_dir" && \
|
| 52 |
+
mkdir -p plugins && \
|
| 53 |
+
# Clone the plugin
|
| 54 |
+
git clone --depth 1 "$plugin_url" "$plugin_dir" || echo "WARN: Failed to clone $plugin_name from $plugin_url, skipping..."; \
|
| 55 |
+
done && \
|
| 56 |
+
# Reset IFS
|
| 57 |
+
unset IFS && \
|
| 58 |
+
apk del .build-deps-parsing; \
|
| 59 |
else \
|
| 60 |
+
echo "PLUGINS argument is empty or not set, skipping plugin cloning."; \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
fi
|
| 62 |
+
# --- END: Dynamically Clone Plugins ---
|
| 63 |
|
| 64 |
+
# Install base SillyTavern dependencies (package*.json should be in the cloned root)
|
| 65 |
RUN \
|
| 66 |
echo "*** Install Base npm packages ***" && \
|
| 67 |
if [ -f package.json ]; then \
|
|
|
|
| 71 |
echo "No package.json found in root, skipping base npm install."; \
|
| 72 |
fi
|
| 73 |
|
| 74 |
+
# --- BEGIN: Dynamically Install Dependencies for Cloned Plugins ---
|
| 75 |
RUN \
|
| 76 |
+
if [ -n "$PLUGINS" ]; then \
|
| 77 |
+
echo "*** Installing Dependencies for specified plugins ***" && \
|
| 78 |
+
apk add --no-cache --virtual .build-deps-parsing basename && \
|
| 79 |
+
IFS=',' && \
|
| 80 |
+
for plugin_url in $PLUGINS; do \
|
| 81 |
+
plugin_url=$(echo "$plugin_url" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') && \
|
| 82 |
+
if [ -z "$plugin_url" ]; then continue; fi && \
|
| 83 |
+
plugin_name=$(basename "$plugin_url" .git) && \
|
| 84 |
+
plugin_dir="plugins/$plugin_name" && \
|
| 85 |
+
if [ -d "$plugin_dir" ] && [ -f "$plugin_dir/package.json" ]; then \
|
| 86 |
+
echo "--- Installing dependencies for $plugin_name in $plugin_dir ---" && \
|
| 87 |
+
cd "$plugin_dir" && \
|
| 88 |
+
npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force && \
|
| 89 |
+
cd "${APP_HOME}"; \
|
| 90 |
+
elif [ -d "$plugin_dir" ]; then \
|
| 91 |
+
echo "--- No package.json found in $plugin_name, skipping dependency install. ---"; \
|
| 92 |
+
else \
|
| 93 |
+
echo "--- Plugin directory $plugin_dir not found (likely clone failed), skipping dependency install. ---"; \
|
| 94 |
+
fi; \
|
| 95 |
+
done && \
|
| 96 |
+
unset IFS && \
|
| 97 |
+
apk del .build-deps-parsing; \
|
| 98 |
else \
|
| 99 |
+
echo "PLUGINS argument is empty or not set, skipping plugin dependency installation."; \
|
|
|
|
|
|
|
| 100 |
fi
|
| 101 |
+
# --- END: Dynamically Install Dependencies ---
|
| 102 |
|
| 103 |
# Go back to the main app directory (redundant but safe)
|
| 104 |
WORKDIR ${APP_HOME}
|
|
|
|
| 143 |
printf '%s\n' \"$CONFIG_YAML\" > ./config.yaml && \
|
| 144 |
chown node:node ./config.yaml && \
|
| 145 |
echo 'Config written to ./config.yaml and permissions set successfully.'; \
|
| 146 |
+
# --- BEGIN DEBUG: Print the written config file ---
|
| 147 |
echo '--- Verifying written ./config.yaml ---'; \
|
| 148 |
cat ./config.yaml; \
|
| 149 |
echo '--- End of ./config.yaml ---'; \
|
| 150 |
+
# --- END DEBUG ---
|
| 151 |
else \
|
| 152 |
echo 'Warning: Environment variable CONFIG_YAML is not set or empty. Attempting to copy default config...'; \
|
| 153 |
# Copy default if ENV VAR is missing and the example exists
|
|
|
|
| 160 |
echo 'Warning: Default config ./public/config.yaml.example not found.'; \
|
| 161 |
fi; \
|
| 162 |
fi; \
|
| 163 |
+
|
| 164 |
# --- BEGIN: Configure Git default identity at Runtime ---
|
| 165 |
echo '--- Configuring Git default user identity at runtime ---'; \
|
| 166 |
git config --global user.name \"SillyTavern Sync\" && \
|
| 167 |
git config --global user.email \"sillytavern-sync@example.com\"; \
|
| 168 |
echo '--- Git identity configured for runtime user. ---'; \
|
| 169 |
# --- END: Configure Git default identity at Runtime ---
|
| 170 |
+
|
| 171 |
echo 'Starting SillyTavern server directly...'; \
|
| 172 |
# Execute node server directly, bypassing docker-entrypoint.sh
|
| 173 |
exec node server.js; \
|