@it-club/provisor 0.1.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/README.md ADDED
@@ -0,0 +1,317 @@
1
+ # @it-club/provisor
2
+
3
+ Interactive CLI tool for server provisioning and deployment with automatic deploy support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Install globally
9
+ npm install -g @it-club/provisor
10
+
11
+ # Or run directly with npx
12
+ npx @it-club/provisor
13
+ ```
14
+
15
+ ## Commands
16
+
17
+ ### `provisor init` - Initialize Server
18
+
19
+ Sets up a new server with user management, SSH hardening, and firewall configuration.
20
+
21
+ ```bash
22
+ provisor init -h <server-ip>
23
+
24
+ # Options
25
+ -h, --host <host> Server hostname or IP (required)
26
+ -u, --user <user> Username to create (default: "deploy")
27
+ -k, --key <path> Path to SSH private key
28
+ -p, --port <port> SSH port (default: "22")
29
+ ```
30
+
31
+ **What it does:**
32
+ 1. Connects as root
33
+ 2. Updates system packages
34
+ 3. Creates a new user with sudo access
35
+ 4. Copies root's SSH keys to new user
36
+ 5. Configures UFW firewall (SSH, HTTP, HTTPS)
37
+ 6. Hardens SSH (disables root login, password auth)
38
+
39
+ ---
40
+
41
+ ### `provisor app` - Provision Application
42
+
43
+ Sets up Caddy, Node.js, and git-based deployment with optional auto-deploy.
44
+
45
+ ```bash
46
+ provisor app -h <server-ip> -n myapp
47
+
48
+ # Options
49
+ -h, --host <host> Server hostname or IP (required)
50
+ -u, --user <user> Username to connect as (default: "deploy")
51
+ -k, --key <path> Path to SSH private key
52
+ -p, --port <port> SSH port (default: "22")
53
+ -b, --branch <branch> Deploy branch (default: "main")
54
+ -n, --name <name> Application name (default: "app")
55
+ -r, --repo <url> Clone from repository URL (GitHub, GitLab, etc.)
56
+ ```
57
+
58
+ **What it does:**
59
+ 1. Installs Caddy web server
60
+ 2. Installs Node.js LTS and PM2
61
+ 3. Sets up deployment (choose from 3 methods):
62
+ - **Push-to-deploy**: Creates bare git repo for `git push` deployments
63
+ - **Clone from public repo**: Clones HTTPS repository
64
+ - **Clone from private repo**: Generates deploy key, clones SSH repository
65
+ 4. Sets up auto-deploy (choose from 3 options):
66
+ - **Git polling**: Checks for new commits every N seconds (simpler, works everywhere)
67
+ - **Webhook**: Instant deployment on push (requires repo webhook setup)
68
+ - **Manual only**: Use `provisor deploy` command
69
+ 5. Configures Caddy with your choice of TLS (on-demand, specific domain, or none)
70
+
71
+ **Deployment Methods:**
72
+
73
+ | Method | Best For | Auto-Deploy |
74
+ |--------|----------|-------------|
75
+ | Push-to-deploy | Private repos, full control | Built-in (git hook) |
76
+ | Clone public | Open source projects | Polling or webhook |
77
+ | Clone private | Private GitHub/GitLab repos | Polling or webhook |
78
+
79
+ ---
80
+
81
+ ### `provisor deploy` - Trigger Deployment
82
+
83
+ Manually trigger a deployment for an application.
84
+
85
+ ```bash
86
+ provisor deploy -h <server-ip> -n myapp
87
+
88
+ # Options
89
+ -h, --host <host> Server hostname or IP (required)
90
+ -n, --name <name> Application name (required)
91
+ -u, --user <user> Username to connect as (default: "deploy")
92
+ -k, --key <path> Path to SSH private key
93
+ -p, --port <port> SSH port (default: "22")
94
+ ```
95
+
96
+ ---
97
+
98
+ ### `provisor config` - Manage Configuration
99
+
100
+ View and manage application configuration, deploy keys, and auto-deploy settings.
101
+
102
+ ```bash
103
+ # Show current configuration
104
+ provisor config -h <server-ip> -n myapp --show
105
+
106
+ # Options
107
+ -h, --host <host> Server hostname or IP (required)
108
+ -n, --name <name> Application name (required)
109
+ -u, --user <user> Username to connect as (default: "deploy")
110
+ -k, --key <path> Path to SSH private key
111
+ -p, --port <port> SSH port (default: "22")
112
+ --show Show current configuration
113
+ --repo <url> Change repository URL
114
+ --branch <branch> Change deploy branch
115
+ --new-key Generate new deploy key
116
+ --delete-key Delete deploy key
117
+ --webhook-secret <secret> Update webhook secret
118
+ --disable-webhook Disable webhook
119
+ --polling-interval <seconds> Set git polling interval
120
+ --enable-polling Enable git polling
121
+ --disable-polling Disable git polling
122
+ ```
123
+
124
+ **Examples:**
125
+
126
+ ```bash
127
+ # View configuration and deploy key
128
+ provisor config -h 203.0.113.10 -n myapp --show
129
+
130
+ # Change polling interval to 30 seconds
131
+ provisor config -h 203.0.113.10 -n myapp --polling-interval 30
132
+
133
+ # Switch branches
134
+ provisor config -h 203.0.113.10 -n myapp --branch develop
135
+
136
+ # Disable auto-deploy
137
+ provisor config -h 203.0.113.10 -n myapp --disable-polling
138
+ ```
139
+
140
+ ---
141
+
142
+ ### `provisor ssh-key` - Manage SSH Keys
143
+
144
+ Add or list SSH keys on the server.
145
+
146
+ ```bash
147
+ # List keys
148
+ provisor ssh-key -h <server-ip> --list
149
+
150
+ # Add a key
151
+ provisor ssh-key -h <server-ip> --add "ssh-ed25519 AAAA... user@machine"
152
+ ```
153
+
154
+ ---
155
+
156
+ ### `provisor status` - Check Server Status
157
+
158
+ Display server health and service status.
159
+
160
+ ```bash
161
+ provisor status -h <server-ip>
162
+ ```
163
+
164
+ ---
165
+
166
+ ## Auto-Deploy Options
167
+
168
+ ### Git Polling (Recommended for simplicity)
169
+
170
+ Checks your repository for new commits at a configurable interval.
171
+
172
+ **Pros:**
173
+ - Works behind NAT/firewalls
174
+ - No webhook configuration needed
175
+ - Works in Docker containers
176
+ - Simple and reliable
177
+
178
+ **Cons:**
179
+ - Slight delay (interval-based)
180
+ - Uses minimal bandwidth for git fetch
181
+
182
+ ```bash
183
+ # View polling status
184
+ provisor config -h server -n app --show
185
+ # Output: Git Polling: Running (every 10s, daemon mode)
186
+
187
+ # Change interval
188
+ provisor config -h server -n app --polling-interval 60
189
+
190
+ # View polling logs
191
+ ssh deploy@server "tail -f /var/log/poll-app.log" # Daemon mode
192
+ ssh deploy@server "journalctl -u poll-app -f" # Systemd mode
193
+ ```
194
+
195
+ ### Webhook (Recommended for instant deploys)
196
+
197
+ Repository triggers deployment instantly on push.
198
+
199
+ **Pros:**
200
+ - Instant deployments
201
+ - No polling overhead
202
+
203
+ **Cons:**
204
+ - Requires firewall port open
205
+ - Requires webhook setup on GitHub/GitLab
206
+ - Doesn't work behind NAT without port forwarding
207
+
208
+ After setup, configure webhook in your repository:
209
+ - **URL**: `http://your-server:PORT/webhook`
210
+ - **Secret**: Shown after provisioning
211
+ - **Events**: Push events only
212
+
213
+ ---
214
+
215
+ ## Typical Workflows
216
+
217
+ ### Quick Start: Push-to-Deploy
218
+
219
+ ```bash
220
+ # 1. Initialize server
221
+ provisor init -h 203.0.113.10
222
+
223
+ # 2. Provision app
224
+ provisor app -h 203.0.113.10 -n myapp
225
+ # Select: Push-to-deploy
226
+ # Select: On-demand TLS
227
+
228
+ # 3. Add remote to local project
229
+ git remote add production ssh://deploy@203.0.113.10/var/repo/myapp.git
230
+
231
+ # 4. Deploy
232
+ git push production main
233
+ ```
234
+
235
+ ### Clone from GitHub with Auto-Deploy
236
+
237
+ ```bash
238
+ # 1. Initialize server
239
+ provisor init -h 203.0.113.10
240
+
241
+ # 2. Provision app with repo
242
+ provisor app -h 203.0.113.10 -n myapp -r https://github.com/user/repo.git
243
+ # Select: Git polling (recommended)
244
+ # Select: On-demand TLS
245
+
246
+ # Done! Polling will auto-deploy on new commits
247
+ ```
248
+
249
+ ### Private Repository with Deploy Key
250
+
251
+ ```bash
252
+ # 1. Initialize server
253
+ provisor init -h 203.0.113.10
254
+
255
+ # 2. Provision app
256
+ provisor app -h 203.0.113.10 -n myapp
257
+ # Select: Clone from private repository
258
+ # Enter: git@github.com:user/private-repo.git
259
+
260
+ # 3. Copy the displayed deploy key to GitHub:
261
+ # Repo → Settings → Deploy keys → Add deploy key
262
+
263
+ # 4. Confirm key added, deployment continues
264
+ # Select: Git polling
265
+ # Select: On-demand TLS
266
+ ```
267
+
268
+ ---
269
+
270
+ ## Environment Detection
271
+
272
+ The CLI automatically adapts to different environments:
273
+
274
+ | Environment | Auto-Deploy Method |
275
+ |-------------|-------------------|
276
+ | Systemd servers (Ubuntu, Debian) | Systemd timer |
277
+ | Docker containers | Background daemon loop |
278
+ | Non-systemd systems | Background daemon loop |
279
+
280
+ ---
281
+
282
+ ## SSH Key Detection
283
+
284
+ The CLI automatically looks for SSH keys in this order:
285
+ 1. `--key` flag if provided
286
+ 2. `~/.ssh/id_ed25519`
287
+ 3. `~/.ssh/id_rsa`
288
+ 4. `~/.ssh/id_ecdsa`
289
+
290
+ ---
291
+
292
+ ## File Locations on Server
293
+
294
+ | File | Purpose |
295
+ |------|---------|
296
+ | `/var/www/<app>/` | Application directory |
297
+ | `/var/repo/<app>.git/` | Bare git repo (push-to-deploy) |
298
+ | `/usr/local/bin/update-<app>` | Update/deploy script |
299
+ | `/usr/local/bin/poll-<app>.sh` | Single poll script |
300
+ | `/usr/local/bin/poll-<app>-daemon.sh` | Polling daemon (non-systemd) |
301
+ | `/var/log/poll-<app>.log` | Polling logs (daemon mode) |
302
+ | `/var/www/<app>/.provisor.json` | App configuration |
303
+ | `/home/<user>/.ssh/deploy_<app>` | Deploy key (private) |
304
+
305
+ ---
306
+
307
+ ## Requirements
308
+
309
+ - Node.js 20+
310
+ - SSH key pair for server access
311
+ - Target server running Debian/Ubuntu
312
+
313
+ ---
314
+
315
+ ## License
316
+
317
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }