clash-linux commited on
Commit
4e7c27f
·
verified ·
1 Parent(s): c8b53b1

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +188 -188
  2. README.md +232 -56
Dockerfile CHANGED
@@ -1,189 +1,189 @@
1
- FROM node:lts-alpine3.19
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}
15
-
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 \
29
- echo "*** Attempting to remove root .gitignore if it exists ***" && \
30
- rm -f .gitignore && \
31
- echo "*** Root .gitignore removed (if it existed). ***"
32
- # --- END: Remove root .gitignore ---
33
-
34
- # Install base SillyTavern dependencies (package*.json should be in the cloned root)
35
- RUN \
36
- echo "*** Install Base npm packages ***" && \
37
- if [ -f package.json ]; then \
38
- # Added --force to potentially overcome file system issues in docker/overlayfs
39
- npm i --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force; \
40
- else \
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
- # --- 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 \"sillytavern-sync@example.com\"; \
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
- echo 'Starting SillyTavern server directly...'; \
165
-
166
- # --- BEGIN: Cleanup before start --- \
167
- # Remove .gitignore
168
- echo 'Attempting final removal of .gitignore...' && \
169
- rm -f .gitignore && \
170
- if [ ! -e .gitignore ]; then \
171
- echo '.gitignore successfully removed.'; \
172
- else \
173
- # This case is unlikely with rm -f unless permissions prevent removal
174
- echo 'WARN: .gitignore could not be removed or reappeared.'; \
175
- fi; \
176
- # Remove .git directory
177
- echo 'Attempting final removal of .git directory...' && \
178
- rm -rf .git && \
179
- if [ ! -d .git ]; then \
180
- echo '.git directory successfully removed.'; \
181
- else \
182
- # This case usually indicates a permission issue
183
- echo 'WARN: .git directory could not be removed.'; \
184
- fi; \
185
- # --- END: Cleanup before start --- \
186
-
187
- # Execute node server directly, bypassing docker-entrypoint.sh
188
- exec node server.js; \
189
  "]
 
1
+ FROM node:lts-alpine3.19
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}
15
+
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 \
29
+ echo "*** Attempting to remove root .gitignore if it exists ***" && \
30
+ rm -f .gitignore && \
31
+ echo "*** Root .gitignore removed (if it existed). ***"
32
+ # --- END: Remove root .gitignore ---
33
+
34
+ # Install base SillyTavern dependencies (package*.json should be in the cloned root)
35
+ RUN \
36
+ echo "*** Install Base npm packages ***" && \
37
+ if [ -f package.json ]; then \
38
+ # Added --force to potentially overcome file system issues in docker/overlayfs
39
+ npm i --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force; \
40
+ else \
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
+ # --- 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 \"sillytavern-sync@example.com\"; \
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
+ echo 'Starting SillyTavern server directly...'; \
165
+
166
+ # --- BEGIN: Cleanup before start --- \
167
+ # Remove .gitignore
168
+ echo 'Attempting final removal of .gitignore...' && \
169
+ rm -f .gitignore && \
170
+ if [ ! -e .gitignore ]; then \
171
+ echo '.gitignore successfully removed.'; \
172
+ else \
173
+ # This case is unlikely with rm -f unless permissions prevent removal
174
+ echo 'WARN: .gitignore could not be removed or reappeared.'; \
175
+ fi; \
176
+ # Remove .git directory
177
+ echo 'Attempting final removal of .git directory...' && \
178
+ rm -rf .git && \
179
+ if [ ! -d .git ]; then \
180
+ echo '.git directory successfully removed.'; \
181
+ else \
182
+ # This case usually indicates a permission issue
183
+ echo 'WARN: .git directory could not be removed.'; \
184
+ fi; \
185
+ # --- END: Cleanup before start --- \
186
+
187
+ # Execute node server directly, bypassing docker-entrypoint.sh
188
+ exec node server.js; \
189
  "]
README.md CHANGED
@@ -1,64 +1,240 @@
1
  ---
2
- title: SillyTavern (Git Deploy) with Dynamic Plugins
3
- emoji: 🚀
4
- colorFrom: blue
5
- colorTo: purple
6
  sdk: docker
7
  pinned: false
8
- app_port: 8000 # SillyTavern default port
9
- # Add secrets
10
  secrets:
