clash-linux commited on
Commit
af997ac
·
verified ·
1 Parent(s): c77c442

Upload 2 files

Browse files
Files changed (1) hide show
  1. Dockerfile +76 -103
Dockerfile CHANGED
@@ -8,7 +8,8 @@ ARG PLUGINS="" # Comma-separated list of plugin git URLs
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}
@@ -31,36 +32,6 @@ 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 ***" && \
@@ -71,104 +42,106 @@ RUN \
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}
105
-
106
- # Create config directory. config.yaml will be handled at runtime by ENTRYPOINT
107
- RUN mkdir -p config
108
-
109
- # Pre-compile public libraries (build-lib.js should be in the unzipped structure)
110
- RUN \
111
- echo "*** Run Webpack ***" && \
112
- # Check if build-lib.js exists before running
113
- if [ -f "./docker/build-lib.js" ]; then \
114
- node "./docker/build-lib.js"; \
115
- elif [ -f "./build-lib.js" ]; then \
116
- node "./build-lib.js"; \
117
- else \
118
- echo "build-lib.js not found, skipping Webpack build."; \
119
- fi
120
-
121
- # Cleanup unnecessary files (like the docker dir if it exists in the zip) and make entrypoint executable
122
- # This block is removed as we no longer use docker-entrypoint.sh
123
- # RUN \
124
- # echo "*** Cleanup and Permissions ***" && \
125
- # ...
126
-
127
- # Fix potential git safe.directory issues if git commands are run later by scripts
128
- RUN git config --global --add safe.directory "${APP_HOME}"
129
-
130
  # Ensure the node user owns the application directory and its contents
131
  RUN chown -R node:node ${APP_HOME}
132
 
 
 
 
133
  EXPOSE 8000
134
 
135
- # Entrypoint: Read config from environment variable CONFIG_YAML if set, copy default if not, configure git, then run node server.js directly
136
  ENTRYPOINT ["tini", "--", "sh", "-c", " \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  echo '--- Checking for CONFIG_YAML environment variable ---'; \
138
- # Ensure the CWD has correct permissions for writing config.yaml
139
- # mkdir -p ./config && chown node:node ./config; # Removed mkdir
140
  if [ -n \"$CONFIG_YAML\" ]; then \
141
  echo 'Environment variable CONFIG_YAML found. Writing to ./config.yaml (root directory)...'; \
142
- # Write directly to ./config.yaml in the CWD
 
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
154
  if [ -f \"./public/config.yaml.example\" ]; then \
155
- # Copy default to ./config.yaml in the CWD
156
  cp \"./public/config.yaml.example\" \"./config.yaml\" && \
157
- chown node:node ./config.yaml && \
158
  echo 'Copied default config to ./config.yaml'; \
159
  else \
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; \
174
  "]
 
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
+ # Add awk for entrypoint script string manipulation
12
+ RUN apk add --no-cache gcompat tini git unzip wget awk
13
 
14
  # Create app directory
15
  WORKDIR ${APP_HOME}
 
32
  echo "*** Root .gitignore removed (if it existed). ***"
33
  # --- END: Remove root .gitignore ---
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  # Install base SillyTavern dependencies (package*.json should be in the cloned root)
36
  RUN \
37
  echo "*** Install Base npm packages ***" && \
 
42
  echo "No package.json found in root, skipping base npm install."; \
43
  fi
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # Ensure the node user owns the application directory and its contents
46
  RUN chown -R node:node ${APP_HOME}
47
 
48
+ # Switch to non-root user
49
+ USER node
50
+
51
  EXPOSE 8000
52
 
53
+ # Entrypoint: Install plugins, Read config, Configure git, Run server
54
  ENTRYPOINT ["tini", "--", "sh", "-c", " \
55
+ # --- BEGIN: Install Plugins at Runtime --- \
56
+ if [ -n \"$PLUGINS\" ]; then \
57
+ echo '--- Found PLUGINS environment variable, attempting to install plugins ---'; \
58
+ # Ensure plugin dir exists \
59
+ mkdir -p plugins; \
60
+ # Use temp var and add trailing comma for loop robustness \
61
+ temp_plugins_var=\"$PLUGINS,\"; \
62
+ while [ -n \"$temp_plugins_var\" ]; do \
63
+ plugin_url=\"${temp_plugins_var%%,*}\"; # Get first element \
64
+ temp_plugins_var=\"${temp_plugins_var#*,}\"; # Remove first element \
65
+ \
66
+ # Trim leading/trailing whitespace using awk \
67
+ plugin_url=$(echo \"$plugin_url\" | awk '{$1=$1;print}'); \
68
+ \
69
+ if [ -z \"$plugin_url\" ]; then continue; fi; \
70
+ \
71
+ # Extract plugin name: remove .git suffix, then get basename \
72
+ plugin_name_tmp=\"${plugin_url%.git}\"; \
73
+ plugin_name=\"${plugin_name_tmp##*/}\"; \
74
+ \
75
+ if [ -z \"$plugin_name\" ]; then \
76
+ echo \"WARN: Could not extract plugin name from URL: $plugin_url, skipping.\"; \
77
+ continue; \
78
+ fi; \
79
+ \
80
+ plugin_dir=\"./plugins/$plugin_name\"; \
81
+ echo \"--- Processing plugin: $plugin_name from $plugin_url ---\"; \
82
+ \
83
+ # Clone (remove existing first) \
84
+ rm -rf \"$plugin_dir\"; \
85
+ echo \"Cloning into $plugin_dir...\"; \
86
+ if git clone --depth 1 \"$plugin_url\" \"$plugin_dir\"; then \
87
+ echo \"Cloned successfully.\"; \
88
+ # Install dependencies if package.json exists \
89
+ if [ -f \"$plugin_dir/package.json\" ]; then \
90
+ echo \"Found package.json, installing dependencies for $plugin_name...\"; \
91
+ # Run npm install within the plugin directory \
92
+ (cd \"$plugin_dir\" && npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force); \
93
+ if [ \$? -ne 0 ]; then \
94
+ echo \"WARN: Failed to install dependencies for $plugin_name\"; \
95
+ else \
96
+ echo \"Dependencies installed for $plugin_name.\"; \
97
+ fi; \
98
+ else \
99
+ echo \"No package.json found for $plugin_name, skipping dependency install.\"; \
100
+ fi; \
101
+ else \
102
+ echo \"WARN: Failed to clone $plugin_name from $plugin_url, skipping further processing.\"; \
103
+ fi; \
104
+ done; \
105
+ echo '--- Finished processing plugins ---'; \
106
+ else \
107
+ echo '--- PLUGINS environment variable not set or empty, skipping plugin installation ---'; \
108
+ fi; \
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
  "]