suthep 1.0.0
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/.editorconfig +17 -0
- package/.github/workflows/publish.yml +42 -0
- package/.prettierignore +6 -0
- package/.prettierrc +7 -0
- package/.scannerwork/.sonar_lock +0 -0
- package/.scannerwork/report-task.txt +6 -0
- package/.vscode/settings.json +19 -0
- package/LICENSE +21 -0
- package/README.md +317 -0
- package/dist/commands/deploy.js +371 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/down.js +179 -0
- package/dist/commands/down.js.map +1 -0
- package/dist/commands/init.js +188 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/setup.js +90 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/up.js +213 -0
- package/dist/commands/up.js.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/certbot.js +64 -0
- package/dist/utils/certbot.js.map +1 -0
- package/dist/utils/config-loader.js +127 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/deployment.js +85 -0
- package/dist/utils/deployment.js.map +1 -0
- package/dist/utils/docker.js +425 -0
- package/dist/utils/docker.js.map +1 -0
- package/dist/utils/env-loader.js +53 -0
- package/dist/utils/env-loader.js.map +1 -0
- package/dist/utils/nginx.js +378 -0
- package/dist/utils/nginx.js.map +1 -0
- package/docs/README.md +38 -0
- package/docs/english/01-introduction.md +84 -0
- package/docs/english/02-installation.md +200 -0
- package/docs/english/03-quick-start.md +258 -0
- package/docs/english/04-configuration.md +433 -0
- package/docs/english/05-commands.md +336 -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 +258 -0
- package/docs/thai/04-configuration.md +433 -0
- package/docs/thai/05-commands.md +336 -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/suthep-complete.yml +103 -0
- package/example/suthep-docker-only.yml +71 -0
- package/example/suthep-env-example.yml +113 -0
- package/example/suthep-no-docker.yml +51 -0
- package/example/suthep-path-routing.yml +62 -0
- package/example/suthep.example.yml +88 -0
- package/package.json +51 -0
- package/src/commands/deploy.ts +488 -0
- package/src/commands/down.ts +240 -0
- package/src/commands/init.ts +214 -0
- package/src/commands/setup.ts +112 -0
- package/src/commands/up.ts +271 -0
- package/src/index.ts +109 -0
- package/src/types/config.ts +52 -0
- package/src/utils/__tests__/certbot.test.ts +222 -0
- package/src/utils/__tests__/config-loader.test.ts +419 -0
- package/src/utils/__tests__/deployment.test.ts +243 -0
- package/src/utils/__tests__/nginx.test.ts +412 -0
- package/src/utils/certbot.ts +144 -0
- package/src/utils/config-loader.ts +184 -0
- package/src/utils/deployment.ts +157 -0
- package/src/utils/docker.ts +768 -0
- package/src/utils/env-loader.ts +135 -0
- package/src/utils/nginx.ts +443 -0
- package/suthep-1.0.0.tgz +0 -0
- package/suthep.example.yml +98 -0
- package/suthep.yml +39 -0
- package/todo.md +6 -0
- package/tsconfig.json +26 -0
- package/vite.config.ts +46 -0
- package/vitest.config.ts +21 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
# Configuration Guide
|
|
2
|
+
|
|
3
|
+
This guide covers all configuration options available in Suthep's `suthep.yml` file.
|
|
4
|
+
|
|
5
|
+
## Configuration File Structure
|
|
6
|
+
|
|
7
|
+
The `suthep.yml` file uses YAML format and consists of several sections:
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
project:
|
|
11
|
+
# Project metadata
|
|
12
|
+
|
|
13
|
+
services:
|
|
14
|
+
# Service definitions
|
|
15
|
+
|
|
16
|
+
nginx:
|
|
17
|
+
# Nginx configuration
|
|
18
|
+
|
|
19
|
+
certbot:
|
|
20
|
+
# SSL certificate configuration
|
|
21
|
+
|
|
22
|
+
deployment:
|
|
23
|
+
# Deployment strategy settings
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Project Configuration
|
|
27
|
+
|
|
28
|
+
The `project` section contains metadata about your project:
|
|
29
|
+
|
|
30
|
+
```yaml
|
|
31
|
+
project:
|
|
32
|
+
name: my-app # Project name
|
|
33
|
+
version: 1.0.0 # Project version
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Fields
|
|
37
|
+
|
|
38
|
+
| Field | Required | Description |
|
|
39
|
+
|-------|----------|-------------|
|
|
40
|
+
| `name` | Yes | Unique identifier for your project |
|
|
41
|
+
| `version` | Yes | Project version (for tracking) |
|
|
42
|
+
|
|
43
|
+
## Services Configuration
|
|
44
|
+
|
|
45
|
+
The `services` array defines all services to deploy. Each service can have multiple configurations.
|
|
46
|
+
|
|
47
|
+
### Basic Service
|
|
48
|
+
|
|
49
|
+
```yaml
|
|
50
|
+
services:
|
|
51
|
+
- name: api
|
|
52
|
+
port: 3000
|
|
53
|
+
domains:
|
|
54
|
+
- api.example.com
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Service Fields
|
|
58
|
+
|
|
59
|
+
| Field | Required | Type | Description |
|
|
60
|
+
|-------|----------|------|-------------|
|
|
61
|
+
| `name` | Yes | string | Unique service identifier |
|
|
62
|
+
| `port` | Yes | number | Port number the service runs on (host port) |
|
|
63
|
+
| `domains` | Yes | array | Array of domain names for this service |
|
|
64
|
+
| `path` | No | string | URL path prefix (default: `/`) |
|
|
65
|
+
| `docker` | No | object | Docker configuration (see below) |
|
|
66
|
+
| `healthCheck` | No | object | Health check configuration (see below) |
|
|
67
|
+
| `environment` | No | object | Environment variables as key-value pairs |
|
|
68
|
+
|
|
69
|
+
### Docker Configuration
|
|
70
|
+
|
|
71
|
+
Configure Docker container deployment:
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
services:
|
|
75
|
+
- name: webapp
|
|
76
|
+
port: 8080
|
|
77
|
+
docker:
|
|
78
|
+
image: nginx:latest # Docker image to pull
|
|
79
|
+
container: webapp-container # Container name
|
|
80
|
+
port: 80 # Container internal port
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Docker Fields
|
|
84
|
+
|
|
85
|
+
| Field | Required | Description |
|
|
86
|
+
|-------|----------|-------------|
|
|
87
|
+
| `image` | No* | Docker image to pull and run |
|
|
88
|
+
| `container` | Yes | Name for the Docker container |
|
|
89
|
+
| `port` | Yes | Internal port the container listens on |
|
|
90
|
+
|
|
91
|
+
\* `image` is optional if connecting to an existing container.
|
|
92
|
+
|
|
93
|
+
#### Connect to Existing Container
|
|
94
|
+
|
|
95
|
+
To connect to an already running container, omit the `image` field:
|
|
96
|
+
|
|
97
|
+
```yaml
|
|
98
|
+
services:
|
|
99
|
+
- name: database-proxy
|
|
100
|
+
port: 5432
|
|
101
|
+
docker:
|
|
102
|
+
container: postgres-container
|
|
103
|
+
port: 5432
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Health Check Configuration
|
|
107
|
+
|
|
108
|
+
Configure health monitoring for your service:
|
|
109
|
+
|
|
110
|
+
```yaml
|
|
111
|
+
services:
|
|
112
|
+
- name: api
|
|
113
|
+
healthCheck:
|
|
114
|
+
path: /health # Health check endpoint
|
|
115
|
+
interval: 30 # Check interval in seconds
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Health Check Fields
|
|
119
|
+
|
|
120
|
+
| Field | Required | Default | Description |
|
|
121
|
+
|-------|----------|---------|-------------|
|
|
122
|
+
| `path` | Yes | - | HTTP endpoint path for health checks |
|
|
123
|
+
| `interval` | No | 30 | Time between health checks (seconds) |
|
|
124
|
+
|
|
125
|
+
### Environment Variables
|
|
126
|
+
|
|
127
|
+
Set environment variables for your service:
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
services:
|
|
131
|
+
- name: api
|
|
132
|
+
environment:
|
|
133
|
+
NODE_ENV: production
|
|
134
|
+
DATABASE_URL: postgresql://localhost:5432/mydb
|
|
135
|
+
API_KEY: your-api-key
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Environment Variable Substitution
|
|
139
|
+
|
|
140
|
+
Suthep supports environment variable substitution in configuration files using `${VAR_NAME}` syntax. You can also use `.env` files to store sensitive values.
|
|
141
|
+
|
|
142
|
+
**Using .env Files:**
|
|
143
|
+
|
|
144
|
+
Suthep automatically loads `.env` files from the same directory as your configuration file. It searches for files in this order (later files override earlier ones):
|
|
145
|
+
|
|
146
|
+
1. `.env.local` (highest priority, should be gitignored)
|
|
147
|
+
2. `.env`
|
|
148
|
+
|
|
149
|
+
Example `.env` file:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# .env
|
|
153
|
+
DATABASE_URL=postgresql://localhost:5432/mydb
|
|
154
|
+
API_KEY=secret-key-123
|
|
155
|
+
DOMAIN=example.com
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Variable Substitution Syntax:**
|
|
159
|
+
|
|
160
|
+
You can use environment variables in your configuration file with the following syntax:
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
services:
|
|
164
|
+
- name: api
|
|
165
|
+
port: 3000
|
|
166
|
+
domains:
|
|
167
|
+
- ${DOMAIN}
|
|
168
|
+
- api.${DOMAIN}
|
|
169
|
+
environment:
|
|
170
|
+
DATABASE_URL: ${DATABASE_URL}
|
|
171
|
+
API_KEY: ${API_KEY}
|
|
172
|
+
NODE_ENV: ${NODE_ENV:-production} # With default value
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Supported Syntax:**
|
|
176
|
+
|
|
177
|
+
- `${VAR_NAME}` - Replaced with the value of `VAR_NAME` from `.env` files or `process.env`
|
|
178
|
+
- `${VAR_NAME:-default}` - Uses `default` if `VAR_NAME` is not set
|
|
179
|
+
- Variables are substituted recursively throughout the configuration
|
|
180
|
+
|
|
181
|
+
**Priority Order:**
|
|
182
|
+
|
|
183
|
+
Environment variables are resolved in this order (highest to lowest priority):
|
|
184
|
+
|
|
185
|
+
1. CLI environment variables (via `-e` or `--env` flag)
|
|
186
|
+
2. Service-specific environment variables (from `environment` section)
|
|
187
|
+
3. Variables from `.env` files
|
|
188
|
+
4. System environment variables (`process.env`)
|
|
189
|
+
|
|
190
|
+
**Example:**
|
|
191
|
+
|
|
192
|
+
```yaml
|
|
193
|
+
# suthep.yml
|
|
194
|
+
services:
|
|
195
|
+
- name: api
|
|
196
|
+
port: ${API_PORT:-3000}
|
|
197
|
+
domains:
|
|
198
|
+
- ${API_DOMAIN:-api.example.com}
|
|
199
|
+
environment:
|
|
200
|
+
NODE_ENV: ${NODE_ENV:-production}
|
|
201
|
+
DATABASE_URL: ${DATABASE_URL}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# .env
|
|
206
|
+
API_PORT=3001
|
|
207
|
+
API_DOMAIN=api.myapp.com
|
|
208
|
+
DATABASE_URL=postgresql://localhost:5432/mydb
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Note:** Always add `.env.local` to your `.gitignore` file to keep sensitive values secure.
|
|
212
|
+
|
|
213
|
+
### Path-Based Routing
|
|
214
|
+
|
|
215
|
+
Route different services on the same domain using paths:
|
|
216
|
+
|
|
217
|
+
```yaml
|
|
218
|
+
services:
|
|
219
|
+
# API service on /api path
|
|
220
|
+
- name: api
|
|
221
|
+
port: 3001
|
|
222
|
+
path: /api
|
|
223
|
+
domains:
|
|
224
|
+
- example.com
|
|
225
|
+
|
|
226
|
+
# UI service on root path
|
|
227
|
+
- name: ui
|
|
228
|
+
port: 3000
|
|
229
|
+
path: /
|
|
230
|
+
domains:
|
|
231
|
+
- example.com
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Nginx Configuration
|
|
235
|
+
|
|
236
|
+
Configure Nginx settings:
|
|
237
|
+
|
|
238
|
+
```yaml
|
|
239
|
+
nginx:
|
|
240
|
+
configPath: /etc/nginx/sites-available
|
|
241
|
+
reloadCommand: sudo nginx -t && sudo systemctl reload nginx
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Nginx Fields
|
|
245
|
+
|
|
246
|
+
| Field | Required | Default | Description |
|
|
247
|
+
|-------|----------|---------|-------------|
|
|
248
|
+
| `configPath` | No | `/etc/nginx/sites-available` | Path where Nginx configs are stored |
|
|
249
|
+
| `reloadCommand` | No | `sudo nginx -t && sudo systemctl reload nginx` | Command to reload Nginx |
|
|
250
|
+
|
|
251
|
+
## Certbot Configuration
|
|
252
|
+
|
|
253
|
+
Configure SSL certificate settings:
|
|
254
|
+
|
|
255
|
+
```yaml
|
|
256
|
+
certbot:
|
|
257
|
+
email: admin@example.com # Email for Let's Encrypt
|
|
258
|
+
staging: false # Use staging environment (for testing)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Certbot Fields
|
|
262
|
+
|
|
263
|
+
| Field | Required | Description |
|
|
264
|
+
|-------|----------|-------------|
|
|
265
|
+
| `email` | Yes | Email address for Let's Encrypt notifications |
|
|
266
|
+
| `staging` | No | Use staging environment (default: `false`) |
|
|
267
|
+
|
|
268
|
+
**Note:** Use `staging: true` for testing to avoid rate limits.
|
|
269
|
+
|
|
270
|
+
## Deployment Configuration
|
|
271
|
+
|
|
272
|
+
Configure deployment strategy:
|
|
273
|
+
|
|
274
|
+
```yaml
|
|
275
|
+
deployment:
|
|
276
|
+
strategy: rolling # Deployment strategy
|
|
277
|
+
healthCheckTimeout: 30000 # Health check timeout (ms)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Deployment Fields
|
|
281
|
+
|
|
282
|
+
| Field | Required | Default | Description |
|
|
283
|
+
|-------|----------|---------|-------------|
|
|
284
|
+
| `strategy` | No | `rolling` | Deployment strategy (`rolling` or `blue-green`) |
|
|
285
|
+
| `healthCheckTimeout` | No | `30000` | Maximum time to wait for health check (milliseconds) |
|
|
286
|
+
|
|
287
|
+
### Deployment Strategies
|
|
288
|
+
|
|
289
|
+
#### Rolling Deployment
|
|
290
|
+
|
|
291
|
+
Gradually replaces old containers with new ones:
|
|
292
|
+
|
|
293
|
+
```yaml
|
|
294
|
+
deployment:
|
|
295
|
+
strategy: rolling
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
#### Blue-Green Deployment
|
|
299
|
+
|
|
300
|
+
Creates new containers, switches traffic, then removes old containers:
|
|
301
|
+
|
|
302
|
+
```yaml
|
|
303
|
+
deployment:
|
|
304
|
+
strategy: blue-green
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Complete Configuration Example
|
|
308
|
+
|
|
309
|
+
Here's a complete example with all options:
|
|
310
|
+
|
|
311
|
+
```yaml
|
|
312
|
+
project:
|
|
313
|
+
name: my-app
|
|
314
|
+
version: 1.0.0
|
|
315
|
+
|
|
316
|
+
services:
|
|
317
|
+
# Simple API service
|
|
318
|
+
- name: api
|
|
319
|
+
port: 3000
|
|
320
|
+
domains:
|
|
321
|
+
- api.example.com
|
|
322
|
+
healthCheck:
|
|
323
|
+
path: /health
|
|
324
|
+
interval: 30
|
|
325
|
+
environment:
|
|
326
|
+
NODE_ENV: production
|
|
327
|
+
|
|
328
|
+
# Docker webapp
|
|
329
|
+
- name: webapp
|
|
330
|
+
port: 8080
|
|
331
|
+
docker:
|
|
332
|
+
image: nginx:latest
|
|
333
|
+
container: webapp-container
|
|
334
|
+
port: 80
|
|
335
|
+
domains:
|
|
336
|
+
- example.com
|
|
337
|
+
- www.example.com
|
|
338
|
+
healthCheck:
|
|
339
|
+
path: /
|
|
340
|
+
interval: 30
|
|
341
|
+
|
|
342
|
+
# Multiple services on same domain
|
|
343
|
+
- name: api-v2
|
|
344
|
+
port: 3001
|
|
345
|
+
path: /api
|
|
346
|
+
domains:
|
|
347
|
+
- example.com
|
|
348
|
+
docker:
|
|
349
|
+
image: myapp/api:latest
|
|
350
|
+
container: api-v2-container
|
|
351
|
+
port: 3001
|
|
352
|
+
|
|
353
|
+
nginx:
|
|
354
|
+
configPath: /etc/nginx/sites-available
|
|
355
|
+
reloadCommand: sudo nginx -t && sudo systemctl reload nginx
|
|
356
|
+
|
|
357
|
+
certbot:
|
|
358
|
+
email: admin@example.com
|
|
359
|
+
staging: false
|
|
360
|
+
|
|
361
|
+
deployment:
|
|
362
|
+
strategy: rolling
|
|
363
|
+
healthCheckTimeout: 30000
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## Configuration Best Practices
|
|
367
|
+
|
|
368
|
+
### 1. Use Descriptive Service Names
|
|
369
|
+
|
|
370
|
+
```yaml
|
|
371
|
+
# Good
|
|
372
|
+
- name: user-api
|
|
373
|
+
- name: payment-service
|
|
374
|
+
|
|
375
|
+
# Avoid
|
|
376
|
+
- name: service1
|
|
377
|
+
- name: app
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### 2. Set Appropriate Health Check Intervals
|
|
381
|
+
|
|
382
|
+
```yaml
|
|
383
|
+
# For critical services
|
|
384
|
+
healthCheck:
|
|
385
|
+
interval: 15 # Check every 15 seconds
|
|
386
|
+
|
|
387
|
+
# For less critical services
|
|
388
|
+
healthCheck:
|
|
389
|
+
interval: 60 # Check every minute
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### 3. Use Staging for Testing
|
|
393
|
+
|
|
394
|
+
```yaml
|
|
395
|
+
certbot:
|
|
396
|
+
staging: true # Use staging for testing
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### 4. Organize Services by Domain
|
|
400
|
+
|
|
401
|
+
Group related services together in your configuration:
|
|
402
|
+
|
|
403
|
+
```yaml
|
|
404
|
+
services:
|
|
405
|
+
# API services
|
|
406
|
+
- name: api
|
|
407
|
+
domains: [api.example.com]
|
|
408
|
+
- name: api-v2
|
|
409
|
+
domains: [api-v2.example.com]
|
|
410
|
+
|
|
411
|
+
# Web services
|
|
412
|
+
- name: webapp
|
|
413
|
+
domains: [example.com, www.example.com]
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## Validation
|
|
417
|
+
|
|
418
|
+
Suthep validates your configuration before deployment. Common validation errors:
|
|
419
|
+
|
|
420
|
+
- **Missing required fields** - Ensure all required fields are present
|
|
421
|
+
- **Invalid port numbers** - Ports must be between 1 and 65535
|
|
422
|
+
- **Duplicate service names** - Each service must have a unique name
|
|
423
|
+
- **Invalid domain format** - Domains must be valid hostnames
|
|
424
|
+
|
|
425
|
+
## Next Steps
|
|
426
|
+
|
|
427
|
+
- [Commands Reference](./05-commands.md) - Learn about all available commands
|
|
428
|
+
- [Examples](./06-examples.md) - See real-world configuration examples
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
**Previous:** [Quick Start](./03-quick-start.md) | **Next:** [Commands Reference →](./05-commands.md)
|
|
433
|
+
|