suthep 0.1.0 → 0.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -71
- package/dist/commands/deploy.js +251 -37
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/down.js +179 -0
- package/dist/commands/down.js.map +1 -0
- package/dist/commands/redeploy.js +59 -0
- package/dist/commands/redeploy.js.map +1 -0
- package/dist/commands/up.js +213 -0
- package/dist/commands/up.js.map +1 -0
- package/dist/index.js +36 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/certbot.js +40 -3
- package/dist/utils/certbot.js.map +1 -1
- package/dist/utils/config-loader.js +30 -0
- package/dist/utils/config-loader.js.map +1 -1
- package/dist/utils/deployment.js +49 -16
- package/dist/utils/deployment.js.map +1 -1
- package/dist/utils/docker.js +396 -25
- package/dist/utils/docker.js.map +1 -1
- package/dist/utils/nginx.js +167 -8
- package/dist/utils/nginx.js.map +1 -1
- package/docs/README.md +25 -49
- package/docs/english/01-introduction.md +84 -0
- package/docs/english/02-installation.md +200 -0
- package/docs/english/03-quick-start.md +256 -0
- package/docs/english/04-configuration.md +358 -0
- package/docs/english/05-commands.md +363 -0
- package/docs/english/06-examples.md +456 -0
- package/docs/english/07-troubleshooting.md +417 -0
- package/docs/english/08-advanced.md +411 -0
- package/docs/english/README.md +48 -0
- package/docs/thai/01-introduction.md +84 -0
- package/docs/thai/02-installation.md +200 -0
- package/docs/thai/03-quick-start.md +256 -0
- package/docs/thai/04-configuration.md +358 -0
- package/docs/thai/05-commands.md +363 -0
- package/docs/thai/06-examples.md +456 -0
- package/docs/thai/07-troubleshooting.md +417 -0
- package/docs/thai/08-advanced.md +411 -0
- package/docs/thai/README.md +48 -0
- package/example/README.md +286 -53
- package/example/suthep-complete.yml +103 -0
- package/example/suthep-docker-only.yml +71 -0
- package/example/suthep-no-docker.yml +51 -0
- package/example/suthep-path-routing.yml +62 -0
- package/example/suthep.example.yml +89 -0
- package/package.json +1 -1
- package/src/commands/deploy.ts +322 -50
- package/src/commands/down.ts +240 -0
- package/src/commands/redeploy.ts +78 -0
- package/src/commands/up.ts +271 -0
- package/src/index.ts +62 -1
- package/src/types/config.ts +25 -24
- package/src/utils/certbot.ts +68 -6
- package/src/utils/config-loader.ts +40 -0
- package/src/utils/deployment.ts +61 -36
- package/src/utils/docker.ts +634 -30
- package/src/utils/nginx.ts +187 -4
- package/suthep-0.1.0-beta.1.tgz +0 -0
- package/suthep-0.1.1.tgz +0 -0
- package/suthep.example.yml +34 -0
- package/suthep.yml +39 -0
- package/test +0 -0
- package/docs/api-reference.md +0 -545
- package/docs/architecture.md +0 -367
- package/docs/commands.md +0 -273
- package/docs/configuration.md +0 -347
- package/docs/examples.md +0 -537
- package/docs/getting-started.md +0 -197
- package/docs/troubleshooting.md +0 -441
- package/example/docker-compose.yml +0 -72
- package/example/suthep.yml +0 -31
package/src/utils/nginx.ts
CHANGED
|
@@ -6,15 +6,24 @@ import type { ServiceConfig } from '../types/config'
|
|
|
6
6
|
/**
|
|
7
7
|
* Generate Nginx server block configuration for a service
|
|
8
8
|
*/
|
|
9
|
-
export function generateNginxConfig(
|
|
9
|
+
export function generateNginxConfig(
|
|
10
|
+
service: ServiceConfig,
|
|
11
|
+
withHttps: boolean,
|
|
12
|
+
portOverride?: number
|
|
13
|
+
): string {
|
|
10
14
|
const serverNames = service.domains.join(' ')
|
|
11
|
-
|
|
15
|
+
// Use primary domain for upstream naming to ensure uniqueness
|
|
16
|
+
const primaryDomain = service.domains[0]
|
|
17
|
+
const domainSafe = primaryDomain.replace(/\./g, '_').replace(/[^a-zA-Z0-9_]/g, '_')
|
|
18
|
+
const upstreamName = `${domainSafe}_${service.name}`
|
|
19
|
+
const servicePath = service.path || '/'
|
|
20
|
+
const port = portOverride || service.port
|
|
12
21
|
|
|
13
22
|
let config = `# Nginx configuration for ${service.name}\n\n`
|
|
14
23
|
|
|
15
24
|
// Upstream configuration
|
|
16
25
|
config += `upstream ${upstreamName} {\n`
|
|
17
|
-
config += ` server localhost:${
|
|
26
|
+
config += ` server localhost:${port} max_fails=3 fail_timeout=30s;\n`
|
|
18
27
|
config += ` keepalive 32;\n`
|
|
19
28
|
config += `}\n\n`
|
|
20
29
|
|
|
@@ -61,7 +70,7 @@ export function generateNginxConfig(service: ServiceConfig, withHttps: boolean):
|
|
|
61
70
|
|
|
62
71
|
// Proxy settings
|
|
63
72
|
config += ` # Proxy settings\n`
|
|
64
|
-
config += ` location
|
|
73
|
+
config += ` location ${servicePath} {\n`
|
|
65
74
|
config += ` proxy_pass http://${upstreamName};\n`
|
|
66
75
|
config += ` proxy_http_version 1.1;\n`
|
|
67
76
|
config += ` proxy_set_header Upgrade $http_upgrade;\n`
|
|
@@ -90,6 +99,180 @@ export function generateNginxConfig(service: ServiceConfig, withHttps: boolean):
|
|
|
90
99
|
return config
|
|
91
100
|
}
|
|
92
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Generate Nginx configuration for multiple services on the same domain
|
|
104
|
+
* Groups services by domain and creates location blocks for each service path
|
|
105
|
+
*/
|
|
106
|
+
export function generateMultiServiceNginxConfig(
|
|
107
|
+
services: ServiceConfig[],
|
|
108
|
+
domain: string,
|
|
109
|
+
withHttps: boolean,
|
|
110
|
+
portOverrides?: Map<string, number>
|
|
111
|
+
): string {
|
|
112
|
+
const upstreams: string[] = []
|
|
113
|
+
const locations: string[] = []
|
|
114
|
+
const healthChecks: string[] = []
|
|
115
|
+
|
|
116
|
+
// Sort services by path length (longest first) to ensure specific paths are matched before general ones
|
|
117
|
+
const sortedServices = [...services].sort((a, b) => {
|
|
118
|
+
const pathA = (a.path || '/').length
|
|
119
|
+
const pathB = (b.path || '/').length
|
|
120
|
+
return pathB - pathA
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// Track upstream names to ensure uniqueness within the same domain config
|
|
124
|
+
const usedUpstreamNames = new Set<string>()
|
|
125
|
+
|
|
126
|
+
for (const service of sortedServices) {
|
|
127
|
+
// Create unique upstream name: domain_service_name to avoid conflicts
|
|
128
|
+
// Replace dots and special chars in domain for valid nginx upstream name
|
|
129
|
+
const domainSafe = domain.replace(/\./g, '_').replace(/[^a-zA-Z0-9_]/g, '_')
|
|
130
|
+
let upstreamName = `${domainSafe}_${service.name}`
|
|
131
|
+
|
|
132
|
+
// Ensure uniqueness (in case same service name appears multiple times)
|
|
133
|
+
let counter = 1
|
|
134
|
+
const originalUpstreamName = upstreamName
|
|
135
|
+
while (usedUpstreamNames.has(upstreamName)) {
|
|
136
|
+
upstreamName = `${originalUpstreamName}_${counter}`
|
|
137
|
+
counter++
|
|
138
|
+
}
|
|
139
|
+
usedUpstreamNames.add(upstreamName)
|
|
140
|
+
|
|
141
|
+
const servicePath = service.path || '/'
|
|
142
|
+
const port = portOverrides?.get(service.name) || service.port
|
|
143
|
+
|
|
144
|
+
// Generate upstream for each service on the same domain
|
|
145
|
+
upstreams.push(`upstream ${upstreamName} {`)
|
|
146
|
+
upstreams.push(` server localhost:${port} max_fails=3 fail_timeout=30s;`)
|
|
147
|
+
upstreams.push(` keepalive 32;`)
|
|
148
|
+
upstreams.push(`}`)
|
|
149
|
+
|
|
150
|
+
// Generate location block
|
|
151
|
+
if (servicePath === '/') {
|
|
152
|
+
// Root path - use exact match or default
|
|
153
|
+
locations.push(` # Service: ${service.name}`)
|
|
154
|
+
locations.push(` location / {`)
|
|
155
|
+
} else {
|
|
156
|
+
// Specific path - use prefix match
|
|
157
|
+
locations.push(` # Service: ${service.name}`)
|
|
158
|
+
locations.push(` location ${servicePath} {`)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
locations.push(` proxy_pass http://${upstreamName};`)
|
|
162
|
+
locations.push(` proxy_http_version 1.1;`)
|
|
163
|
+
locations.push(` proxy_set_header Upgrade $http_upgrade;`)
|
|
164
|
+
locations.push(` proxy_set_header Connection 'upgrade';`)
|
|
165
|
+
locations.push(` proxy_set_header Host $host;`)
|
|
166
|
+
locations.push(` proxy_set_header X-Real-IP $remote_addr;`)
|
|
167
|
+
locations.push(` proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;`)
|
|
168
|
+
locations.push(` proxy_set_header X-Forwarded-Proto $scheme;`)
|
|
169
|
+
locations.push(` proxy_cache_bypass $http_upgrade;`)
|
|
170
|
+
locations.push(` proxy_connect_timeout 60s;`)
|
|
171
|
+
locations.push(` proxy_send_timeout 60s;`)
|
|
172
|
+
locations.push(` proxy_read_timeout 60s;`)
|
|
173
|
+
locations.push(` }`)
|
|
174
|
+
|
|
175
|
+
// Health check endpoint
|
|
176
|
+
if (service.healthCheck) {
|
|
177
|
+
healthChecks.push(` # Health check for ${service.name}`)
|
|
178
|
+
healthChecks.push(` location ${service.healthCheck.path} {`)
|
|
179
|
+
healthChecks.push(` proxy_pass http://${upstreamName};`)
|
|
180
|
+
healthChecks.push(` access_log off;`)
|
|
181
|
+
healthChecks.push(` }`)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let config = `# Nginx configuration for ${domain}\n`
|
|
186
|
+
config += `# Multiple services on the same domain\n\n`
|
|
187
|
+
|
|
188
|
+
// Add upstreams
|
|
189
|
+
config += upstreams.join('\n') + '\n\n'
|
|
190
|
+
|
|
191
|
+
if (withHttps) {
|
|
192
|
+
// HTTP server - redirect to HTTPS
|
|
193
|
+
config += `server {\n`
|
|
194
|
+
config += ` listen 80;\n`
|
|
195
|
+
config += ` listen [::]:80;\n`
|
|
196
|
+
config += ` server_name ${domain};\n\n`
|
|
197
|
+
config += ` # Redirect all HTTP to HTTPS\n`
|
|
198
|
+
config += ` return 301 https://$server_name$request_uri;\n`
|
|
199
|
+
config += `}\n\n`
|
|
200
|
+
|
|
201
|
+
// HTTPS server
|
|
202
|
+
config += `server {\n`
|
|
203
|
+
config += ` listen 443 ssl http2;\n`
|
|
204
|
+
config += ` listen [::]:443 ssl http2;\n`
|
|
205
|
+
config += ` server_name ${domain};\n\n`
|
|
206
|
+
|
|
207
|
+
// SSL configuration
|
|
208
|
+
config += ` # SSL Configuration\n`
|
|
209
|
+
config += ` ssl_certificate /etc/letsencrypt/live/${domain}/fullchain.pem;\n`
|
|
210
|
+
config += ` ssl_certificate_key /etc/letsencrypt/live/${domain}/privkey.pem;\n`
|
|
211
|
+
config += ` ssl_protocols TLSv1.2 TLSv1.3;\n`
|
|
212
|
+
config += ` ssl_ciphers HIGH:!aNULL:!MD5;\n`
|
|
213
|
+
config += ` ssl_prefer_server_ciphers on;\n\n`
|
|
214
|
+
} else {
|
|
215
|
+
// HTTP only server
|
|
216
|
+
config += `server {\n`
|
|
217
|
+
config += ` listen 80;\n`
|
|
218
|
+
config += ` listen [::]:80;\n`
|
|
219
|
+
config += ` server_name ${domain};\n\n`
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Logging
|
|
223
|
+
config += ` # Logging\n`
|
|
224
|
+
config += ` access_log /var/log/nginx/${domain}_access.log;\n`
|
|
225
|
+
config += ` error_log /var/log/nginx/${domain}_error.log;\n\n`
|
|
226
|
+
|
|
227
|
+
// Client settings
|
|
228
|
+
config += ` # Client settings\n`
|
|
229
|
+
config += ` client_max_body_size 100M;\n\n`
|
|
230
|
+
|
|
231
|
+
// Location blocks
|
|
232
|
+
config += ` # Service locations\n`
|
|
233
|
+
config += locations.join('\n') + '\n\n'
|
|
234
|
+
|
|
235
|
+
// Health check endpoints
|
|
236
|
+
if (healthChecks.length > 0) {
|
|
237
|
+
config += ` # Health check endpoints\n`
|
|
238
|
+
config += healthChecks.join('\n') + '\n'
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
config += `}\n`
|
|
242
|
+
|
|
243
|
+
return config
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Check if an Nginx config file exists
|
|
248
|
+
*/
|
|
249
|
+
export async function configExists(configName: string, configPath: string): Promise<boolean> {
|
|
250
|
+
const configFilePath = path.join(configPath, `${configName}.conf`)
|
|
251
|
+
return await fs.pathExists(configFilePath)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Write Nginx configuration file, deleting existing file if it exists and creating new one
|
|
256
|
+
*/
|
|
257
|
+
export async function writeNginxConfig(
|
|
258
|
+
configName: string,
|
|
259
|
+
configPath: string,
|
|
260
|
+
configContent: string
|
|
261
|
+
): Promise<boolean> {
|
|
262
|
+
const configFilePath = path.join(configPath, `${configName}.conf`)
|
|
263
|
+
const exists = await fs.pathExists(configFilePath)
|
|
264
|
+
|
|
265
|
+
// If config file exists, delete it first
|
|
266
|
+
if (exists) {
|
|
267
|
+
await fs.remove(configFilePath)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Create new config file
|
|
271
|
+
await fs.writeFile(configFilePath, configContent)
|
|
272
|
+
|
|
273
|
+
return exists // Return true if file existed (was deleted and recreated)
|
|
274
|
+
}
|
|
275
|
+
|
|
93
276
|
/**
|
|
94
277
|
* Enable an Nginx site by creating a symbolic link
|
|
95
278
|
*/
|
|
Binary file
|
package/suthep-0.1.1.tgz
ADDED
|
Binary file
|
package/suthep.example.yml
CHANGED
|
@@ -56,6 +56,40 @@ services:
|
|
|
56
56
|
domains:
|
|
57
57
|
- db.example.com
|
|
58
58
|
|
|
59
|
+
# Example 5: Multiple services on the same domain with path-based routing
|
|
60
|
+
# API service on /api path
|
|
61
|
+
- name: api
|
|
62
|
+
port: 3001
|
|
63
|
+
path: /api
|
|
64
|
+
domains:
|
|
65
|
+
- muacle.com
|
|
66
|
+
docker:
|
|
67
|
+
image: myapp/api:latest
|
|
68
|
+
container: api-container
|
|
69
|
+
port: 3001
|
|
70
|
+
healthCheck:
|
|
71
|
+
path: /health
|
|
72
|
+
interval: 30
|
|
73
|
+
|
|
74
|
+
# UI service on root path
|
|
75
|
+
- name: ui
|
|
76
|
+
port: 3000
|
|
77
|
+
path: /
|
|
78
|
+
domains:
|
|
79
|
+
- muacle.com
|
|
80
|
+
docker:
|
|
81
|
+
image: myapp/ui:latest
|
|
82
|
+
container: ui-container
|
|
83
|
+
port: 3000
|
|
84
|
+
healthCheck:
|
|
85
|
+
path: /
|
|
86
|
+
interval: 30
|
|
87
|
+
|
|
88
|
+
# ========================================
|
|
89
|
+
# Deployment Platform Configuration
|
|
90
|
+
# ========================================
|
|
91
|
+
# Nginx + Certbot Configuration
|
|
92
|
+
|
|
59
93
|
nginx:
|
|
60
94
|
configPath: /etc/nginx/sites-available
|
|
61
95
|
reloadCommand: sudo nginx -t && sudo systemctl reload nginx
|
package/suthep.yml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
project:
|
|
2
|
+
name: small-production-app
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
|
|
5
|
+
services:
|
|
6
|
+
# Simple API service for small production deployment
|
|
7
|
+
# - name: muacle-api-dev
|
|
8
|
+
# port: 3003
|
|
9
|
+
# path: /api
|
|
10
|
+
# domains:
|
|
11
|
+
# - dev.muacle.com
|
|
12
|
+
# docker:
|
|
13
|
+
# image: muacle-api:dev
|
|
14
|
+
# container: api-container-dev
|
|
15
|
+
# port: 3001
|
|
16
|
+
# healthCheck:
|
|
17
|
+
# path: /health
|
|
18
|
+
# interval: 30
|
|
19
|
+
# environment:
|
|
20
|
+
# NODE_ENV: production
|
|
21
|
+
|
|
22
|
+
# UI service on root path
|
|
23
|
+
- name: muacle-ui-dev
|
|
24
|
+
port: 3002
|
|
25
|
+
path: /
|
|
26
|
+
domains:
|
|
27
|
+
- localhost
|
|
28
|
+
docker:
|
|
29
|
+
image: frontend-api:latest
|
|
30
|
+
container: ui-container-dev
|
|
31
|
+
port: 3000
|
|
32
|
+
# healthCheck:
|
|
33
|
+
# path: /
|
|
34
|
+
# interval: 30
|
|
35
|
+
|
|
36
|
+
deployment:
|
|
37
|
+
strategy: rolling
|
|
38
|
+
healthCheckTimeout: 30000
|
|
39
|
+
|
package/test
ADDED
|
File without changes
|