11
  - name: CONFIG_YAML
12
- description: "Contents of your config.yaml file"
13
- required: true # Keep config required
14
  - name: PLUGINS
15
- description: "Comma-separated list of Git URLs for plugins to install"
16
- required: false # Make plugins optional
17
  ---
18
 
19
- # SillyTavern with Dynamic Plugins (Git Deployment)
20
-
21
- This Space runs SillyTavern by cloning the core repository directly from GitHub and dynamically installing plugins specified via Hugging Face Secrets.
22
-
23
- **IMPORTANT:** This setup requires you to provide your `config.yaml` content as a Hugging Face Secret named `CONFIG_YAML`. Optionally, you can specify plugins to install via a secret named `PLUGINS`.
24
-
25
- ## Setup and Deployment Steps
26
-
27
- 1. **Prepare `config.yaml`:**
28
- * Ensure you have a valid `config.yaml` file for SillyTavern.
29
- * **Remove any comments** from the file, as they might interfere with environment variable parsing.
30
-
31
- 2. **Upload Files to Hugging Face:**
32
- * Clone your Hugging Face Space repository locally or use the web UI.
33
- * Add/replace the following files in the root of your Space repository:
34
- * This `README.md` file.
35
- * The `Dockerfile` provided in our conversation.
36
- * Commit and push the changes. **You no longer need to upload `sillytavern.zip`.**
37
-
38
- 3. **Configure Secrets:**
39
- * Go to your Space's **Settings** tab on Hugging Face.
40
- * Navigate to the **Secrets** section.
41
- * **Add `CONFIG_YAML` Secret:**
42
- * Click **New secret**.
43
- * Enter the name exactly as `CONFIG_YAML`.
44
- * Paste the **entire content** of your prepared (comment-free) `config.yaml` file into the **Secret value** field.
45
- * Save the secret.
46
- * **(Optional) Add `PLUGINS` Secret:**
47
- * Click **New secret** again.
48
- * Enter the name exactly as `PLUGINS`.
49
- * Paste a **comma-separated list** of the Git URLs for the plugins you want to install into the **Secret value** field. **Ensure there are no spaces around the commas.** Example:
50
- ```
51
- https://github.com/fuwei99/plugin-manager.git,https://github.com/fuwei99/cloud-saves.git,https://github.com/fuwei99/data-sync.git
52
- ```
53
- * Save the secret. If you leave this secret empty or don't create it, no extra plugins will be installed.
54
-
55
- 4. **Build and Launch:**
56
- * Hugging Face should automatically start building the Docker image based on the `Dockerfile`.
57
- * The build process will clone the SillyTavern core (`staging` branch) and then clone/install dependencies for the plugins listed in the `PLUGINS` secret.
58
- * Once the build is complete, the Space should launch SillyTavern.
59
-
60
- ## Accessing SillyTavern and Plugins
61
-
62
- * Access the main SillyTavern interface via the public URL of your Space.
63
- * If you installed plugins, access their UIs as needed (e.g., `/api/plugins/plugin-manager/ui`, `/api/plugins/data-sync/ui`, `/api/plugins/cloud-saves/ui`). Check each plugin's documentation for its specific path.
64
- * Remember to configure plugins like `data-sync` or `cloud-saves` within their respective UIs (repo URL, auth tokens, etc.).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: SillyTavern Docker & HF部署
3
+ emoji: 🥂
4
+ colorFrom: pink
5
+ colorTo: blue
6
  sdk: docker
7
  pinned: false
8
+ app_port: 8000 # SillyTavern 默认端口
9
+ # 定义所需的 Hugging Face Secrets
10
  secrets:
11
  - name: CONFIG_YAML
12
+ description: "你的 config.yaml 文件内容(无注释)"
13
+ required: true # 配置是必需的
14
  - name: PLUGINS
15
+ description: "要安装的插件Git URL列表(逗号分隔)"
16
+ required: false # 插件是可选的
17
  ---
18
 
