suthep 0.1.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.
Files changed (65) hide show
  1. package/.editorconfig +17 -0
  2. package/.prettierignore +6 -0
  3. package/.prettierrc +7 -0
  4. package/.vscode/settings.json +19 -0
  5. package/LICENSE +21 -0
  6. package/README.md +217 -0
  7. package/dist/commands/deploy.js +318 -0
  8. package/dist/commands/deploy.js.map +1 -0
  9. package/dist/commands/init.js +188 -0
  10. package/dist/commands/init.js.map +1 -0
  11. package/dist/commands/setup.js +90 -0
  12. package/dist/commands/setup.js.map +1 -0
  13. package/dist/index.js +19 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/utils/certbot.js +64 -0
  16. package/dist/utils/certbot.js.map +1 -0
  17. package/dist/utils/config-loader.js +95 -0
  18. package/dist/utils/config-loader.js.map +1 -0
  19. package/dist/utils/deployment.js +76 -0
  20. package/dist/utils/deployment.js.map +1 -0
  21. package/dist/utils/docker.js +393 -0
  22. package/dist/utils/docker.js.map +1 -0
  23. package/dist/utils/nginx.js +303 -0
  24. package/dist/utils/nginx.js.map +1 -0
  25. package/docs/README.md +95 -0
  26. package/docs/TRANSLATIONS.md +211 -0
  27. package/docs/en/README.md +76 -0
  28. package/docs/en/api-reference.md +545 -0
  29. package/docs/en/architecture.md +369 -0
  30. package/docs/en/commands.md +273 -0
  31. package/docs/en/configuration.md +347 -0
  32. package/docs/en/developer-guide.md +588 -0
  33. package/docs/en/docker-ports-config.md +333 -0
  34. package/docs/en/examples.md +537 -0
  35. package/docs/en/getting-started.md +202 -0
  36. package/docs/en/port-binding.md +268 -0
  37. package/docs/en/troubleshooting.md +441 -0
  38. package/docs/th/README.md +64 -0
  39. package/docs/th/commands.md +202 -0
  40. package/docs/th/configuration.md +325 -0
  41. package/docs/th/getting-started.md +203 -0
  42. package/example/README.md +85 -0
  43. package/example/docker-compose.yml +76 -0
  44. package/example/docker-ports-example.yml +81 -0
  45. package/example/muacle.yml +47 -0
  46. package/example/port-binding-example.yml +45 -0
  47. package/example/suthep.yml +46 -0
  48. package/example/suthep=1.yml +46 -0
  49. package/package.json +45 -0
  50. package/src/commands/deploy.ts +405 -0
  51. package/src/commands/init.ts +214 -0
  52. package/src/commands/setup.ts +112 -0
  53. package/src/index.ts +42 -0
  54. package/src/types/config.ts +52 -0
  55. package/src/utils/certbot.ts +144 -0
  56. package/src/utils/config-loader.ts +121 -0
  57. package/src/utils/deployment.ts +157 -0
  58. package/src/utils/docker.ts +755 -0
  59. package/src/utils/nginx.ts +326 -0
  60. package/suthep-0.1.1.tgz +0 -0
  61. package/suthep.example.yml +98 -0
  62. package/test +0 -0
  63. package/todo.md +6 -0
  64. package/tsconfig.json +26 -0
  65. package/vite.config.ts +46 -0
