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.
Files changed (72) hide show
  1. package/README.md +172 -71
  2. package/dist/commands/deploy.js +251 -37
  3. package/dist/commands/deploy.js.map +1 -1
  4. package/dist/commands/down.js +179 -0
  5. package/dist/commands/down.js.map +1 -0
  6. package/dist/commands/redeploy.js +59 -0
  7. package/dist/commands/redeploy.js.map +1 -0
  8. package/dist/commands/up.js +213 -0
  9. package/dist/commands/up.js.map +1 -0
  10. package/dist/index.js +36 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/utils/certbot.js +40 -3
  13. package/dist/utils/certbot.js.map +1 -1
  14. package/dist/utils/config-loader.js +30 -0
  15. package/dist/utils/config-loader.js.map +1 -1
  16. package/dist/utils/deployment.js +49 -16
  17. package/dist/utils/deployment.js.map +1 -1
  18. package/dist/utils/docker.js +396 -25
  19. package/dist/utils/docker.js.map +1 -1
  20. package/dist/utils/nginx.js +167 -8
  21. package/dist/utils/nginx.js.map +1 -1
  22. package/docs/README.md +25 -49
  23. package/docs/english/01-introduction.md +84 -0
  24. package/docs/english/02-installation.md +200 -0
  25. package/docs/english/03-quick-start.md +256 -0
  26. package/docs/english/04-configuration.md +358 -0
  27. package/docs/english/05-commands.md +363 -0
  28. package/docs/english/06-examples.md +456 -0
  29. package/docs/english/07-troubleshooting.md +417 -0
  30. package/docs/english/08-advanced.md +411 -0
  31. package/docs/english/README.md +48 -0
  32. package/docs/thai/01-introduction.md +84 -0
  33. package/docs/thai/02-installation.md +200 -0
  34. package/docs/thai/03-quick-start.md +256 -0
  35. package/docs/thai/04-configuration.md +358 -0
  36. package/docs/thai/05-commands.md +363 -0
  37. package/docs/thai/06-examples.md +456 -0
  38. package/docs/thai/07-troubleshooting.md +417 -0
  39. package/docs/thai/08-advanced.md +411 -0
  40. package/docs/thai/README.md +48 -0
  41. package/example/README.md +286 -53
  42. package/example/suthep-complete.yml +103 -0
  43. package/example/suthep-docker-only.yml +71 -0
  44. package/example/suthep-no-docker.yml +51 -0
  45. package/example/suthep-path-routing.yml +62 -0
  46. package/example/suthep.example.yml +89 -0
  47. package/package.json +1 -1
  48. package/src/commands/deploy.ts +322 -50
  49. package/src/commands/down.ts +240 -0
  50. package/src/commands/redeploy.ts +78 -0
  51. package/src/commands/up.ts +271 -0
  52. package/src/index.ts +62 -1
  53. package/src/types/config.ts +25 -24
  54. package/src/utils/certbot.ts +68 -6
  55. package/src/utils/config-loader.ts +40 -0
  56. package/src/utils/deployment.ts +61 -36
  57. package/src/utils/docker.ts +634 -30
  58. package/src/utils/nginx.ts +187 -4
  59. package/suthep-0.1.0-beta.1.tgz +0 -0
  60. package/suthep-0.1.1.tgz +0 -0
  61. package/suthep.example.yml +34 -0
  62. package/suthep.yml +39 -0
  63. package/test +0 -0
  64. package/docs/api-reference.md +0 -545
  65. package/docs/architecture.md +0 -367
  66. package/docs/commands.md +0 -273
  67. package/docs/configuration.md +0 -347
  68. package/docs/examples.md +0 -537
  69. package/docs/getting-started.md +0 -197
  70. package/docs/troubleshooting.md +0 -441
  71. package/example/docker-compose.yml +0 -72
  72. package/example/suthep.yml +0 -31
