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M 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 |
+
RUN apk add --no-cache gcompat tini git unzip
|
| 10 |
+
|
| 11 |
+
# Create app directory
|
| 12 |
+
WORKDIR ${APP_HOME}
|
| 13 |
+
|
| 14 |
+
# Set NODE_ENV to production
|
| 15 |
+
ENV NODE_ENV=production
|
| 16 |
+
|
| 17 |
+
# Copy the zip file from the build context
|
| 18 |
+
COPY sillytavern.zip .
|
| 19 |
+
RUN \
|
| 20 |
+
echo "*** Unzipping SillyTavern Core ***" && \
|
| 21 |
+
unzip -q sillytavern.zip && \
|
| 22 |
+
rm sillytavern.zip
|
| 23 |
+
|
| 24 |
+
# --- BEGIN: Remove root .gitignore if exists ---
|
| 25 |
+
RUN \
|
| 26 |
+
echo "*** Attempting to remove root .gitignore if it exists ***" && \
|
| 27 |
+
rm -f .gitignore && \
|
| 28 |
+
echo "*** Root .gitignore removed (if it existed). ***"
|
| 29 |
+
# --- END: Remove root .gitignore ---
|
| 30 |
+
|
| 31 |
+
# --- BEGIN: Clone or Update data-sync plugin ---
|
| 32 |
+
RUN \
|
| 33 |
+
echo "*** Checking data-sync plugin ***" && \
|
| 34 |
+
if [ -d "plugins/data-sync/.git" ]; then \
|
| 35 |
+
# Directory exists and is a git repository, try to update
|
| 36 |
+
echo "data-sync directory exists, attempting git pull..." && \
|
| 37 |
+
cd plugins/data-sync && \
|
| 38 |
+
# Reset any local changes before pulling
|
| 39 |
+
git reset --hard HEAD && \
|
| 40 |
+
git pull origin main --rebase --autostash && \
|
| 41 |
+
cd ${APP_HOME}; \
|
| 42 |
+
else \
|
| 43 |
+
# Directory does not exist or is not a git repo, clone it
|
| 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 or Update data-sync plugin ---
|
| 51 |
+
|
| 52 |
+
# Install base SillyTavern dependencies (package*.json should be in the unzipped root)
|
| 53 |
+
RUN \
|
| 54 |
+
echo "*** Install Base npm packages ***" && \
|
| 55 |
+
if [ -f package.json ]; then \
|
| 56 |
+
# Added --force to potentially overcome file system issues in docker/overlayfs
|
| 57 |
+
npm i --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force; \
|
| 58 |
+
else \
|
| 59 |
+
echo "No package.json found in root, skipping base npm install."; \
|
| 60 |
+
fi
|
| 61 |
+
|
| 62 |
+
# Install data-sync plugin dependencies
|
| 63 |
+
RUN \
|
| 64 |
+
# Check if plugins/data-sync directory exists (it should now)
|
| 65 |
+
if [ -d "plugins/data-sync" ]; then \
|
| 66 |
+
echo "*** Install data-sync plugin npm packages ***" && \
|
| 67 |
+
cd plugins/data-sync && \
|
| 68 |
+
if [ -f package.json ]; then \
|
| 69 |
+
# Added --force
|
| 70 |
+
npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force; \
|
| 71 |
+
else \
|
| 72 |
+
echo "No package.json found in data-sync, skipping npm install."; \
|
| 73 |
+
fi && \
|
| 74 |
+
cd ${APP_HOME}; \
|
| 75 |
+
else \
|
| 76 |
+
# This else block should ideally not be reached now
|
| 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}
|
| 83 |
+
|
| 84 |
+
# Create config directory. config.yaml will be handled at runtime by ENTRYPOINT
|
| 85 |
+
RUN mkdir -p config
|
| 86 |
+
|
| 87 |
+
# Pre-compile public libraries (build-lib.js should be in the unzipped structure)
|
| 88 |
+
RUN \
|
| 89 |
+
echo "*** Run Webpack ***" && \
|
| 90 |
+
# Check if build-lib.js exists before running
|
| 91 |
+
if [ -f "./docker/build-lib.js" ]; then \
|
| 92 |
+
node "./docker/build-lib.js"; \
|
| 93 |
+
elif [ -f "./build-lib.js" ]; then \
|
| 94 |
+
node "./build-lib.js"; \
|
| 95 |
+
else \
|
| 96 |
+
echo "build-lib.js not found, skipping Webpack build."; \
|
| 97 |
+
fi
|
| 98 |
+
|
| 99 |
+
# Cleanup unnecessary files (like the docker dir if it exists in the zip) and make entrypoint executable
|
| 100 |
+
# This block is removed as we no longer use docker-entrypoint.sh
|
| 101 |
+
# RUN \
|
| 102 |
+
# echo "*** Cleanup and Permissions ***" && \
|
| 103 |
+
# ...
|
| 104 |
+
|
| 105 |
+
# Fix potential git safe.directory issues if git commands are run later by scripts
|
| 106 |
+
RUN git config --global --add safe.directory "${APP_HOME}"
|
| 107 |
+
|
| 108 |
+
# Ensure the node user owns the application directory and its contents
|
| 109 |
+
RUN chown -R node:node ${APP_HOME}
|
| 110 |
+
|
| 111 |
+
EXPOSE 8000
|
| 112 |
+
|
| 113 |
+
# Entrypoint: Read config from environment variable CONFIG_YAML if set, copy default if not, configure git, then run node server.js directly
|
| 114 |
+
ENTRYPOINT ["tini", "--", "sh", "-c", " \
|
| 115 |
+
echo '--- Checking for CONFIG_YAML environment variable ---'; \
|
| 116 |
+
# Ensure the CWD has correct permissions for writing config.yaml
|
| 117 |
+
# mkdir -p ./config && chown node:node ./config; # Removed mkdir
|
| 118 |
+
if [ -n \"$CONFIG_YAML\" ]; then \
|
| 119 |
+
echo 'Environment variable CONFIG_YAML found. Writing to ./config.yaml (root directory)...'; \
|
| 120 |
+
# Write directly to ./config.yaml in the CWD
|
| 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
|
| 132 |
+
if [ -f \"./public/config.yaml.example\" ]; then \
|
| 133 |
+
# Copy default to ./config.yaml in the CWD
|
| 134 |
+
cp \"./public/config.yaml.example\" \"./config.yaml\" && \
|
| 135 |
+
chown node:node ./config.yaml && \
|
| 136 |
+
echo 'Copied default config to ./config.yaml'; \
|
| 137 |
+
else \
|
| 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; \
|
| 152 |
+
"]
|
README.md
CHANGED
|
@@ -1,12 +1,60 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SillyTavern (Zip Deploy) with Data Sync
|
| 3 |
+
emoji: 📦 # Changed emoji to reflect zip deployment
|
| 4 |
+
colorFrom: indigo
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
app_port: 8000 # SillyTavern default port
|
| 9 |
+
# Add secret for config.yaml
|
| 10 |
+
secrets:
|
| 11 |
+
- name: CONFIG_YAML
|
| 12 |
+
description: "Contents of your config.yaml file"
|
| 13 |
+
required: true
|
| 14 |
---
|
| 15 |
|
| 16 |
+
# SillyTavern with Data Sync Plugin (Zip Deployment)
|
| 17 |
+
|
| 18 |
+
This Space runs SillyTavern using a zipped deployment method to accommodate Hugging Face file limits. It includes the custom `data-sync` plugin.
|
| 19 |
+
|
| 20 |
+
**IMPORTANT:** This setup requires you to upload your SillyTavern installation (including the plugin) as a single `sillytavern.zip` file and provide your `config.yaml` content as a Hugging Face Secret.
|
| 21 |
+
|
| 22 |
+
## Setup and Deployment Steps
|
| 23 |
+
|
| 24 |
+
1. **Prepare Locally:**
|
| 25 |
+
* Have a working local installation of SillyTavern.
|
| 26 |
+
* Ensure the `data-sync` plugin (`https://github.com/fuwei99/data-sync.git`) is cloned into the `plugins/data-sync` directory within your local SillyTavern folder.
|
| 27 |
+
* **Crucially: Delete the `config.yaml` file from your local SillyTavern directory before proceeding.** Its contents will be added as a secret.
|
| 28 |
+
|
| 29 |
+
2. **Create `sillytavern.zip`:**
|
| 30 |
+
* Navigate **inside** your local SillyTavern directory (the one containing `server.js`, `public`, `plugins`, etc.).
|
| 31 |
+
* Select **all files and folders** within this directory.
|
| 32 |
+
* Create a zip archive named exactly `sillytavern.zip` from these selected contents.
|
| 33 |
+
* **DO NOT** zip the parent SillyTavern folder itself; the zip file's root should contain `server.js`, etc.
|
| 34 |
+
* *(Optional but Recommended)*: Exclude unnecessary files/folders like `.git`, `node_modules`, `chats/logs`, large backups, etc., to reduce the zip size.
|
| 35 |
+
|
| 36 |
+
3. **Upload to Hugging Face:**
|
| 37 |
+
* Clone your Hugging Face Space repository locally or use the web UI.
|
| 38 |
+
* Add/replace the following files in the root of your Space repository:
|
| 39 |
+
* This `README.md` file.
|
| 40 |
+
* The `Dockerfile` provided.
|
| 41 |
+
* The `sillytavern.zip` file you created in step 2.
|
| 42 |
+
* Commit and push the changes.
|
| 43 |
+
|
| 44 |
+
4. **Configure Secret:**
|
| 45 |
+
* Go to your Space's **Settings** tab on Hugging Face.
|
| 46 |
+
* Navigate to the **Secrets** section.
|
| 47 |
+
* Click **New secret**.
|
| 48 |
+
* Enter the name exactly as `CONFIG_YAML`.
|
| 49 |
+
* Paste the **entire content** of your original (now deleted locally) `config.yaml` file into the **Secret value** field.
|
| 50 |
+
* Save the secret.
|
| 51 |
+
|
| 52 |
+
5. **Build and Launch:**
|
| 53 |
+
* Hugging Face should automatically start building the Docker image based on the `Dockerfile` and your uploaded files.
|
| 54 |
+
* Once the build is complete, the Space should launch SillyTavern.
|
| 55 |
+
|
| 56 |
+
## Accessing SillyTavern and Data Sync
|
| 57 |
+
|
| 58 |
+
* Access the main SillyTavern interface via the public URL of your Space.
|
| 59 |
+
* Access the data-sync plugin UI at `/api/plugins/data-sync/ui` relative to your Space's URL.
|
| 60 |
+
* Remember to configure the data-sync plugin within its UI (repo URL, auth token if needed) and use its features to push/pull your data.
|
sillytavern.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c54306289e8e9555c9fdb24d4382366bbcc9f21417d6d0465259ce42e07a6049
|
| 3 |
+
size 37749225
|