Spaces:
Paused
Paused
Upload Dockerfile
Browse files- Dockerfile +110 -102
Dockerfile
CHANGED
|
@@ -5,8 +5,9 @@ ARG APP_HOME=/home/node/app
|
|
| 5 |
ARG PLUGINS="" # Comma-separated list of plugin git URLs
|
| 6 |
|
| 7 |
# Install system dependencies
|
| 8 |
-
#
|
| 9 |
-
#
|
|
|
|
| 10 |
RUN apk add --no-cache gcompat tini git unzip wget
|
| 11 |
|
| 12 |
# Create app directory
|
|
@@ -40,108 +41,115 @@ RUN \
|
|
| 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:
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 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 |
-
echo "
|
| 120 |
-
|
| 121 |
-
echo "
|
| 122 |
-
|
| 123 |
-
echo
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 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 |
-
'
|
|
|
|
| 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
|
|
|
|
| 41 |
echo "No package.json found in root, skipping base npm install."; \
|
| 42 |
fi
|
| 43 |
|
| 44 |
+
# Go back to the main app directory (redundant but safe)
|
| 45 |
+
WORKDIR ${APP_HOME}
|
| 46 |
+
|
| 47 |
+
# Create config directory. config.yaml will be handled at runtime by ENTRYPOINT
|
| 48 |
+
RUN mkdir -p config
|
| 49 |
+
|
| 50 |
+
# Pre-compile public libraries (build-lib.js should be in the unzipped structure)
|
| 51 |
+
RUN \
|
| 52 |
+
echo "*** Run Webpack ***" && \
|
| 53 |
+
# Check if build-lib.js exists before running
|
| 54 |
+
if [ -f "./docker/build-lib.js" ]; then \
|
| 55 |
+
node "./docker/build-lib.js"; \
|
| 56 |
+
elif [ -f "./build-lib.js" ]; then \
|
| 57 |
+
node "./build-lib.js"; \
|
| 58 |
+
else \
|
| 59 |
+
echo "build-lib.js not found, skipping Webpack build."; \
|
| 60 |
+
fi
|
| 61 |
+
|
| 62 |
+
# Cleanup unnecessary files (like the docker dir if it exists in the zip) and make entrypoint executable
|
| 63 |
+
# This block is removed as we no longer use docker-entrypoint.sh
|
| 64 |
+
# RUN \
|
| 65 |
+
# echo "*** Cleanup and Permissions ***" && \
|
| 66 |
+
# ...
|
| 67 |
+
|
| 68 |
+
# Fix potential git safe.directory issues if git commands are run later by scripts
|
| 69 |
+
RUN git config --global --add safe.directory "${APP_HOME}"
|
| 70 |
+
|
| 71 |
# Ensure the node user owns the application directory and its contents
|
| 72 |
RUN chown -R node:node ${APP_HOME}
|
| 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 |
+
echo '--- Checking for CONFIG_YAML environment variable ---'; \
|
| 79 |
+
# Ensure the CWD has correct permissions for writing config.yaml
|
| 80 |
+
# mkdir -p ./config && chown node:node ./config; # Removed mkdir
|
| 81 |
+
if [ -n \"$CONFIG_YAML\" ]; then \
|
| 82 |
+
echo 'Environment variable CONFIG_YAML found. Writing to ./config.yaml (root directory)...'; \
|
| 83 |
+
# Write directly to ./config.yaml in the CWD
|
| 84 |
+
printf '%s\n' \"$CONFIG_YAML\" > ./config.yaml && \
|
| 85 |
+
chown node:node ./config.yaml && \
|
| 86 |
+
echo 'Config written to ./config.yaml and permissions set successfully.'; \
|
| 87 |
+
# --- BEGIN DEBUG: Print the written config file ---
|
| 88 |
+
echo '--- Verifying written ./config.yaml ---'; \
|
| 89 |
+
cat ./config.yaml; \
|
| 90 |
+
echo '--- End of ./config.yaml ---'; \
|
| 91 |
+
# --- END DEBUG ---
|
| 92 |
+
else \
|
| 93 |
+
echo 'Warning: Environment variable CONFIG_YAML is not set or empty. Attempting to copy default config...'; \
|
| 94 |
+
# Copy default if ENV VAR is missing and the example exists
|
| 95 |
+
if [ -f \"./public/config.yaml.example\" ]; then \
|
| 96 |
+
# Copy default to ./config.yaml in the CWD
|
| 97 |
+
cp \"./public/config.yaml.example\" \"./config.yaml\" && \
|
| 98 |
+
chown node:node ./config.yaml && \
|
| 99 |
+
echo 'Copied default config to ./config.yaml'; \
|
| 100 |
+
else \
|
| 101 |
+
echo 'Warning: Default config ./public/config.yaml.example not found.'; \
|
| 102 |
+
fi; \
|
| 103 |
+
fi; \
|
| 104 |
+
|
| 105 |
+
# --- BEGIN: Configure Git default identity at Runtime --- \
|
| 106 |
+
echo '--- Configuring Git default user identity at runtime ---'; \
|
| 107 |
+
git config --global user.name \"SillyTavern Sync\" && \
|
| 108 |
+
git config --global user.email \"sillytavern-sync@example.com\"; \
|
| 109 |
+
echo '--- Git identity configured for runtime user. ---'; \
|
| 110 |
+
# --- END: Configure Git default identity at Runtime --- \
|
| 111 |
+
|
| 112 |
+
# --- BEGIN: Dynamically Install Plugins at Runtime --- \
|
| 113 |
+
echo '--- Checking for PLUGINS environment variable ---'; \
|
| 114 |
+
if [ -n \"$PLUGINS\" ]; then \
|
| 115 |
+
echo \"*** Installing Plugins specified in PLUGINS environment variable: $PLUGINS ***\" && \
|
| 116 |
+
# Ensure plugins directory exists
|
| 117 |
+
mkdir -p ./plugins && chown node:node ./plugins && \
|
| 118 |
+
# Set comma as delimiter
|
| 119 |
+
IFS=',' && \
|
| 120 |
+
# Loop through each plugin URL
|
| 121 |
+
for plugin_url in $PLUGINS; do \
|
| 122 |
+
# Trim leading/trailing whitespace
|
| 123 |
+
plugin_url=$(echo \"$plugin_url\" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') && \
|
| 124 |
+
if [ -z \"$plugin_url\" ]; then continue; fi && \
|
| 125 |
+
# Extract plugin name
|
| 126 |
+
plugin_name_git=$(basename \"$plugin_url\") && \
|
| 127 |
+
plugin_name=${plugin_name_git%.git} && \
|
| 128 |
+
plugin_dir=\"./plugins/$plugin_name\" && \
|
| 129 |
+
echo \"--- Installing plugin: $plugin_name from $plugin_url into $plugin_dir ---\" && \
|
| 130 |
+
# Remove existing dir if it exists
|
| 131 |
+
rm -rf \"$plugin_dir\" && \
|
| 132 |
+
# Clone the plugin (run as root, fix perms later)
|
| 133 |
+
git clone --depth 1 \"$plugin_url\" \"$plugin_dir\" && \
|
| 134 |
+
if [ -f \"$plugin_dir/package.json\" ]; then \
|
| 135 |
+
echo \"--- Installing dependencies for $plugin_name ---\" && \
|
| 136 |
+
(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\"; \
|
| 137 |
+
else \
|
| 138 |
+
echo \"--- No package.json found for $plugin_name, skipping dependency install. ---\"; \
|
| 139 |
+
fi || echo \"WARN: Failed to clone $plugin_name from $plugin_url, skipping...\"; \
|
| 140 |
+
done && \
|
| 141 |
+
# Reset IFS
|
| 142 |
+
unset IFS && \
|
| 143 |
+
# Fix permissions for plugins directory after installation
|
| 144 |
+
echo \"--- Setting permissions for plugins directory ---\" && \
|
| 145 |
+
chown -R node:node ./plugins && \
|
| 146 |
+
echo \"*** Plugin installation finished. ***\"; \
|
| 147 |
+
else \
|
| 148 |
+
echo 'PLUGINS environment variable is not set or empty, skipping runtime plugin installation.'; \
|
| 149 |
+
fi; \
|
| 150 |
+
# --- END: Dynamically Install Plugins at Runtime --- \
|
| 151 |
+
|
| 152 |
+
echo 'Starting SillyTavern server directly...'; \
|
| 153 |
+
# Execute node server directly, bypassing docker-entrypoint.sh
|
| 154 |
+
exec node server.js; \
|
| 155 |
+
"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|