@@ -0,0 +1,456 @@
1
+ # ตัวอย่าง
2
+
3
+ คู่มือนี้ให้ตัวอย่างในโลกจริงของการ deploy ประเภทบริการต่างๆ ด้วย Suthep
4
+
5
+ ## ตัวอย่างที่ 1: Node.js API แบบง่าย
6
+
7
+ Deploy บริการ API Node.js พร้อม health checks
8
+
9
+ ### การตั้งค่า
10
+
11
+ ```yaml
12
+ project:
13
+ name: my-api
14
+ version: 1.0.0
15
+
16
+ services:
17
+ - name: api
18
+ port: 3000
19
+ domains:
20
+ - api.example.com
21
+ healthCheck:
22
+ path: /health
23
+ interval: 30
24
+ environment:
25
+ NODE_ENV: production
26
+ PORT: 3000
27
+
28
+ nginx:
29
+ configPath: /etc/nginx/sites-available
30
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
31
+
32
+ certbot:
33
+ email: admin@example.com
34
+ staging: false
35
+
36
+ deployment:
37
+ strategy: rolling
38
+ healthCheckTimeout: 30000
39
+ ```
40
+
41
+ ### การ Deploy
42
+
43
+ ```bash
44
+ suthep setup
45
+ suthep deploy
46
+ ```
47
+
48
+ ### ผลลัพธ์
49
+
50
+ - บริการพร้อมใช้งานที่ `https://api.example.com`
51
+ - Health checks ทำงานทุก 30 วินาที
52
+ - ใบรับรอง SSL อัตโนมัติจาก Let's Encrypt
53
+
54
+ ## ตัวอย่างที่ 2: เว็บแอปพลิเคชัน Docker
55
+
56
+ Deploy เว็บแอปพลิเคชันโดยใช้ Docker container
57
+
58
+ ### การตั้งค่า
59
+
60
+ ```yaml
61
+ project:
62
+ name: webapp
63
+ version: 1.0.0
64
+
65
+ services:
66
+ - name: webapp
67
+ port: 8080
68
+ docker:
69
+ image: nginx:latest
70
+ container: webapp-container
71
+ port: 80
72
+ domains:
73
+ - example.com
74
+ - www.example.com
75
+ healthCheck:
76
+ path: /
77
+ interval: 30
78
+
79
+ nginx:
80
+ configPath: /etc/nginx/sites-available
81
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
82
+
83
+ certbot:
84
+ email: admin@example.com
85
+ staging: false
86
+
87
+ deployment:
88
+ strategy: rolling
89
+ healthCheckTimeout: 30000
90
+ ```
91
+
92
+ ### การ Deploy
93
+
94
+ ```bash
95
+ suthep deploy
96
+ ```
97
+
98
+ ### ผลลัพธ์
99
+
100
+ - Docker container กำลังรันบนพอร์ต 8080
101
+ - บริการพร้อมใช้งานที่ `https://example.com` และ `https://www.example.com`
102
+ - การจัดการ container อัตโนมัติ
103
+
104
+ ## ตัวอย่างที่ 3: หลายบริการบนโดเมนเดียวกัน
105
+
106
+ กำหนดเส้นทางหลายบริการบนโดเมนเดียวกันโดยใช้ path-based routing
107
+
108
+ ### การตั้งค่า
109
+
110
+ ```yaml
111
+ project:
112
+ name: fullstack-app
113
+ version: 1.0.0
114
+
115
+ services:
116
+ # บริการ API บน path /api
117
+ - name: api
118
+ port: 3001
119
+ path: /api
120
+ domains:
121
+ - example.com
122
+ docker:
123
+ image: myapp/api:latest
124
+ container: api-container
125
+ port: 3001
126
+ healthCheck:
127
+ path: /api/health
128
+ interval: 30
129
+
130
+ # บริการ UI บน root path
131
+ - name: ui
132
+ port: 3000
133
+ path: /
134
+ domains:
135
+ - example.com
136
+ docker:
137
+ image: myapp/ui:latest
138
+ container: ui-container
139
+ port: 3000
140
+ healthCheck:
141
+ path: /
142
+ interval: 30
143
+
144
+ nginx:
145
+ configPath: /etc/nginx/sites-available
146
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
147
+
148
+ certbot:
149
+ email: admin@example.com
150
+ staging: false
151
+
152
+ deployment:
153
+ strategy: rolling
154
+ healthCheckTimeout: 30000
155
+ ```
156
+
157
+ ### การ Deploy
158
+
159
+ ```bash
160
+ suthep deploy
161
+ ```
162
+
163
+ ### ผลลัพธ์
164
+
165
+ - API พร้อมใช้งานที่ `https://example.com/api`
166
+ - UI พร้อมใช้งานที่ `https://example.com`
167
+ - ทั้งสองบริการใช้โดเมนเดียวกัน
168
+
169
+ ## ตัวอย่างที่ 4: หลายโดเมนสำหรับบริการเดียว
170
+
171
+ กำหนดเส้นทางหลายโดเมนไปยังบริการเดียวกัน
172
+
173
+ ### การตั้งค่า
174
+
175
+ ```yaml
176
+ project:
177
+ name: dashboard
178
+ version: 1.0.0
179
+
180
+ services:
181
+ - name: dashboard
182
+ port: 5000
183
+ domains:
184
+ - dashboard.example.com
185
+ - admin.example.com
186
+ - app.example.com
187
+ healthCheck:
188
+ path: /api/health
189
+ interval: 60
190
+ environment:
191
+ DATABASE_URL: postgresql://localhost:5432/dashboard
192
+ REDIS_URL: redis://localhost:6379
193
+
194
+ nginx:
195
+ configPath: /etc/nginx/sites-available
196
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
197
+
198
+ certbot:
199
+ email: admin@example.com
200
+ staging: false
201
+
202
+ deployment:
203
+ strategy: rolling
204
+ healthCheckTimeout: 30000
205
+ ```
206
+
207
+ ### การ Deploy
208
+
209
+ ```bash
210
+ suthep deploy
211
+ ```
212
+
213
+ ### ผลลัพธ์
214
+
215
+ - บริการพร้อมใช้งานที่:
216
+ - `https://dashboard.example.com`
217
+ - `https://admin.example.com`
218
+ - `https://app.example.com`
219
+ - โดเมนทั้งหมดกำหนดเส้นทางไปยังบริการเดียวกัน
220
+
221
+ ## ตัวอย่างที่ 5: เชื่อมต่อกับ Docker Container ที่มีอยู่
222
+
223
+ เชื่อมต่อกับ Docker container ที่กำลังรันอยู่แล้ว
224
+
225
+ ### การตั้งค่า
226
+
227
+ ```yaml
228
+ project:
229
+ name: database-proxy
230
+ version: 1.0.0
231
+
232
+ services:
233
+ - name: database-proxy
234
+ port: 5432
235
+ docker:
236
+ container: postgres-container
237
+ port: 5432
238
+ domains:
239
+ - db.example.com
240
+
241
+ nginx:
242
+ configPath: /etc/nginx/sites-available
243
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
244
+
245
+ certbot:
246
+ email: admin@example.com
247
+ staging: false
248
+
249
+ deployment:
250
+ strategy: rolling
251
+ healthCheckTimeout: 30000
252
+ ```
253
+
254
+ ### การ Deploy
255
+
256
+ ```bash
257
+ # ตรวจสอบว่า container กำลังรัน
258
+ docker start postgres-container
259
+
260
+ # Deploy
261
+ suthep deploy
262
+ ```
263
+
264
+ ### ผลลัพธ์
265
+
266
+ - Nginx ตั้งค่าให้ proxy ไปยัง container ที่มีอยู่
267
+ - ไม่มีการสร้าง container ใหม่
268
+
269
+ ## ตัวอย่างที่ 6: สถาปัตยกรรม Microservices
270
+
271
+ Deploy หลาย microservices พร้อมโดเมนต่างกัน
272
+
273
+ ### การตั้งค่า
274
+
275
+ ```yaml
276
+ project:
277
+ name: microservices-platform
278
+ version: 1.0.0
279
+
280
+ services:
281
+ # บริการผู้ใช้
282
+ - name: user-service
283
+ port: 3001
284
+ domains:
285
+ - users.api.example.com
286
+ docker:
287
+ image: myapp/user-service:latest
288
+ container: user-service-container
289
+ port: 3001
290
+ healthCheck:
291
+ path: /health
292
+ interval: 30
293
+
294
+ # บริการผลิตภัณฑ์
295
+ - name: product-service
296
+ port: 3002
297
+ domains:
298
+ - products.api.example.com
299
+ docker:
300
+ image: myapp/product-service:latest
301
+ container: product-service-container
302
+ port: 3002
303
+ healthCheck:
304
+ path: /health
305
+ interval: 30
306
+
307
+ # บริการคำสั่งซื้อ
308
+ - name: order-service
309
+ port: 3003
310
+ domains:
311
+ - orders.api.example.com
312
+ docker:
313
+ image: myapp/order-service:latest
314
+ container: order-service-container
315
+ port: 3003
316
+ healthCheck:
317
+ path: /health
318
+ interval: 30
319
+
320
+ nginx:
321
+ configPath: /etc/nginx/sites-available
322
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
323
+
324
+ certbot:
325
+ email: admin@example.com
326
+ staging: false
327
+
328
+ deployment:
329
+ strategy: rolling
330
+ healthCheckTimeout: 30000
331
+ ```
332
+
333
+ ### การ Deploy
334
+
335
+ ```bash
336
+ suthep deploy
337
+ ```
338
+
339
+ ### ผลลัพธ์
340
+
341
+ - แต่ละ microservice มี subdomain ของตัวเอง
342
+ - การ deploy และ scaling อิสระ
343
+ - บริการทั้งหมดมี HTTPS อัตโนมัติ
344
+
345
+ ## ตัวอย่างที่ 7: สภาพแวดล้อมการพัฒนา
346
+
347
+ Deploy พร้อมใบรับรอง SSL staging สำหรับการทดสอบ
348
+
349
+ ### การตั้งค่า
350
+
351
+ ```yaml
352
+ project:
353
+ name: dev-app
354
+ version: 0.1.0
355
+
356
+ services:
357
+ - name: api
358
+ port: 3000
359
+ domains:
360
+ - api.dev.example.com
361
+ healthCheck:
362
+ path: /health
363
+ interval: 60
364
+
365
+ nginx:
366
+ configPath: /etc/nginx/sites-available
367
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
368
+
369
+ certbot:
370
+ email: dev@example.com
371
+ staging: true # ใช้ staging สำหรับการทดสอบ
372
+
373
+ deployment:
374
+ strategy: rolling
375
+ healthCheckTimeout: 30000
376
+ ```
377
+
378
+ ### การ Deploy
379
+
380
+ ```bash
381
+ suthep deploy
382
+ ```
383
+
384
+ ### ผลลัพธ์
385
+
386
+ - ใช้สภาพแวดล้อม staging ของ Let's Encrypt
387
+ - ไม่มี rate limits สำหรับการทดสอบ
388
+ - สามารถทดสอบ SSL โดยไม่กระทบ production
389
+
390
+ ## ตัวอย่างที่ 8: Blue-Green Deployment
391
+
392
+ ใช้กลยุทธ์ blue-green deployment สำหรับ zero downtime
393
+
394
+ ### การตั้งค่า
395
+
396
+ ```yaml
397
+ project:
398
+ name: production-app
399
+ version: 2.0.0
400
+
401
+ services:
402
+ - name: api
403
+ port: 3000
404
+ domains:
405
+ - api.example.com
406
+ docker:
407
+ image: myapp/api:v2.0.0
408
+ container: api-container
409
+ port: 3000
410
+ healthCheck:
411
+ path: /health
412
+ interval: 30
413
+
414
+ nginx:
415
+ configPath: /etc/nginx/sites-available
416
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
417
+
418
+ certbot:
419
+ email: admin@example.com
420
+ staging: false
421
+
422
+ deployment:
423
+ strategy: blue-green # ใช้ blue-green deployment
424
+ healthCheckTimeout: 30000
425
+ ```
426
+
427
+ ### การ Deploy
428
+
429
+ ```bash
430
+ suthep deploy
431
+ ```
432
+
433
+ ### ผลลัพธ์
434
+
435
+ - สร้าง container ใหม่พร้อมกับ container เก่า
436
+ - สลับ traffic ไปยัง container ใหม่
437
+ - ลบ container เก่าหลังสลับ
438
+ - Zero downtime ระหว่างการ deploy
439
+
440
+ ## วิธีปฏิบัติที่ดีจากตัวอย่าง
441
+
442
+ 1. **ใช้ชื่อบริการที่อธิบายได้** - ทำให้การตั้งค่าเข้าใจง่ายขึ้น
443
+ 2. **ตั้งค่าช่วงเวลา health check ที่เหมาะสม** - สมดุลระหว่างการตอบสนองและโหลด
444
+ 3. **ใช้ staging สำหรับการพัฒนา** - หลีกเลี่ยง rate limits ระหว่างการทดสอบ
445
+ 4. **จัดกลุ่มบริการที่เกี่ยวข้อง** - จัดระเบียบตามโดเมนหรือฟังก์ชันการทำงาน
446
+ 5. **ใช้ path-based routing** - ใช้โดเมนเดียวอย่างมีประสิทธิภาพสำหรับหลายบริการ
447
+
448
+ ## ขั้นตอนถัดไป
449
+
450
+ - [การแก้ปัญหา](./07-troubleshooting.md) - ปัญหาที่พบบ่อยและวิธีแก้ไข
451
+ - [หัวข้อขั้นสูง](./08-advanced.md) - ตัวเลือกการตั้งค่าขั้นสูง
452
+
453
+ ---
454
+
455
+ **ก่อนหน้า:** [คำสั่งอ้างอิง](./05-commands.md) | **ถัดไป:** [การแก้ปัญหา →](./07-troubleshooting.md)
456
+