@@ -0,0 +1,537 @@
1
+ # Examples
2
+
3
+ This document provides real-world examples of using Suthep for various deployment scenarios.
4
+
5
+ ## Example 1: Simple Node.js API
6
+
7
+ Deploy a basic Node.js Express API with health checks.
8
+
9
+ ### Service Code
10
+
11
+ ```javascript
12
+ // server.js
13
+ const express = require('express');
14
+ const app = express();
15
+
16
+ app.get('/health', (req, res) => {
17
+ res.json({ status: 'ok', timestamp: Date.now() });
18
+ });
19
+
20
+ app.get('/', (req, res) => {
21
+ res.json({ message: 'Hello from API!' });
22
+ });
23
+
24
+ app.listen(3000, () => {
25
+ console.log('API server running on port 3000');
26
+ });
27
+ ```
28
+
29
+ ### Configuration
30
+
31
+ ```yaml
32
+ project:
33
+ name: simple-api
34
+ version: 1.0.0
35
+
36
+ services:
37
+ - name: api
38
+ port: 3000
39
+ domains:
40
+ - api.example.com
41
+ healthCheck:
42
+ path: /health
43
+ interval: 30
44
+ environment:
45
+ NODE_ENV: production
46
+
47
+ nginx:
48
+ configPath: /etc/nginx/sites-available
49
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
50
+
51
+ certbot:
52
+ email: admin@example.com
53
+ staging: false
54
+
55
+ deployment:
56
+ strategy: rolling
57
+ healthCheckTimeout: 30000
58
+ ```
59
+
60
+ ### Deployment
61
+
62
+ ```bash
63
+ # Start your Node.js server
64
+ node server.js
65
+
66
+ # Deploy
67
+ suthep deploy
68
+ ```
69
+
70
+ ## Example 2: Docker Container Service
71
+
72
+ Deploy a web application running in a Docker container.
73
+
74
+ ### Configuration
75
+
76
+ ```yaml
77
+ project:
78
+ name: webapp
79
+ version: 1.0.0
80
+
81
+ services:
82
+ - name: webapp
83
+ port: 8080
84
+ docker:
85
+ image: nginx:alpine
86
+ container: webapp-container
87
+ port: 80
88
+ domains:
89
+ - example.com
90
+ - www.example.com
91
+ healthCheck:
92
+ path: /
93
+ interval: 30
94
+
95
+ nginx:
96
+ configPath: /etc/nginx/sites-available
97
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
98
+
99
+ certbot:
100
+ email: admin@example.com
101
+ staging: false
102
+
103
+ deployment:
104
+ strategy: rolling
105
+ healthCheckTimeout: 30000
106
+ ```
107
+
108
+ ### Deployment
109
+
110
+ ```bash
111
+ # Suthep will automatically pull and run the Docker image
112
+ suthep deploy
113
+ ```
114
+
115
+ ## Example 3: Multiple Services (Microservices)
116
+
117
+ Deploy a microservices architecture with multiple services.
118
+
119
+ ### Configuration
120
+
121
+ ```yaml
122
+ project:
123
+ name: microservices-app
124
+ version: 1.0.0
125
+
126
+ services:
127
+ # API Gateway
128
+ - name: gateway
129
+ port: 3000
130
+ domains:
131
+ - api.example.com
132
+ healthCheck:
133
+ path: /health
134
+ interval: 30
135
+ environment:
136
+ NODE_ENV: production
137
+
138
+ # User Service
139
+ - name: user-service
140
+ port: 3001
141
+ domains:
142
+ - users.example.com
143
+ healthCheck:
144
+ path: /health
145
+ interval: 30
146
+ environment:
147
+ NODE_ENV: production
148
+ DATABASE_URL: postgresql://localhost:5432/users
149
+
150
+ # Product Service
151
+ - name: product-service
152
+ port: 3002
153
+ domains:
154
+ - products.example.com
155
+ healthCheck:
156
+ path: /health
157
+ interval: 30
158
+ environment:
159
+ NODE_ENV: production
160
+ DATABASE_URL: postgresql://localhost:5432/products
161
+
162
+ # Frontend (Docker)
163
+ - name: frontend
164
+ port: 8080
165
+ docker:
166
+ image: myapp/frontend:latest
167
+ container: frontend-container
168
+ port: 80
169
+ domains:
170
+ - example.com
171
+ - www.example.com
172
+ healthCheck:
173
+ path: /
174
+ interval: 30
175
+
176
+ nginx:
177
+ configPath: /etc/nginx/sites-available
178
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
179
+
180
+ certbot:
181
+ email: admin@example.com
182
+ staging: false
183
+
184
+ deployment:
185
+ strategy: rolling
186
+ healthCheckTimeout: 30000
187
+ ```
188
+
189
+ ## Example 4: Connect to Existing Docker Container
190
+
191
+ Connect Suthep to an already running Docker container.
192
+
193
+ ### Configuration
194
+
195
+ ```yaml
196
+ project:
197
+ name: existing-container
198
+ version: 1.0.0
199
+
200
+ services:
201
+ - name: database-proxy
202
+ port: 5432
203
+ docker:
204
+ # No image specified - connects to existing container
205
+ container: postgres-container
206
+ port: 5432
207
+ domains:
208
+ - db.example.com
209
+
210
+ nginx:
211
+ configPath: /etc/nginx/sites-available
212
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
213
+
214
+ certbot:
215
+ email: admin@example.com
216
+ staging: false
217
+
218
+ deployment:
219
+ strategy: rolling
220
+ healthCheckTimeout: 30000
221
+ ```
222
+
223
+ ### Prerequisites
224
+
225
+ ```bash
226
+ # Start your container first
227
+ docker run -d --name postgres-container \
228
+ -p 5432:5432 \
229
+ -e POSTGRES_PASSWORD=secret \
230
+ postgres:latest
231
+ ```
232
+
233
+ ### Deployment
234
+
235
+ ```bash
236
+ suthep deploy
237
+ ```
238
+
239
+ ## Example 5: Development Environment with Staging Certificates
240
+
241
+ Use staging certificates for development/testing.
242
+
243
+ ### Configuration
244
+
245
+ ```yaml
246
+ project:
247
+ name: dev-app
248
+ version: 0.1.0
249
+
250
+ services:
251
+ - name: api
252
+ port: 3000
253
+ domains:
254
+ - api-dev.example.com
255
+ healthCheck:
256
+ path: /health
257
+ interval: 30
258
+
259
+ nginx:
260
+ configPath: /etc/nginx/sites-available
261
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
262
+
263
+ certbot:
264
+ email: dev@example.com
265
+ staging: true # Use staging environment
266
+
267
+ deployment:
268
+ strategy: rolling
269
+ healthCheckTimeout: 30000
270
+ ```
271
+
272
+ ## Example 6: HTTP Only (No HTTPS)
273
+
274
+ Deploy without SSL certificates (development only).
275
+
276
+ ### Configuration
277
+
278
+ ```yaml
279
+ project:
280
+ name: http-only
281
+ version: 1.0.0
282
+
283
+ services:
284
+ - name: api
285
+ port: 3000
286
+ domains:
287
+ - api.local
288
+ healthCheck:
289
+ path: /health
290
+ interval: 30
291
+
292
+ nginx:
293
+ configPath: /etc/nginx/sites-available
294
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
295
+
296
+ certbot:
297
+ email: admin@example.com
298
+ staging: false
299
+
300
+ deployment:
301
+ strategy: rolling
302
+ healthCheckTimeout: 30000
303
+ ```
304
+
305
+ ### Deployment
306
+
307
+ ```bash
308
+ # Skip HTTPS setup
309
+ suthep deploy --no-https
310
+ ```
311
+
312
+ ## Example 7: Docker with Environment Variables
313
+
314
+ Deploy a Docker container with custom environment variables.
315
+
316
+ ### Configuration
317
+
318
+ ```yaml
319
+ project:
320
+ name: env-app
321
+ version: 1.0.0
322
+
323
+ services:
324
+ - name: app
325
+ port: 8080
326
+ docker:
327
+ image: myapp/api:latest
328
+ container: app-container
329
+ port: 3000
330
+ domains:
331
+ - app.example.com
332
+ environment:
333
+ NODE_ENV: production
334
+ DATABASE_URL: postgresql://db:5432/mydb
335
+ REDIS_URL: redis://redis:6379
336
+ API_KEY: your-secret-key
337
+ LOG_LEVEL: info
338
+ healthCheck:
339
+ path: /health
340
+ interval: 30
341
+
342
+ nginx:
343
+ configPath: /etc/nginx/sites-available
344
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
345
+
346
+ certbot:
347
+ email: admin@example.com
348
+ staging: false
349
+
350
+ deployment:
351
+ strategy: rolling
352
+ healthCheckTimeout: 30000
353
+ ```
354
+
355
+ ## Example 8: Blue-Green Deployment
356
+
357
+ Use blue-green deployment strategy for zero-downtime.
358
+
359
+ ### Configuration
360
+
361
+ ```yaml
362
+ project:
363
+ name: blue-green-app
364
+ version: 1.0.0
365
+
366
+ services:
367
+ - name: api
368
+ port: 3000
369
+ domains:
370
+ - api.example.com
371
+ healthCheck:
372
+ path: /health
373
+ interval: 30
374
+
375
+ nginx:
376
+ configPath: /etc/nginx/sites-available
377
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
378
+
379
+ certbot:
380
+ email: admin@example.com
381
+ staging: false
382
+
383
+ deployment:
384
+ strategy: blue-green # Use blue-green strategy
385
+ healthCheckTimeout: 60000 # Longer timeout for blue-green
386
+
387
+ ```
388
+
389
+ ## Example 9: Custom Health Check Interval
390
+
391
+ Configure custom health check intervals for different services.
392
+
393
+ ### Configuration
394
+
395
+ ```yaml
396
+ project:
397
+ name: custom-health
398
+ version: 1.0.0
399
+
400
+ services:
401
+ # Fast health checks for critical service
402
+ - name: api
403
+ port: 3000
404
+ domains:
405
+ - api.example.com
406
+ healthCheck:
407
+ path: /health
408
+ interval: 10 # Check every 10 seconds
409
+
410
+ # Slower health checks for less critical service
411
+ - name: worker
412
+ port: 3001
413
+ domains:
414
+ - worker.example.com
415
+ healthCheck:
416
+ path: /health
417
+ interval: 60 # Check every 60 seconds
418
+
419
+ nginx:
420
+ configPath: /etc/nginx/sites-available
421
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
422
+
423
+ certbot:
424
+ email: admin@example.com
425
+ staging: false
426
+
427
+ deployment:
428
+ strategy: rolling
429
+ healthCheckTimeout: 30000
430
+ ```
431
+
432
+ ## Example 10: Multiple Domains per Service
433
+
434
+ Route multiple domains to a single service.
435
+
436
+ ### Configuration
437
+
438
+ ```yaml
439
+ project:
440
+ name: multi-domain
441
+ version: 1.0.0
442
+
443
+ services:
444
+ - name: app
445
+ port: 3000
446
+ domains:
447
+ - example.com
448
+ - www.example.com
449
+ - app.example.com
450
+ - myapp.com
451
+ - www.myapp.com
452
+ healthCheck:
453
+ path: /health
454
+ interval: 30
455
+
456
+ nginx:
457
+ configPath: /etc/nginx/sites-available
458
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
459
+
460
+ certbot:
461
+ email: admin@example.com
462
+ staging: false
463
+
464
+ deployment:
465
+ strategy: rolling
466
+ healthCheckTimeout: 30000
467
+ ```
468
+
469
+ ## Example 11: Full Stack Application
470
+
471
+ Deploy a complete full-stack application with frontend, backend, and database proxy.
472
+
473
+ ### Configuration
474
+
475
+ ```yaml
476
+ project:
477
+ name: fullstack-app
478
+ version: 1.0.0
479
+
480
+ services:
481
+ # React Frontend (Docker)
482
+ - name: frontend
483
+ port: 8080
484
+ docker:
485
+ image: myapp/frontend:latest
486
+ container: frontend-container
487
+ port: 80
488
+ domains:
489
+ - example.com
490
+ - www.example.com
491
+ healthCheck:
492
+ path: /
493
+ interval: 30
494
+
495
+ # Node.js Backend API
496
+ - name: backend
497
+ port: 3000
498
+ domains:
499
+ - api.example.com
500
+ healthCheck:
501
+ path: /api/health
502
+ interval: 30
503
+ environment:
504
+ NODE_ENV: production
505
+ DATABASE_URL: postgresql://localhost:5432/mydb
506
+
507
+ # Database Proxy (existing container)
508
+ - name: database
509
+ port: 5432
510
+ docker:
511
+ container: postgres-container
512
+ port: 5432
513
+ domains:
514
+ - db.example.com
515
+
516
+ nginx:
517
+ configPath: /etc/nginx/sites-available
518
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
519
+
520
+ certbot:
521
+ email: admin@example.com
522
+ staging: false
523
+
524
+ deployment:
525
+ strategy: rolling
526
+ healthCheckTimeout: 30000
527
+ ```
528
+
529
+ ## Tips for Real-World Deployments
530
+
531
+ 1. **Start with staging certificates**: Use `certbot.staging: true` during development
532
+ 2. **Test health checks**: Ensure your health endpoints return 200 OK
533
+ 3. **Monitor logs**: Check Nginx and application logs after deployment
534
+ 4. **DNS configuration**: Ensure all domains point to your server's IP
535
+ 5. **Firewall rules**: Open ports 80 and 443 for HTTP/HTTPS
536
+ 6. **Backup configurations**: Keep backups of your `suthep.yml` file
537
+ 7. **Version control**: Commit your configuration files to version control
@@ -0,0 +1,202 @@
1
+ # Getting Started with Suthep
2
+
3
+ This guide will walk you through installing Suthep and deploying your first service.
4
+
5
+ ## Installation
6
+
7
+ ### Prerequisites
8
+
9
+ Before installing Suthep, ensure you have:
10
+
11
+ - **Node.js 16+** - [Download Node.js](https://nodejs.org/)
12
+ - **sudo access** - Required for Nginx and Certbot operations
13
+ - **Docker** (optional) - Only needed if deploying Docker containers
14
+
15
+ ### Install Suthep
16
+
17
+ 1. Clone or download the Suthep repository:
18
+ ```bash
19
+ git clone <repository-url>
20
+ cd suthep
21
+ ```
22
+
23
+ 2. Install dependencies:
24
+ ```bash
25
+ npm install
26
+ ```
27
+
28
+ 3. Link the CLI tool globally:
29
+ ```bash
30
+ npm link
31
+ ```
32
+
33
+ This makes the `suthep` command available globally on your system.
34
+
35
+ 4. Verify installation:
36
+ ```bash
37
+ suthep --version
38
+ ```
39
+
40
+ ## Quick Start Guide
41
+
42
+ ### Step 1: Initialize Configuration
43
+
44
+ Create a configuration file for your project:
45
+
46
+ ```bash
47
+ suthep init
48
+ ```
49
+
50
+ This interactive command will:
51
+ - Ask for your project name and version
52
+ - Guide you through configuring services
53
+ - Set up domain names
54
+ - Configure Docker (if needed)
55
+ - Set up health checks
56
+ - Configure Certbot email
57
+
58
+ Alternatively, you can copy the example configuration:
59
+
60
+ ```bash
61
+ cp suthep.example.yml suthep.yml
62
+ # Edit suthep.yml with your settings
63
+ ```
64
+
65
+ ### Step 2: Setup Prerequisites
66
+
67
+ Install and configure Nginx and Certbot:
68
+
69
+ ```bash
70
+ suthep setup
71
+ ```
72
+
73
+ This command will:
74
+ - Install Nginx (if not already installed)
75
+ - Install Certbot (if not already installed)
76
+ - Start and enable the Nginx service
77
+
78
+ You can also install them separately:
79
+
80
+ ```bash
81
+ suthep setup --nginx-only # Only install Nginx
82
+ suthep setup --certbot-only # Only install Certbot
83
+ ```
84
+
85
+ ### Step 3: Deploy Your Services
86
+
87
+ Deploy your project:
88
+
89
+ ```bash
90
+ suthep deploy
91
+ ```
92
+
93
+ This will:
94
+ 1. Load your configuration from `suthep.yml`
95
+ 2. Start Docker containers (if configured)
96
+ 3. Deploy each service
97
+ 4. Generate and enable Nginx configurations
98
+ 5. Request SSL certificates from Let's Encrypt
99
+ 6. Reload Nginx
100
+ 7. Perform health checks
101
+
102
+ ## Your First Deployment
103
+
104
+ Let's deploy a simple Node.js API service:
105
+
106
+ ### 1. Create a Simple Service
107
+
108
+ Create a basic Node.js server:
109
+
110
+ ```javascript
111
+ // server.js
112
+ const http = require('http');
113
+
114
+ const server = http.createServer((req, res) => {
115
+ if (req.url === '/health') {
116
+ res.writeHead(200, { 'Content-Type': 'application/json' });
117
+ res.end(JSON.stringify({ status: 'ok' }));
118
+ } else {
119
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
120
+ res.end('Hello from Suthep!');
121
+ }
122
+ });
123
+
124
+ server.listen(3000, () => {
125
+ console.log('Server running on port 3000');
126
+ });
127
+ ```
128
+
129
+ ### 2. Create Configuration
130
+
131
+ Create `suthep.yml`:
132
+
133
+ ```yaml
134
+ project:
135
+ name: my-first-app
136
+ version: 1.0.0
137
+
138
+ services:
139
+ - name: api
140
+ port: 3000
141
+ domains:
142
+ - api.yourdomain.com
143
+ healthCheck:
144
+ path: /health
145
+ interval: 30
146
+
147
+ nginx:
148
+ configPath: /etc/nginx/sites-available
149
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
150
+
151
+ certbot:
152
+ email: your-email@example.com
153
+ staging: false
154
+
155
+ deployment:
156
+ strategy: rolling
157
+ healthCheckTimeout: 30000
158
+ ```
159
+
160
+ ### 3. Start Your Service
161
+
162
+ Run your Node.js server:
163
+
164
+ ```bash
165
+ node server.js
166
+ ```
167
+
168
+ ### 4. Setup and Deploy
169
+
170
+ ```bash
171
+ # Setup Nginx and Certbot
172
+ suthep setup
173
+
174
+ # Deploy
175
+ suthep deploy
176
+ ```
177
+
178
+ ### 5. Verify
179
+
180
+ Visit `https://api.yourdomain.com` in your browser. You should see "Hello from Suthep!" and the SSL certificate should be valid.
181
+
182
+ ## Next Steps
183
+
184
+ - Read the [Configuration Reference](./configuration.md) to learn about all configuration options
185
+ - Check out [Examples](./examples.md) for more complex deployment scenarios
186
+ - Review [Commands Reference](./commands.md) for detailed command documentation
187
+
188
+ ## Common Issues
189
+
190
+ If you encounter issues during setup:
191
+
192
+ 1. **Permission denied**: Ensure you have sudo access
193
+ 2. **Nginx not found**: Run `suthep setup` to install it
194
+ 3. **Domain not resolving**: Make sure your domain DNS points to your server's IP
195
+ 4. **SSL certificate failed**: Check that your domain is publicly accessible and port 80 is open
196
+
197
+ For more troubleshooting help, see the [Troubleshooting Guide](./troubleshooting.md).
198
+
199
+ ## Other Languages / ภาษาอื่นๆ
200
+
201
+ - [English](./getting-started.md) - English version (current)
202
+ - [ไทย](../th/getting-started.md) - Thai version / เวอร์ชันภาษาไทย