clash-linux commited on
Commit
e74f0e8
·
verified ·
1 Parent(s): d942c4b

Upload 2 files

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -95
Dockerfile CHANGED
@@ -40,106 +40,27 @@ 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: Install plugins, Read config, Configure git, Run server
52
- ENTRYPOINT ["tini", "--", "sh", "-c", " \
53
- # --- BEGIN: Install Plugins at Runtime --- \
54
- if [ -n \"$PLUGINS\" ]; then \
55
- echo '--- Found PLUGINS environment variable, attempting to install plugins ---'; \
56
- # Ensure plugin dir exists \
57
- mkdir -p plugins; \
58
- # Use temp var and add trailing comma for loop robustness \
59
- temp_plugins_var=\"$PLUGINS,\"; \
60
- while [ -n \"$temp_plugins_var\" ]; do \
61
- plugin_url=\"${temp_plugins_var%%,*}\"; # Get first element \
62
- temp_plugins_var=\"${temp_plugins_var#*,}\"; # Remove first element \
63
- \
64
- # Trim leading/trailing whitespace using awk \
65
- plugin_url=$(echo \"$plugin_url\" | awk '{$1=$1;print}'); \
66
- \
67
- if [ -z \"$plugin_url\" ]; then continue; fi; \
68
- \
69
- # Extract plugin name: remove .git suffix, then get basename \
70
- plugin_name_tmp=\"${plugin_url%.git}\"; \
71
- plugin_name=\"${plugin_name_tmp##*/}\"; \
72
- \
73
- if [ -z \"$plugin_name\" ]; then \
74
- echo \"WARN: Could not extract plugin name from URL: $plugin_url, skipping.\"; \
75
- continue; \
76
- fi; \
77
- \
78
- plugin_dir=\"./plugins/$plugin_name\"; \
79
- echo \"--- Processing plugin: $plugin_name from $plugin_url ---\"; \
80
- \
81
- # Clone (remove existing first) \
82
- rm -rf \"$plugin_dir\"; \
83
- echo \"Cloning into $plugin_dir...\"; \
84
- if git clone --depth 1 \"$plugin_url\" \"$plugin_dir\"; then \
85
- echo \"Cloned successfully.\"; \
86
- # Install dependencies if package.json exists \
87
- if [ -f \"$plugin_dir/package.json\" ]; then \
88
- echo \"Found package.json, installing dependencies for $plugin_name...\"; \
89
- # Run npm install within the plugin directory \
90
- (cd \"$plugin_dir\" && npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force); \
91
- if [ \$? -ne 0 ]; then \
92
- echo \"WARN: Failed to install dependencies for $plugin_name\"; \
93
- else \
94
- echo \"Dependencies installed for $plugin_name.\"; \
95
- fi; \
96
- else \
97
- echo \"No package.json found for $plugin_name, skipping dependency install.\"; \
98
- fi; \
99
- else \
100
- echo \"WARN: Failed to clone $plugin_name from $plugin_url, skipping further processing.\"; \
101
- fi; \
102
- done; \
103
- echo '--- Finished processing plugins ---'; \
104
- else \
105
- echo '--- PLUGINS environment variable not set or empty, skipping plugin installation ---'; \
106
- fi; \
107
- \
108
- # --- Original Entrypoint logic --- \
109
- echo '--- Checking for CONFIG_YAML environment variable ---'; \
110
- # Ensure the CWD has correct permissions for writing config.yaml \
111
- # mkdir -p ./config && chown node:node ./config; # Removed mkdir \
112
- if [ -n \"$CONFIG_YAML\" ]; then \
113
- echo 'Environment variable CONFIG_YAML found. Writing to ./config.yaml (root directory)...'; \
114
- # Write directly to ./config.yaml in the CWD \
115
- # Need to ensure node user has write permission here. CWD should be owned by node due to chown and USER node. \
116
- printf '%s\n' \"$CONFIG_YAML\" > ./config.yaml && \
117
- echo 'Config written to ./config.yaml successfully.'; \
118
- # --- BEGIN DEBUG: Print the written config file --- \
119
- echo '--- Verifying written ./config.yaml ---'; \
120
- cat ./config.yaml; \
121
- echo '--- End of ./config.yaml ---'; \
122
- # --- END DEBUG --- \
123
- else \
124
- echo 'Warning: Environment variable CONFIG_YAML is not set or empty. Attempting to copy default config...'; \
125
- # Copy default if ENV VAR is missing and the example exists \
126
- if [ -f \"./public/config.yaml.example\" ]; then \
127
- # Copy default to ./config.yaml in the CWD \
128
- cp \"./public/config.yaml.example\" \"./config.yaml\" && \
129
- echo 'Copied default config to ./config.yaml'; \
130
- else \
131
- echo 'Warning: Default config ./public/config.yaml.example not found.'; \
132
- fi; \
133
- fi; \
134
- \
135
- # --- BEGIN: Configure Git default identity at Runtime --- \
136
- echo '--- Configuring Git default user identity at runtime ---'; \
137
- git config --global user.name \"SillyTavern Sync\" && \
138
- git config --global user.email \"sillytavern-sync@example.com\"; \
139
- echo '--- Git identity configured for runtime user. ---'; \
140
- # --- END: Configure Git default identity at Runtime --- \
141
- \
142
- echo 'Starting SillyTavern server directly...'; \
143
- # Execute node server directly. Since we used USER node, this should run as the node user. \
144
- exec node server.js; \
145
- "]
 
40
  echo "No package.json found in root, skipping base npm install."; \
41
  fi
42
 
43
+ # Pre-compile public libraries (only if build-lib.js exists)
44
+ RUN \
45
+ echo "*** Run Webpack (if build-lib.js exists) ***" && \
46
+ if [ -f "./build-lib.js" ]; then \
47
+ node "./build-lib.js"; \
48
+ else \
49
+ echo "build-lib.js not found, skipping Webpack build."; \
50
+ fi
51
+
52
  # Ensure the node user owns the application directory and its contents
53
+ # Do this before COPYing the script as root
54
  RUN chown -R node:node ${APP_HOME}
55
 
56
+ # Copy the entrypoint script and set permissions
57
+ COPY entrypoint.sh /home/node/app/entrypoint.sh
58
+ RUN chown node:node /home/node/app/entrypoint.sh && chmod +x /home/node/app/entrypoint.sh
59
+
60
  # Switch to non-root user
61
  USER node
62
 
63
  EXPOSE 8000
64
 
65
+ # Entrypoint: Use tini to launch the script
66
+ ENTRYPOINT ["tini", "--", "/home/node/app/entrypoint.sh"]