19
+ # 最简单的方法:一键部署
20
+
21
+ 如果你不想手动配置,可以直接点击下方按钮,一键将 SillyTavern Docker 部署到你自己的 Hugging Face Space 中(需要先注册 Hugging Face 账号):
22
+
23
+ [![部署到 Hugging Face Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/deploy-to-spaces-lg.svg)](https://huggingface.co/spaces/malt666/Tavern-Docker?duplicate=true)
24
+
25
+ 点击按钮后,系统会帮你复制一份完整的项目配置,你只需要按照提示设置 Secrets(主要是修改 CONFIG_YAML 中的用户名和密码),即可完成部署。这是最适合新手的快捷部署方式。
26
+
27
+ ---
28
+
29
+ # SillyTavern Docker Hugging Face 部署指南
30
+
31
+ 本指南说明了如何使用提供的 `Dockerfile` 来构建和运行 SillyTavern,以及如何在 Hugging Face Spaces 上进行部署。部署的核心思想是通过环境变量在容器启动时动态配置 SillyTavern 和安装插件。
32
+
33
+ ## 关键文件
34
+
35
+ * `Dockerfile`: 用于构建 SillyTavern 运行环境的 Docker 镜像。它会:
36
+ * 基于官方 Node.js Alpine 镜像。
37
+ * 安装必要的系统依赖(如 `git`)。
38
+ * 从 GitHub 克隆 SillyTavern 的 `staging` 分支代码。
39
+ * 设置工作目录和用户权限。
40
+ * 定义容器启动���的 `ENTRYPOINT` 脚本,该脚本负责:
41
+ * 读取 `CONFIG_YAML` 环境变量并写入 `./config.yaml` 文件。
42
+ * 读取 `PLUGINS` 环境变量,并克隆、安装指定的插件。
43
+ * 启动 SillyTavern 服务器 (`node server.js`)。
44
+ * `README.md`: 本说明文件。
45
+
46
+ ## 配置方式:环境变量
47
+
48
+ 我们通过两个主要的环境变量来配置容器:
49
+
50
+ 1. `CONFIG_YAML`: **必需**。
51
+ * **作用**: 定义 SillyTavern 的运行配置。
52
+ * **内容**: 下面是推荐的默认配置内容。你可以直接复制粘贴使用,但**强烈建议你修改其中的认证信息**。
53
+ * **推荐配置内容**:
54
+ ```yaml
55
+ dataRoot: ./data
56
+ listen: true
57
+ listenAddress:
58
+ ipv4: 0.0.0.0
59
+ ipv6: '[::]'
60
+ protocol:
61
+ ipv4: true
62
+ ipv6: false
63
+ dnsPreferIPv6: false
64
+ autorunHostname: "auto"
65
+ port: 8000
66
+ autorunPortOverride: -1
67
+ ssl:
68
+ enabled: false
69
+ certPath: "./certs/cert.pem"
70
+ keyPath: "./certs/privkey.pem"
71
+ whitelistMode: false
72
+ enableForwardedWhitelist: false
73
+ whitelist:
74
+ - ::1
75
+ - 127.0.0.1
76
+ whitelistDockerHosts: true
77
+ basicAuthMode: true
78
+ basicAuthUser:
79
+ username: "用户名" # 请务必修改为你自己的用户名
80
+ password: "密码" # 请务必修改为你自己的密码
81
+ enableCorsProxy: false
82
+ requestProxy:
83
+ enabled: false
84
+ url: "socks5://username:password@example.com:1080"
85
+ bypass:
86
+ - localhost
87
+ - 127.0.0.1
88
+ enableUserAccounts: false
89
+ enableDiscreetLogin: false
90
+ autheliaAuth: false
91
+ perUserBasicAuth: false
92
+ sessionTimeout: -1
93
+ disableCsrfProtection: false
94
+ securityOverride: false
95
+ logging:
96
+ enableAccessLog: true
97
+ minLogLevel: 0
98
+ rateLimiting:
99
+ preferRealIpHeader: false
100
+ autorun: false
101
+ avoidLocalhost: false
102
+ backups:
103
+ common:
104
+ numberOfBackups: 50
105
+ chat:
106
+ enabled: true
107
+ checkIntegrity: true
108
+ maxTotalBackups: -1
109
+ throttleInterval: 10000
110
+ thumbnails:
111
+ enabled: true
112
+ format: "jpg"
113
+ quality: 95
114
+ dimensions: { 'bg': [160, 90], 'avatar': [96, 144] }
115
+ performance:
116
+ lazyLoadCharacters: false
117
+ memoryCacheCapacity: '100mb'
118
+ useDiskCache: true
119
+ allowKeysExposure: false
120
+ skipContentCheck: false
121
+ whitelistImportDomains:
122
+ - localhost
123
+ - cdn.discordapp.com
124
+ - files.catbox.moe
125
+ - raw.githubusercontent.com
126
+ requestOverrides: []
127
+ extensions:
128
+ enabled: true
129
+ autoUpdate: true
130
+ models:
131
+ autoDownload: true
132
+ classification: Cohee/distilbert-base-uncased-go-emotions-onnx
133
+ captioning: Xenova/vit-gpt2-image-captioning
134
+ embedding: Cohee/jina-embeddings-v2-base-en
135
+ speechToText: Xenova/whisper-small
136
+ textToSpeech: Xenova/speecht5_tts
137
+ enableDownloadableTokenizers: true
138
+ promptPlaceholder: "[Start a new chat]"
139
+ openai:
140
+ randomizeUserId: false
141
+ captionSystemPrompt: ""
142
+ deepl:
143
+ formality: default
144
+ mistral:
145
+ enablePrefix: false
146
+ ollama:
147
+ keepAlive: -1
148
+ batchSize: -1
149
+ claude:
150
+ enableSystemPromptCache: false
151
+ cachingAtDepth: -1
152
+ enableServerPlugins: true
153
+ enableServerPluginsAutoUpdate: false
154
+ ```
155
+ * **⚠️ 重要警告**: 请务必修改上方配置中 `basicAuthUser` 下的 `username` 和 `password` 为你自己的凭据,以确保安全!**不要使用默认的 "用户名" 和 "密码"!**
156
+ * **注意**: 必须是有效的 YAML 格式,且**不应包含任何 `#` 开头的注释行**。
157
+
158
+ 2. `PLUGINS`: **可选**。
159
+ * **作用**: 指定需要在容器启动时自动安装的 SillyTavern 插件。
160
+ * **内容**: 一个**逗号分隔**的插件 Git 仓库 URL 列表。
161
+ * **推荐安装**: 强烈建议安装 `cloud-saves` 插件,以便在不同部署环境(如本地和 Hugging Face)之间同步数据。
162
+ * **插件地址**: `https://github.com/fuwei99/cloud-saves.git`
163
+ * **重要前置条件**: 为了让容器/Hugging Face Space 能够拉取你的存档,你**必须**先在你本地的 SillyTavern 中安装好 `cloud-saves` 插件,并**至少进行一次数据存档操作**。这样,远程部署的环境才能通过该插件下载你的存档。
164
+ * **格式示例**: `https://github.com/fuwei99/cloud-saves.git` (注意包含推荐的 cloud-saves 插件)
165
+ * **注意**: URL 之间**只能用英文逗号 `,` 分隔**,且逗号前后**不能有空格**。如果留空或不提供此变量,��不会安装额外插件。
166
+
167
+ ## 方法一:本地 Docker 部署
168
+
169
+ 你可以在本地使用 Docker 来构建和运行 SillyTavern。
170
+
171
+ 1. **构建镜像**: 在包含 `Dockerfile` 的目录下,运行:
172
+ ```bash
173
+ docker build -t sillytavern-local .
174
+ ```
175
+ 将 `sillytavern-local` 替换为你想要的镜像名称。
176
+
177
+ 2. **准备配置**: 将你的 `config.yaml` 内容(无注释)准备好。
178
+
179
+ 3. **运行容器**: 使用 `docker run` 命令,并通过 `-e` 参数传递环境变量。
180
+ * 将上方提供的**推荐配置内容**复制,并作为 `CONFIG_YAML` 环境变量的值。**确保你已经修改了其中的用户名和密码!**
181
+ * 如果你需要安装插件(**推荐安装 `cloud-saves`**),请准备好插件 URL 列表。
182
+
183
+ ```bash
184
+ # 示例:使用推荐配置并安装 cloud-saves 插件
185
+ # 1. 将推荐配置(修改密码后)保存到名为 config_no_comments.yaml 的文件中
186
+ # 2. 运行以下命令
187
+
188
+ docker run -p 8000:8000 --name my-sillytavern \\
189
+ -e CONFIG_YAML="$(cat config_no_comments.yaml)" \\
190
+ -e PLUGINS='https://github.com/fuwei99/cloud-saves.git' \\
191
+ sillytavern-local
192
+
193
+ # 如果你需要安装更多插件,用逗号隔开添加到 PLUGINS 变量中
194
+ # 例如:
195
+ # docker run -p 8000:8000 --name my-sillytavern \
196
+ # -e CONFIG_YAML="$(cat config_no_comments.yaml)" \
197
+ # -e PLUGINS='https://github.com/fuwei99/cloud-saves.git,https://github.com/user/other-plugin.git' \
198
+ # sillytavern-local
199
+ ```
200
+ * `-p 8000:8000`: 将容器的 8000 端口映射到宿主机的 8000 端口。
201
+ * `--name my-sillytavern`: 为容器命名,方便管理。
202
+ * `-e CONFIG_YAML="$(cat config_no_comments.yaml)"`: 从文件读取配置内容并传递。这是处理多行 YAML 最可靠的方式。**再次确认:运行前务必修改 `config_no_comments.yaml` 文件中的用户名和密码!**
203
+ * `-e PLUGINS='...'`: 传递插件列表,这里以安装 `cloud-saves` 为例。
204
+
205
+ 4. **访问**: 打开浏览器访问 `http://localhost:8000`。
206
+
207
+ ## 方法二:Hugging Face Spaces 部署
208
+
209
+ 这是推荐的在线部署方式,利用 Hugging Face 的免费计算资源和 Secrets 管理功能。
210
+
211
+ 1. **创建 Space**: 在 Hugging Face 上创建一个新的 Space,选择 **Docker** SDK。
212
+
213
+ 2. **上传文件**: 将本项目中的 `Dockerfile` 和 `README.md` 文件上传到你的 Space 仓库根目录。
214
+
215
+ 3. **配置 Secrets**: 进入你的 Space 页面的 **Settings -> Secrets** 部分。
216
+ * **添加 `CONFIG_YAML` Secret**:
217
+ * 点击 "New secret"。
218
+ * 名称 (Name) 输入: `CONFIG_YAML`
219
+ * 值 (Value) 粘贴: **复制上方提供的推荐配置内容**。**再次强调:粘贴前请务必修改 `basicAuthUser` 下的 `username` 和 `password` 为你自己的安全凭据!**
220
+ * 点击 "Add secret"。
221
+ * **(推荐) 添加 `PLUGINS` Secret**:
222
+ * 再次点击 "New secret"。
223
+ * 名称 (Name) 输入: `PLUGINS`
224
+ * 值 (Value) 粘贴: 推荐至少包含 `cloud-saves` 插件。例如:`https://github.com/fuwei99/cloud-saves.git`。如果你需要其他插件,用逗号隔开添加,例如:`https://github.com/fuwei99/cloud-saves.git,https://github.com/user/other-plugin.git`。
225
+ * **重要提醒**: 请确保你已经在本地 SillyTavern 安装了 `cloud-saves` 并至少进行了一次存档。
226
+ * 点击 "Add secret"。如果你确实不需要任何额外插件,可以跳过这一步。
227
+
228
+ 4. **构建与启动**: Hugging Face 会自动检测到 `Dockerfile` 和 Secrets,并开始构建镜像、启动容器。你可以在 Space 的 **Logs** 标签页查看构建和启动过程。
229
+
230
+ 5. **访问**: 构建成功并启动后,通过 Space 提供的公共 URL 访问 SillyTavern 界面。
231
+
232
+ ## 插件访问
233
+
234
+ 如果通过 `PLUGINS` 环境变量安装了插件,你需要根据各个插件的说明文档找到访问其界面的路径。
235
+
236
+ * 对于推荐安装的 `cloud-saves` 插件,其管理界面通常位于:
237
+ `http://<你的SillyTavern访问地址>/api/plugins/cloud-saves/ui`
238
+ 例如,如果是本地部署,则为 `http://127.0.0.1:8000/api/plugins/cloud-saves/ui`。如果是 Hugging Face Space,则将 `<你的SillyTavern访问地址>` 替换为你的 Space 公共 URL。
239
+
240
+ 其他插件的访问路径请参考其各自的文档。