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
package/.editorconfig ADDED
@@ -0,0 +1,17 @@
1
+ # Editor configuration, see http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 2
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.md]
12
+ max_line_length = off
13
+ trim_trailing_whitespace = false
14
+
15
+ [{Makefile,**.mk}]
16
+ indent_style = tab
17
+ indent_size = 2
@@ -0,0 +1,42 @@
1
+ name: Publish Package
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+ inputs:
9
+ tag:
10
+ description: "Version tag (e.g., v0.2.1)"
11
+ required: false
12
+ type: string
13
+
14
+ permissions:
15
+ id-token: write # Required for OIDC
16
+ contents: read
17
+
18
+ jobs:
19
+ publish:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - name: Checkout code
24
+ uses: actions/checkout@v6
25
+
26
+ - name: Setup Node.js
27
+ uses: actions/setup-node@v6
28
+ with:
29
+ node-version: "24"
30
+ registry-url: "https://registry.npmjs.org"
31
+
32
+ - name: Install dependencies
33
+ run: npm ci
34
+
35
+ - name: Run tests
36
+ run: npm test
37
+
38
+ - name: Build project
39
+ run: npm run build
40
+
41
+ - name: Publish to npm
42
+ run: npm publish
@@ -0,0 +1,6 @@
1
+ **/dist
2
+ **/coverage
3
+ **/.turbo
4
+ **/node_modules
5
+
6
+ package.json
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "tabWidth": 2,
3
+ "trailingComma": "es5",
4
+ "printWidth": 100,
5
+ "singleQuote": true,
6
+ "semi": false
7
+ }
File without changes
@@ -0,0 +1,6 @@
1
+ projectKey=suthep
2
+ serverUrl=http://localhost:9000
3
+ serverVersion=25.11.0.114957
4
+ dashboardUrl=http://localhost:9000/dashboard?id=suthep
5
+ ceTaskId=b372afa7-4704-4c89-be84-163ecb3ffff0
6
+ ceTaskUrl=http://localhost:9000/api/ce/task?id=b372afa7-4704-4c89-be84-163ecb3ffff0
@@ -0,0 +1,19 @@
1
+ {
2
+ "eslint.workingDirectories": [
3
+ {
4
+ "mode": "auto"
5
+ }
6
+ ],
7
+ "[typescript]": {
8
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
9
+ },
10
+ "editor.codeActionsOnSave": {
11
+ "source.organizeImports": "explicit"
12
+ },
13
+ "editor.formatOnSave": true,
14
+ "editor.insertSpaces": false,
15
+ "files.eol": "\n",
16
+ "files.insertFinalNewline": true,
17
+ "files.trimTrailingWhitespace": true
18
+ }
19
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Montol Saklor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,317 @@
1
+ # Suthep
2
+
3
+ A powerful CLI tool for deploying projects with automatic Nginx reverse proxy setup, HTTPS with Certbot, and zero-downtime deployments.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Features](#features)
8
+ - [Installation](#installation)
9
+ - [Quick Start](#quick-start)
10
+ - [Configuration](#configuration)
11
+ - [Commands](#commands)
12
+ - [Examples](#examples)
13
+ - [Requirements](#requirements)
14
+ - [Benefits](#benefits)
15
+ - [License](#license)
16
+
17
+ ## Features
18
+
19
+ - ✅ **Automatic Nginx Reverse Proxy** - Configures Nginx automatically for your services
20
+ - ✅ **Automatic HTTPS** - Sets up SSL/TLS certificates with Let's Encrypt via Certbot
21
+ - ✅ **Zero-Downtime Deployment** - Rolling deployment strategy ensures continuous availability
22
+ - ✅ **Docker Support** - Deploy Docker containers or connect to existing containers
23
+ - ✅ **Multiple Domains** - Support for multiple domains and subdomains per service
24
+ - ✅ **Health Checks** - Built-in health check monitoring for service reliability
25
+ - ✅ **YAML Configuration** - Simple, declarative configuration file format
26
+
27
+ ## Installation
28
+
29
+ Install Suthep globally using your preferred package manager:
30
+
31
+ ```bash
32
+ npm install -g suthep
33
+ # or
34
+ yarn global add suthep
35
+ # or
36
+ pnpm add -g suthep
37
+ ```
38
+
39
+ > **Note:** The tool uses `tsx` to run TypeScript directly, so no build step is required for development. For production builds, you can optionally compile to JavaScript using `npm run build`.
40
+
41
+ ## Quick Start
42
+
43
+ ### 1. Initialize Configuration
44
+
45
+ Create a new configuration file interactively:
46
+
47
+ ```bash
48
+ suthep init
49
+ ```
50
+
51
+ This will create a `suthep.yml` file with interactive prompts, or you can use an example configuration:
52
+
53
+ ```bash
54
+ cp example/suthep.yml suthep.yml
55
+ # Edit suthep.yml with your settings
56
+ ```
57
+
58
+ ### 2. Setup Prerequisites
59
+
60
+ Install and configure Nginx and Certbot on your system:
61
+
62
+ ```bash
63
+ suthep setup
64
+ ```
65
+
66
+ This command will:
67
+ - Install Nginx (if not already installed)
68
+ - Install Certbot (if not already installed)
69
+ - Configure system dependencies
70
+
71
+ ### 3. Deploy Your Project
72
+
73
+ Deploy your project using the configuration file:
74
+
75
+ ```bash
76
+ suthep deploy
77
+ ```
78
+
79
+ ## Configuration
80
+
81
+ The configuration file (`suthep.yml`) uses a YAML format to define your deployment. Here's the complete structure:
82
+
83
+ ```yaml
84
+ project:
85
+ name: my-app
86
+ version: 1.0.0
87
+
88
+ services:
89
+ - name: api
90
+ port: 3000
91
+ domains:
92
+ - api.example.com
93
+ - www.api.example.com
94
+ healthCheck:
95
+ path: /health
96
+ interval: 30
97
+ environment:
98
+ NODE_ENV: production
99
+
100
+ - name: webapp
101
+ port: 8080
102
+ docker:
103
+ image: nginx:latest
104
+ container: webapp-container
105
+ port: 80
106
+ domains:
107
+ - example.com
108
+ - www.example.com
109
+
110
+ nginx:
111
+ configPath: /etc/nginx/sites-available
112
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
113
+
114
+ certbot:
115
+ email: admin@example.com
116
+ staging: false
117
+
118
+ deployment:
119
+ strategy: rolling
120
+ healthCheckTimeout: 30000
121
+ ```
122
+
123
+ ### Service Configuration
124
+
125
+ Each service in the `services` array can have the following properties:
126
+
127
+ | Property | Required | Description |
128
+ |----------|----------|-------------|
129
+ | `name` | ✅ Yes | Unique identifier for the service |
130
+ | `port` | ✅ Yes | Port number the service runs on (host port) |
131
+ | `domains` | ✅ Yes | Array of domain names or subdomains to route to this service |
132
+ | `docker` | ❌ No | Docker configuration (see below) |
133
+ | `healthCheck` | ❌ No | Health check configuration (see below) |
134
+ | `environment` | ❌ No | Environment variables as key-value pairs |
135
+
136
+ #### Docker Configuration
137
+
138
+ When deploying Docker containers, use the `docker` object:
139
+
140
+ - **`image`**: Docker image to pull and run (e.g., `nginx:latest`)
141
+ - **`container`**: Name for the Docker container
142
+ - **`port`**: Internal port the container listens on (mapped to the service `port`)
143
+
144
+ #### Health Check Configuration
145
+
146
+ Configure health monitoring for your service:
147
+
148
+ - **`path`**: HTTP endpoint path for health checks (e.g., `/health`)
149
+ - **`interval`**: Time between health checks in seconds (default: 30)
150
+
151
+ ## Commands
152
+
153
+ ### `suthep init`
154
+
155
+ Initialize a new deployment configuration file with interactive prompts.
156
+
157
+ ```bash
158
+ suthep init [-f suthep.yml]
159
+ ```
160
+
161
+ **Options:**
162
+ - `-f, --file`: Configuration file path (default: `suthep.yml`)
163
+
164
+ ### `suthep setup`
165
+
166
+ Install and configure Nginx and Certbot on your system. This command checks for existing installations and sets up any missing components.
167
+
168
+ ```bash
169
+ suthep setup [--nginx-only] [--certbot-only]
170
+ ```
171
+
172
+ **Options:**
173
+ - `--nginx-only`: Only install and configure Nginx
174
+ - `--certbot-only`: Only install and configure Certbot
175
+
176
+ ### `suthep deploy`
177
+
178
+ Deploy your project using the configuration file. This command will:
179
+ 1. Configure Nginx reverse proxy for all services
180
+ 2. Obtain SSL certificates via Certbot (if enabled)
181
+ 3. Deploy services with zero-downtime strategy
182
+
183
+ ```bash
184
+ suthep deploy [service-name] [-f suthep.yml] [--no-https] [--no-nginx] [-e KEY=VALUE ...]
185
+ ```
186
+
187
+ **Options:**
188
+ - `service-name`: Name of the service to deploy (optional, deploys all services if not specified)
189
+ - `-f, --file`: Configuration file path (default: `suthep.yml`)
190
+ - `--no-https`: Skip HTTPS/SSL certificate setup
191
+ - `--no-nginx`: Skip Nginx configuration (useful for testing)
192
+ - `-e, --env`: Set environment variables (can be used multiple times, e.g., `-e KEY1=value1 -e KEY2=value2`)
193
+
194
+ ## Examples
195
+
196
+ ### Example 1: Simple Node.js API Service
197
+
198
+ Deploy a Node.js API service with health checks:
199
+
200
+ ```yaml
201
+ project:
202
+ name: my-api
203
+ version: 1.0.0
204
+
205
+ services:
206
+ - name: api
207
+ port: 3000
208
+ domains:
209
+ - api.example.com
210
+ healthCheck:
211
+ path: /health
212
+ interval: 30
213
+ environment:
214
+ NODE_ENV: production
215
+
216
+ nginx:
217
+ configPath: /etc/nginx/sites-available
218
+ reloadCommand: sudo nginx -t && sudo systemctl reload nginx
219
+
220
+ certbot:
221
+ email: admin@example.com
222
+ staging: false
223
+
224
+ deployment:
225
+ strategy: rolling
226
+ healthCheckTimeout: 30000
227
+ ```
228
+
229
+ ### Example 2: Docker Container Service
230
+
231
+ Deploy a web application using a Docker container:
232
+
233
+ ```yaml
234
+ services:
235
+ - name: webapp
236
+ port: 8080
237
+ docker:
238
+ image: myapp/webapp:latest
239
+ container: webapp-container
240
+ port: 80
241
+ domains:
242
+ - example.com
243
+ - www.example.com
244
+ ```
245
+
246
+ ### Example 3: Multiple Domains for Single Service
247
+
248
+ Route multiple domains to the same service:
249
+
250
+ ```yaml
251
+ services:
252
+ - name: dashboard
253
+ port: 5000
254
+ domains:
255
+ - dashboard.example.com
256
+ - admin.example.com
257
+ - app.example.com
258
+ healthCheck:
259
+ path: /api/health
260
+ ```
261
+
262
+ ### Example 4: Connect to Existing Docker Container
263
+
264
+ Connect to an already running Docker container:
265
+
266
+ ```yaml
267
+ services:
268
+ - name: database-proxy
269
+ port: 5432
270
+ docker:
271
+ container: postgres-container
272
+ port: 5432
273
+ domains:
274
+ - db.example.com
275
+ ```
276
+
277
+ > **Note:** When connecting to an existing container, omit the `image` field. The tool will use the existing container.
278
+
279
+ ## Requirements
280
+
281
+ ### System Requirements
282
+
283
+ - **Node.js** 16 or higher
284
+ - **Nginx** (installed automatically via `suthep setup`)
285
+ - **Certbot** (installed automatically via `suthep setup`)
286
+ - **Docker** (optional, required only for Docker-based services)
287
+ - **sudo access** (required for Nginx and Certbot operations)
288
+
289
+ ### Permissions
290
+
291
+ Suthep requires sudo privileges to:
292
+ - Install system packages (Nginx, Certbot)
293
+ - Modify Nginx configuration files
294
+ - Reload Nginx service
295
+ - Obtain SSL certificates from Let's Encrypt
296
+
297
+ ## Benefits
298
+
299
+ ### Cost Optimization
300
+
301
+ Suthep helps optimize infrastructure costs by:
302
+
303
+ - **Multi-Service Management** - Run multiple services on a single server efficiently
304
+ - **Automated Configuration** - Eliminates manual Nginx and SSL setup, saving time and reducing errors
305
+ - **Zero-Downtime Deployments** - Rolling deployment strategy ensures continuous service availability
306
+ - **Health Monitoring** - Built-in health checks help maintain service reliability and catch issues early
307
+
308
+ ### Developer Experience
309
+
310
+ - **Simple Configuration** - YAML-based configuration is easy to understand and maintain
311
+ - **One Command Deployment** - Deploy entire infrastructure with a single command
312
+ - **Automatic SSL** - HTTPS certificates are obtained and renewed automatically
313
+ - **Docker Integration** - Seamless support for containerized applications
314
+
315
+ ## License
316
+
317
+ [MIT](LICENSE)