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.
Files changed (83) hide show
  1. package/.editorconfig +17 -0
  2. package/.github/workflows/publish.yml +42 -0
  3. package/.prettierignore +6 -0
  4. package/.prettierrc +7 -0
  5. package/.scannerwork/.sonar_lock +0 -0
  6. package/.scannerwork/report-task.txt +6 -0
  7. package/.vscode/settings.json +19 -0
  8. package/LICENSE +21 -0
  9. package/README.md +317 -0
  10. package/dist/commands/deploy.js +371 -0
  11. package/dist/commands/deploy.js.map +1 -0
  12. package/dist/commands/down.js +179 -0
  13. package/dist/commands/down.js.map +1 -0
  14. package/dist/commands/init.js +188 -0
  15. package/dist/commands/init.js.map +1 -0
  16. package/dist/commands/setup.js +90 -0
  17. package/dist/commands/setup.js.map +1 -0
  18. package/dist/commands/up.js +213 -0
  19. package/dist/commands/up.js.map +1 -0
  20. package/dist/index.js +66 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/utils/certbot.js +64 -0
  23. package/dist/utils/certbot.js.map +1 -0
  24. package/dist/utils/config-loader.js +127 -0
  25. package/dist/utils/config-loader.js.map +1 -0
  26. package/dist/utils/deployment.js +85 -0
  27. package/dist/utils/deployment.js.map +1 -0
  28. package/dist/utils/docker.js +425 -0
  29. package/dist/utils/docker.js.map +1 -0
  30. package/dist/utils/env-loader.js +53 -0
  31. package/dist/utils/env-loader.js.map +1 -0
  32. package/dist/utils/nginx.js +378 -0
  33. package/dist/utils/nginx.js.map +1 -0
  34. package/docs/README.md +38 -0
  35. package/docs/english/01-introduction.md +84 -0
  36. package/docs/english/02-installation.md +200 -0
  37. package/docs/english/03-quick-start.md +258 -0
  38. package/docs/english/04-configuration.md +433 -0
  39. package/docs/english/05-commands.md +336 -0
  40. package/docs/english/06-examples.md +456 -0
  41. package/docs/english/07-troubleshooting.md +417 -0
  42. package/docs/english/08-advanced.md +411 -0
  43. package/docs/english/README.md +48 -0
  44. package/docs/thai/01-introduction.md +84 -0
  45. package/docs/thai/02-installation.md +200 -0
  46. package/docs/thai/03-quick-start.md +258 -0
  47. package/docs/thai/04-configuration.md +433 -0
  48. package/docs/thai/05-commands.md +336 -0
  49. package/docs/thai/06-examples.md +456 -0
  50. package/docs/thai/07-troubleshooting.md +417 -0
  51. package/docs/thai/08-advanced.md +411 -0
  52. package/docs/thai/README.md +48 -0
  53. package/example/suthep-complete.yml +103 -0
  54. package/example/suthep-docker-only.yml +71 -0
  55. package/example/suthep-env-example.yml +113 -0
  56. package/example/suthep-no-docker.yml +51 -0
  57. package/example/suthep-path-routing.yml +62 -0
  58. package/example/suthep.example.yml +88 -0
  59. package/package.json +51 -0
  60. package/src/commands/deploy.ts +488 -0
  61. package/src/commands/down.ts +240 -0
  62. package/src/commands/init.ts +214 -0
  63. package/src/commands/setup.ts +112 -0
  64. package/src/commands/up.ts +271 -0
  65. package/src/index.ts +109 -0
  66. package/src/types/config.ts +52 -0
  67. package/src/utils/__tests__/certbot.test.ts +222 -0
  68. package/src/utils/__tests__/config-loader.test.ts +419 -0
  69. package/src/utils/__tests__/deployment.test.ts +243 -0
  70. package/src/utils/__tests__/nginx.test.ts +412 -0
  71. package/src/utils/certbot.ts +144 -0
  72. package/src/utils/config-loader.ts +184 -0
  73. package/src/utils/deployment.ts +157 -0
  74. package/src/utils/docker.ts +768 -0
  75. package/src/utils/env-loader.ts +135 -0
  76. package/src/utils/nginx.ts +443 -0
  77. package/suthep-1.0.0.tgz +0 -0
  78. package/suthep.example.yml +98 -0
  79. package/suthep.yml +39 -0
  80. package/todo.md +6 -0
  81. package/tsconfig.json +26 -0
  82. package/vite.config.ts +46 -0
  83. package/vitest.config.ts +21 -0
@@ -0,0 +1,200 @@
1
+ # Installation Guide
2
+
3
+ This guide will walk you through installing Suthep on your system.
4
+
5
+ ## System Requirements
6
+
7
+ Before installing Suthep, ensure your system meets these requirements:
8
+
9
+ - **Node.js** version 16 or higher
10
+ - **npm**, **yarn**, or **pnpm** package manager
11
+ - **sudo/administrator privileges** (required for Nginx and Certbot setup)
12
+ - **Linux** or **macOS** operating system
13
+
14
+ ## Installing Suthep
15
+
16
+ Suthep can be installed globally using any Node.js package manager.
17
+
18
+ ### Using npm
19
+
20
+ ```bash
21
+ npm install -g suthep
22
+ ```
23
+
24
+ ### Using yarn
25
+
26
+ ```bash
27
+ yarn global add suthep
28
+ ```
29
+
30
+ ### Using pnpm
31
+
32
+ ```bash
33
+ pnpm add -g suthep
34
+ ```
35
+
36
+ ## Verify Installation
37
+
38
+ After installation, verify that Suthep is installed correctly:
39
+
40
+ ```bash
41
+ suthep --version
42
+ ```
43
+
44
+ You should see the version number (e.g., `0.1.0-beta.1`).
45
+
46
+ You can also check the help menu:
47
+
48
+ ```bash
49
+ suthep --help
50
+ ```
51
+
52
+ ## Installing Prerequisites
53
+
54
+ Suthep requires Nginx and Certbot to function. You can install these automatically using the `setup` command:
55
+
56
+ ```bash
57
+ suthep setup
58
+ ```
59
+
60
+ This command will:
61
+ - Install Nginx (if not already installed)
62
+ - Install Certbot (if not already installed)
63
+ - Configure system dependencies
64
+
65
+ ### Manual Installation (Optional)
66
+
67
+ If you prefer to install prerequisites manually:
68
+
69
+ #### Nginx Installation
70
+
71
+ **Ubuntu/Debian:**
72
+ ```bash
73
+ sudo apt-get update
74
+ sudo apt-get install -y nginx
75
+ ```
76
+
77
+ **CentOS/RHEL:**
78
+ ```bash
79
+ sudo yum install -y nginx
80
+ ```
81
+
82
+ **macOS:**
83
+ ```bash
84
+ brew install nginx
85
+ ```
86
+
87
+ #### Certbot Installation
88
+
89
+ **Ubuntu/Debian:**
90
+ ```bash
91
+ sudo apt-get update
92
+ sudo apt-get install -y certbot python3-certbot-nginx
93
+ ```
94
+
95
+ **CentOS/RHEL:**
96
+ ```bash
97
+ sudo yum install -y certbot python3-certbot-nginx
98
+ ```
99
+
100
+ **macOS:**
101
+ ```bash
102
+ brew install certbot
103
+ ```
104
+
105
+ ## Docker (Optional)
106
+
107
+ If you plan to deploy Docker containers, install Docker:
108
+
109
+ **Ubuntu/Debian:**
110
+ ```bash
111
+ sudo apt-get update
112
+ sudo apt-get install -y docker.io
113
+ sudo systemctl start docker
114
+ sudo systemctl enable docker
115
+ ```
116
+
117
+ **macOS:**
118
+ ```bash
119
+ brew install docker
120
+ ```
121
+
122
+ Or download Docker Desktop from [docker.com](https://www.docker.com/products/docker-desktop).
123
+
124
+ ## Post-Installation
125
+
126
+ After installation, you're ready to:
127
+
128
+ 1. **Initialize your first configuration:**
129
+ ```bash
130
+ suthep init
131
+ ```
132
+
133
+ 2. **Or continue to the Quick Start guide:**
134
+ See [Quick Start Guide](./03-quick-start.md)
135
+
136
+ ## Troubleshooting Installation
137
+
138
+ ### Command Not Found
139
+
140
+ If you get a "command not found" error:
141
+
142
+ 1. **Check Node.js installation:**
143
+ ```bash
144
+ node --version
145
+ npm --version
146
+ ```
147
+
148
+ 2. **Verify global bin path:**
149
+ ```bash
150
+ npm config get prefix
151
+ ```
152
+
153
+ 3. **Add npm global bin to PATH** (if needed):
154
+ ```bash
155
+ export PATH="$PATH:$(npm config get prefix)/bin"
156
+ ```
157
+
158
+ ### Permission Errors
159
+
160
+ If you encounter permission errors:
161
+
162
+ 1. **Use sudo for global installation:**
163
+ ```bash
164
+ sudo npm install -g suthep
165
+ ```
166
+
167
+ 2. **Or configure npm to use a different directory:**
168
+ ```bash
169
+ mkdir ~/.npm-global
170
+ npm config set prefix '~/.npm-global'
171
+ export PATH=~/.npm-global/bin:$PATH
172
+ ```
173
+
174
+ ### Nginx/Certbot Installation Issues
175
+
176
+ If `suthep setup` fails:
177
+
178
+ 1. **Check your package manager:**
179
+ - Ubuntu/Debian: Ensure `apt-get` is available
180
+ - CentOS/RHEL: Ensure `yum` is available
181
+ - macOS: Ensure Homebrew is installed
182
+
183
+ 2. **Run setup with verbose output:**
184
+ ```bash
185
+ suthep setup --verbose
186
+ ```
187
+
188
+ 3. **Install prerequisites manually** (see Manual Installation above)
189
+
190
+ ## Next Steps
191
+
192
+ Now that Suthep is installed:
193
+
194
+ - [Quick Start Guide](./03-quick-start.md) - Deploy your first service
195
+ - [Configuration Guide](./04-configuration.md) - Learn about configuration options
196
+
197
+ ---
198
+
199
+ **Previous:** [Introduction](./01-introduction.md) | **Next:** [Quick Start →](./03-quick-start.md)
200
+
@@ -0,0 +1,258 @@
1
+ # Quick Start Guide
2
+
3
+ This guide will help you deploy your first service with Suthep in just a few minutes.
4
+
5
+ ## Step 1: Initialize Configuration
6
+
7
+ Create a new configuration file interactively:
8
+
9
+ ```bash
10
+ suthep init
11
+ ```
12
+
13
+ This command will prompt you for:
14
+ - Project name and version
15
+ - Service details (name, port, domains)
16
+ - Docker configuration (if needed)
17
+ - Health check settings
18
+ - SSL certificate email
19
+
20
+ Alternatively, you can copy the example configuration:
21
+
22
+ ```bash
23
+ cp suthep.example.yml suthep.yml
24
+ ```
25
+
26
+ Then edit `suthep.yml` with your settings.
27
+
28
+ ## Step 2: Setup Prerequisites
29
+
30
+ Install and configure Nginx and Certbot:
31
+
32
+ ```bash
33
+ suthep setup
34
+ ```
35
+
36
+ This will:
37
+ - Install Nginx (if not already installed)
38
+ - Install Certbot (if not already installed)
39
+ - Configure system dependencies
40
+
41
+ **Note:** This command requires sudo privileges.
42
+
43
+ ## Step 3: Deploy Your Service
44
+
45
+ Deploy your project:
46
+
47
+ ```bash
48
+ suthep deploy
49
+ ```
50
+
51
+ This command will:
52
+ 1. Configure Nginx reverse proxy for all services
53
+ 2. Obtain SSL certificates via Certbot (if enabled)
54
+ 3. Deploy services with zero-downtime strategy
55
+
56
+ ## Example: Deploying a Simple API
57
+
58
+ Let's walk through deploying a Node.js API service:
59
+
60
+ ### 1. Create Configuration
61
+
62
+ Create `suthep.yml`:
63
+
64
+ ```yaml
65
+ project:
66
+ name: my-api
67
+ version: 1.0.0
68
+
69
+ services:
70
+ - name: api
71
+ port: 3000
72
+ domains:
73
+ - api.example.com
74
+ healthCheck:
75
+ path: /health
76
+ interval: 30
77
+ environment:
78
+ NODE_ENV: production
79
+
80
+ nginx:
81
+ configPath: /etc/nginx/sites-available
82
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
83
+
84
+ certbot:
85
+ email: admin@example.com
86
+ staging: false
87
+
88
+ deployment:
89
+ strategy: rolling
90
+ healthCheckTimeout: 30000
91
+ ```
92
+
93
+ ### 2. Setup Prerequisites
94
+
95
+ ```bash
96
+ suthep setup
97
+ ```
98
+
99
+ ### 3. Deploy
100
+
101
+ ```bash
102
+ suthep deploy
103
+ ```
104
+
105
+ ### 4. Verify Deployment
106
+
107
+ After deployment, Suthep will display service URLs:
108
+
109
+ ```
110
+ 📋 Service URLs:
111
+ api: https://api.example.com
112
+ ```
113
+
114
+ Visit the URL in your browser to verify the service is running.
115
+
116
+ ## Example: Deploying a Docker Container
117
+
118
+ To deploy a Docker container:
119
+
120
+ ```yaml
121
+ services:
122
+ - name: webapp
123
+ port: 8080
124
+ docker:
125
+ image: nginx:latest
126
+ container: webapp-container
127
+ port: 80
128
+ domains:
129
+ - example.com
130
+ - www.example.com
131
+ ```
132
+
133
+ Then run:
134
+
135
+ ```bash
136
+ suthep deploy
137
+ ```
138
+
139
+ ## Common Commands
140
+
141
+ ### Check Service Status
142
+
143
+ ```bash
144
+ # View Nginx configuration
145
+ sudo nginx -t
146
+
147
+ # Check running containers
148
+ docker ps
149
+
150
+ # View service logs
151
+ docker logs <container-name>
152
+ ```
153
+
154
+ ### Update Configuration
155
+
156
+ 1. Edit `suthep.yml`
157
+ 2. Redeploy (bring down and deploy again):
158
+ ```bash
159
+ suthep down <service-name> && suthep deploy <service-name>
160
+ # Or for all services:
161
+ suthep down --all && suthep deploy
162
+ ```
163
+
164
+ ### Stop Services
165
+
166
+ ```bash
167
+ # Stop a specific service
168
+ suthep down <service-name>
169
+
170
+ # Stop all services
171
+ suthep down --all
172
+ ```
173
+
174
+ ### Start Services
175
+
176
+ ```bash
177
+ # Start a specific service
178
+ suthep up <service-name>
179
+
180
+ # Start all services
181
+ suthep up --all
182
+ ```
183
+
184
+ ## What Happens During Deployment?
185
+
186
+ When you run `suthep deploy`, Suthep:
187
+
188
+ 1. **Loads Configuration** - Reads your `suthep.yml` file
189
+ 2. **Starts Docker Containers** - If Docker is configured, starts containers
190
+ 3. **Configures Nginx** - Generates and writes Nginx configuration files
191
+ 4. **Enables Sites** - Creates symlinks to enable Nginx sites
192
+ 5. **Obtains SSL Certificates** - Requests certificates from Let's Encrypt
193
+ 6. **Updates Nginx for HTTPS** - Adds SSL configuration to Nginx
194
+ 7. **Reloads Nginx** - Applies all changes
195
+ 8. **Performs Health Checks** - Verifies services are running correctly
196
+
197
+ ## Troubleshooting Quick Start
198
+
199
+ ### Domain Not Resolving
200
+
201
+ Ensure your domain points to your server:
202
+
203
+ ```bash
204
+ # Check DNS
205
+ nslookup api.example.com
206
+
207
+ # Verify server IP matches
208
+ curl -I http://api.example.com
209
+ ```
210
+
211
+ ### Port Already in Use
212
+
213
+ If you get a "port already in use" error:
214
+
215
+ 1. **Find what's using the port:**
216
+ ```bash
217
+ sudo lsof -i :3000
218
+ ```
219
+
220
+ 2. **Stop the conflicting service** or **change the port** in `suthep.yml`
221
+
222
+ ### SSL Certificate Issues
223
+
224
+ If SSL certificate creation fails:
225
+
226
+ 1. **Check domain DNS** - Ensure domain points to your server
227
+ 2. **Use staging mode** for testing:
228
+ ```yaml
229
+ certbot:
230
+ staging: true
231
+ ```
232
+
233
+ 3. **Check firewall** - Ensure ports 80 and 443 are open
234
+
235
+ ### Nginx Configuration Errors
236
+
237
+ If Nginx fails to reload:
238
+
239
+ ```bash
240
+ # Test Nginx configuration
241
+ sudo nginx -t
242
+
243
+ # Check Nginx error logs
244
+ sudo tail -f /var/log/nginx/error.log
245
+ ```
246
+
247
+ ## Next Steps
248
+
249
+ Now that you've deployed your first service:
250
+
251
+ - [Configuration Guide](./04-configuration.md) - Learn about all configuration options
252
+ - [Commands Reference](./05-commands.md) - Explore all available commands
253
+ - [Examples](./06-examples.md) - See more deployment examples
254
+
255
+ ---
256
+
257
+ **Previous:** [Installation](./02-installation.md) | **Next:** [Configuration Guide →](./04-configuration.md)
258
+