shipfe 1.1.0 → 1.1.3
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 +13 -686
- package/bin/shipfe +0 -0
- package/package.json +21 -10
- package/.vscode/settings.json +0 -5
- package/README_CN.md +0 -691
package/README.md
CHANGED
|
@@ -4,711 +4,38 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://github.com/Master-Jian/shipfe-rust)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
一个强大的、**免费**、**基于 Rust** 的 Web 应用部署工具,**不请求网络**,实现**一键前端静态部署包上传到服务器**。支持多环境和子环境部署,具有零停机原子部署功能。
|
|
8
8
|
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
- 🚀 **Free and Open Source**: No hidden costs, MIT licensed
|
|
12
|
-
- 🦀 **Built with Rust**: Fast, reliable, and memory-safe
|
|
13
|
-
- 🔒 **No Network Requests**: Works completely offline, ensuring security and privacy
|
|
14
|
-
- ⚡ **One-Click Deployment**: Upload static frontend packages to servers instantly
|
|
15
|
-
- 🔄 **Atomic Deployments**: Zero-downtime deployments with automatic rollback
|
|
16
|
-
- 🌍 **Multi-Environment Support**: Configure different environments (dev, staging, prod)
|
|
17
|
-
- 📦 **Sub-Environment Support**: Deploy multiple apps to the same server
|
|
18
|
-
- 🔑 **Flexible Authentication**: SSH key, password, or environment variable authentication
|
|
19
|
-
- 📝 **Detailed Logging**: Comprehensive deployment logs for troubleshooting
|
|
20
|
-
- 🗂️ **Shared Asset Management**: Deduplicate hashed static assets across releases
|
|
21
|
-
- 📊 **Resource Snapshot**: Generate deployment snapshots with file manifests
|
|
22
|
-
- 🧹 **Automatic Cleanup**: Configurable retention of old releases and unused assets
|
|
23
|
-
- 🗑️ **Shared Asset Reset**: Automatically clear all shared assets on deployment for clean state
|
|
24
|
-
|
|
25
|
-
## Installation
|
|
9
|
+
## 安装
|
|
26
10
|
|
|
27
11
|
```bash
|
|
28
12
|
npm install -g shipfe
|
|
29
13
|
```
|
|
30
14
|
|
|
31
|
-
##
|
|
15
|
+
## 快速开始
|
|
32
16
|
|
|
33
|
-
1.
|
|
17
|
+
1. 初始化项目:
|
|
34
18
|
```bash
|
|
35
19
|
shipfe init
|
|
36
20
|
```
|
|
37
21
|
|
|
38
|
-
2.
|
|
39
|
-
|
|
40
|
-
3. Deploy:
|
|
41
|
-
```bash
|
|
42
|
-
shipfe deploy --profile prod
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Usage
|
|
46
|
-
|
|
47
|
-
### Initialize project
|
|
48
|
-
```bash
|
|
49
|
-
shipfe init
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Deploy to environment
|
|
53
|
-
```bash
|
|
54
|
-
# Deploy to default environment
|
|
55
|
-
shipfe deploy
|
|
56
|
-
|
|
57
|
-
# Deploy to specific environment
|
|
58
|
-
shipfe deploy --profile dev
|
|
59
|
-
|
|
60
|
-
# Deploy to sub-environment
|
|
61
|
-
shipfe deploy --profile dev-admin
|
|
62
|
-
|
|
63
|
-
# Deploy to all sub-environments
|
|
64
|
-
shipfe deploy --profile dev --all-sub
|
|
65
|
-
|
|
66
|
-
# Atomic deployment (creates releases/timestamp and updates current symlink)
|
|
67
|
-
shipfe deploy --atomic
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Rollback Deployment
|
|
71
|
-
```bash
|
|
72
|
-
# Rollback main environment
|
|
73
|
-
shipfe rollback --profile prod --to 20260303_034945
|
|
74
|
-
|
|
75
|
-
# Rollback sub-environment
|
|
76
|
-
shipfe rollback --profile prod-admin --to 20260303_034945
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Configuration
|
|
80
|
-
|
|
81
|
-
Edit `shipfe.config.json` to configure your deployment settings:
|
|
82
|
-
|
|
83
|
-
```json
|
|
84
|
-
{
|
|
85
|
-
"environments": {
|
|
86
|
-
"dev": {
|
|
87
|
-
"build_command": "npm run build",
|
|
88
|
-
"local_dist_path": "./dist",
|
|
89
|
-
"servers": [
|
|
90
|
-
{
|
|
91
|
-
"host": "dev.example.com",
|
|
92
|
-
"port": 22,
|
|
93
|
-
"username": "deploy",
|
|
94
|
-
"remote_deploy_path": "/var/www/dev"
|
|
95
|
-
}
|
|
96
|
-
],
|
|
97
|
-
"remote_tmp": "/tmp",
|
|
98
|
-
"hashed_asset_patterns": ["assets/"],
|
|
99
|
-
"enable_shared": true,
|
|
100
|
-
"keep_releases": 5,
|
|
101
|
-
"delete_old": false
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
#### Authentication Options
|
|
108
|
-
|
|
109
|
-
Each server can have its own authentication method. Shipfe tries authentication methods in this order:
|
|
110
|
-
|
|
111
|
-
1. **Password** (if `password` is set in server config)
|
|
112
|
-
2. **SSH Private Key from environment** (if `SSH_PRIVATE_KEY` env var is set)
|
|
113
|
-
3. **SSH Key file** (if `key_path` is set in server config)
|
|
114
|
-
|
|
115
|
-
**Example with multiple servers using different auth methods:**
|
|
116
|
-
|
|
117
|
-
```json
|
|
118
|
-
{
|
|
119
|
-
"environments": {
|
|
120
|
-
"prod": {
|
|
121
|
-
"build_command": "npm run build",
|
|
122
|
-
"local_dist_path": "./dist",
|
|
123
|
-
"servers": [
|
|
124
|
-
{
|
|
125
|
-
"host": "web1.prod.com",
|
|
126
|
-
"port": 22,
|
|
127
|
-
"username": "deploy",
|
|
128
|
-
"password": "web1_password",
|
|
129
|
-
"remote_deploy_path": "/var/www/prod"
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
"host": "web2.prod.com",
|
|
133
|
-
"port": 22,
|
|
134
|
-
"username": "deploy",
|
|
135
|
-
"key_path": "/home/user/.ssh/web2_key",
|
|
136
|
-
"remote_deploy_path": "/var/www/prod"
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
"host": "web3.prod.com",
|
|
140
|
-
"port": 22,
|
|
141
|
-
"username": "deploy",
|
|
142
|
-
"remote_deploy_path": "/var/www/prod"
|
|
143
|
-
}
|
|
144
|
-
],
|
|
145
|
-
"remote_tmp": "/tmp",
|
|
146
|
-
"delete_old": false
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
### Sub-environments
|
|
152
|
-
|
|
153
|
-
For deploying multiple applications or different configurations to the same server, use sub-environments:
|
|
154
|
-
|
|
155
|
-
```json
|
|
156
|
-
{
|
|
157
|
-
"environments": {
|
|
158
|
-
"dev": {
|
|
159
|
-
"build_command": "npm run build",
|
|
160
|
-
"local_dist_path": "./dist",
|
|
161
|
-
"servers": [
|
|
162
|
-
{
|
|
163
|
-
"host": "dev.example.com",
|
|
164
|
-
"port": 22,
|
|
165
|
-
"username": "deploy",
|
|
166
|
-
"remote_deploy_path": "/var/www/dev"
|
|
167
|
-
}
|
|
168
|
-
],
|
|
169
|
-
"remote_tmp": "/tmp",
|
|
170
|
-
"hashed_asset_patterns": ["assets/"],
|
|
171
|
-
"enable_shared": true,
|
|
172
|
-
"keep_releases": 5,
|
|
173
|
-
"delete_old": false,
|
|
174
|
-
"sub_environments": {
|
|
175
|
-
"admin": {
|
|
176
|
-
"build_command": "npm run build:admin",
|
|
177
|
-
"remote_deploy_path": "/var/www/dev/admin"
|
|
178
|
-
},
|
|
179
|
-
"shop": {
|
|
180
|
-
"build_command": "npm run build:shop",
|
|
181
|
-
"remote_deploy_path": "/var/www/dev/shop"
|
|
182
|
-
},
|
|
183
|
-
"cu": {
|
|
184
|
-
"build_command": "npm run build:cu",
|
|
185
|
-
"remote_deploy_path": "/var/www/dev/cu"
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
Deploy to sub-environments:
|
|
194
|
-
```bash
|
|
195
|
-
shipfe deploy --profile dev-admin
|
|
196
|
-
shipfe deploy --profile dev-shop
|
|
197
|
-
shipfe deploy --profile dev-cu
|
|
198
|
-
|
|
199
|
-
# Deploy to all sub-environments at once
|
|
200
|
-
shipfe deploy --profile dev --all-sub
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Configuration Details
|
|
204
|
-
|
|
205
|
-
Here are all available configuration options in `shipfe.config.json`:
|
|
206
|
-
|
|
207
|
-
#### Global Configuration Options
|
|
208
|
-
|
|
209
|
-
- **`enable_shared`** (boolean, default: false)
|
|
210
|
-
- Enable shared asset management
|
|
211
|
-
- When enabled, matching files are hashed and stored in a shared directory to avoid re-uploading duplicates
|
|
212
|
-
- Suitable for applications with frequent deployments and many static assets
|
|
213
|
-
|
|
214
|
-
- **`hashed_asset_patterns`** (array of strings, default: [])
|
|
215
|
-
- File patterns for assets that should be hashed and shared
|
|
216
|
-
- Supports glob patterns like `"**/*.js"`, `"**/*.css"`, `"**/*.{png,jpg,svg}"`
|
|
217
|
-
- Only matching files will be hashed and shared; others are uploaded fresh each deployment
|
|
218
|
-
|
|
219
|
-
- **`keep_releases`** (number, default: 10)
|
|
220
|
-
- Number of release versions to keep
|
|
221
|
-
- Older releases beyond this number will be automatically cleaned up
|
|
222
|
-
- Set to 0 to disable automatic cleanup
|
|
223
|
-
|
|
224
|
-
#### Environment Configuration Options
|
|
225
|
-
|
|
226
|
-
Each environment (like `dev`, `prod`) can contain these options:
|
|
227
|
-
|
|
228
|
-
- **`build_command`** (string, required)
|
|
229
|
-
- Local build command, e.g., `"npm run build"` or `"yarn build"`
|
|
230
|
-
|
|
231
|
-
- **`local_dist_path`** (string, required)
|
|
232
|
-
- Local build output directory path, e.g., `"./dist"` or `"./build"`
|
|
233
|
-
|
|
234
|
-
- **`servers`** (array of objects, required)
|
|
235
|
-
- List of servers, each containing:
|
|
236
|
-
- **`host`** (string, required): Server hostname or IP address
|
|
237
|
-
- **`port`** (number, default: 22): SSH port
|
|
238
|
-
- **`username`** (string, required): SSH username
|
|
239
|
-
- **`password`** (string, optional): SSH password (not recommended, use keys instead)
|
|
240
|
-
- **`key_path`** (string, optional): Path to SSH private key file
|
|
241
|
-
- **`remote_deploy_path`** (string, required): Deployment directory path on server
|
|
242
|
-
|
|
243
|
-
- **`remote_tmp`** (string, default: "/tmp")
|
|
244
|
-
- Temporary directory path on server for file uploads
|
|
245
|
-
|
|
246
|
-
- **`sub_environments`** (object, optional)
|
|
247
|
-
- Sub-environment configurations, keyed by sub-environment name
|
|
248
|
-
- Sub-environments inherit parent settings but can override `build_command`, `local_dist_path`, `remote_deploy_path`
|
|
249
|
-
|
|
250
|
-
- **`delete_old`** (boolean, default: false)
|
|
251
|
-
- Delete all old releases after each deployment
|
|
252
|
-
- Keep only the current deployment
|
|
253
|
-
- Overrides `keep_releases` setting
|
|
254
|
-
|
|
255
|
-
#### Shared Assets and Hashing Configuration Explained
|
|
256
|
-
|
|
257
|
-
**How Shared Assets Work:**
|
|
258
|
-
|
|
259
|
-
1. **File Matching**: Files are matched against `hashed_asset_patterns`
|
|
260
|
-
2. **Hash Calculation**: SHA256 hashes are computed for matching files
|
|
261
|
-
3. **Storage Strategy**:
|
|
262
|
-
- Identical files are stored only once in the `shared/assets/` directory
|
|
263
|
-
- Filename format: `{hash}.{ext}`, e.g., `abc123def456.js`
|
|
264
|
-
4. **Link Creation**: Hard links are created in release directories pointing to shared files
|
|
265
|
-
5. **Cleanup**: Shared files no longer referenced by any kept release are removed
|
|
266
|
-
|
|
267
|
-
**Configuration Example with Explanations:**
|
|
268
|
-
|
|
269
|
-
```json
|
|
270
|
-
{
|
|
271
|
-
"enable_shared": true,
|
|
272
|
-
"hashed_asset_patterns": [
|
|
273
|
-
"**/*.js", // Match all JS files
|
|
274
|
-
"**/*.css", // Match all CSS files
|
|
275
|
-
"**/*.{png,jpg}", // Match PNG and JPG files
|
|
276
|
-
"!**/vendor/**" // Exclude vendor directory (if not needed for sharing)
|
|
277
|
-
],
|
|
278
|
-
"keep_releases": 5
|
|
279
|
-
}
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
**When to Use:**
|
|
283
|
-
- **Enable sharing**: Large applications, frequent deployments, many static assets
|
|
284
|
-
- **Disable sharing**: Small applications, infrequent deployments, or need for simple debugging
|
|
285
|
-
|
|
286
|
-
**Important Notes:**
|
|
287
|
-
- Shared assets require filesystem support for hard links
|
|
288
|
-
- On first enable, all matching files will be hashed
|
|
289
|
-
- Disabling sharing doesn't remove existing shared files (manual cleanup required)
|
|
290
|
-
|
|
291
|
-
### Shared Assets Management
|
|
292
|
-
|
|
293
|
-
Shipfe supports deduplication of hashed static assets across releases to save disk space and bandwidth. When `enable_shared` is set to `true`, hashed assets are stored in a shared directory and hard-linked in each release.
|
|
294
|
-
|
|
295
|
-
**Configuration:**
|
|
296
|
-
```json
|
|
297
|
-
{
|
|
298
|
-
"environments": {
|
|
299
|
-
"prod": {
|
|
300
|
-
"enable_shared": true,
|
|
301
|
-
"hashed_asset_patterns": ["assets/"],
|
|
302
|
-
"keep_releases": 5,
|
|
303
|
-
"delete_old": false
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
**How it works:**
|
|
310
|
-
1. **Asset Detection**: Automatically detects hashed files based on:
|
|
311
|
-
- User-defined patterns (e.g., `["assets/", "static/"]`)
|
|
312
|
-
- Filename format: `name-hash.ext` (e.g., `app-abc123.js`, `style-def456.css`)
|
|
313
|
-
|
|
314
|
-
2. **Deduplication Process**:
|
|
315
|
-
- First deployment: Copies hashed assets to `shared/assets/`
|
|
316
|
-
- Subsequent deployments: Creates hard links to existing shared assets
|
|
317
|
-
- Same hash = same file, no duplication
|
|
318
|
-
|
|
319
|
-
3. **Shared Asset Reset**: At the start of each deployment, all existing assets in the `shared/` directory are cleared to ensure a clean state, then `shared/assets/` is recreated.
|
|
320
|
-
|
|
321
|
-
4. **Automatic Cleanup**: Removes unused assets when no longer referenced by any kept release
|
|
322
|
-
|
|
323
|
-
**Benefits:**
|
|
324
|
-
- **Disk Space**: Saves storage by eliminating duplicate hashed files
|
|
325
|
-
- **Bandwidth**: Faster deployments with smaller transfer sizes
|
|
326
|
-
- **Performance**: Hard links provide instant access with minimal overhead
|
|
327
|
-
|
|
328
|
-
**Example Directory Structure:**
|
|
329
|
-
```
|
|
330
|
-
remote_deploy_path/
|
|
331
|
-
├── releases/
|
|
332
|
-
│ ├── 20260304_120000/
|
|
333
|
-
│ │ ├── index.html
|
|
334
|
-
│ │ └── assets/
|
|
335
|
-
│ │ ├── app.js -> ../../../shared/assets/app-abc123.js
|
|
336
|
-
│ │ └── style.css -> ../../../shared/assets/style-def456.css
|
|
337
|
-
│ └── 20260304_120100/
|
|
338
|
-
│ ├── index.html
|
|
339
|
-
│ └── assets/
|
|
340
|
-
│ ├── app.js -> ../../../shared/assets/app-abc123.js (same file)
|
|
341
|
-
│ └── style.css -> ../../../shared/assets/style-ghi789.css (new)
|
|
342
|
-
├── shared/
|
|
343
|
-
│ └── assets/
|
|
344
|
-
│ ├── app-abc123.js
|
|
345
|
-
│ ├── style-def456.css
|
|
346
|
-
│ └── style-ghi789.css
|
|
347
|
-
└── current -> releases/20260304_120100
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
### Automatic Cleanup
|
|
351
|
-
|
|
352
|
-
Shipfe provides configurable automatic cleanup of old releases and unused shared assets to manage disk usage efficiently.
|
|
353
|
-
|
|
354
|
-
**Configuration Options:**
|
|
355
|
-
|
|
356
|
-
1. **`keep_releases`** (recommended):
|
|
357
|
-
```json
|
|
358
|
-
{
|
|
359
|
-
"keep_releases": 5,
|
|
360
|
-
"delete_old": false
|
|
361
|
-
}
|
|
362
|
-
```
|
|
363
|
-
- Keeps the 5 most recent releases
|
|
364
|
-
- Automatically removes older releases
|
|
365
|
-
- Works with shared assets cleanup
|
|
366
|
-
|
|
367
|
-
2. **`delete_old`** (legacy):
|
|
368
|
-
```json
|
|
369
|
-
{
|
|
370
|
-
"delete_old": true
|
|
371
|
-
}
|
|
372
|
-
```
|
|
373
|
-
- Removes ALL old releases after each deployment
|
|
374
|
-
- Only keeps the current deployment
|
|
375
|
-
- Overrides `keep_releases` setting
|
|
376
|
-
|
|
377
|
-
**Cleanup Process:**
|
|
378
|
-
|
|
379
|
-
1. **Release Cleanup**:
|
|
380
|
-
- Sorts releases by modification time (newest first)
|
|
381
|
-
- Keeps specified number of recent releases
|
|
382
|
-
- Removes older release directories completely
|
|
383
|
-
|
|
384
|
-
2. **Shared Assets Cleanup** (when `enable_shared: true`):
|
|
385
|
-
- Scans all remaining release snapshots
|
|
386
|
-
- Collects all currently referenced hashed assets
|
|
387
|
-
- Removes unreferenced files from `shared/assets/`
|
|
388
|
-
|
|
389
|
-
**Example Cleanup Behavior:**
|
|
390
|
-
|
|
391
|
-
**Before cleanup (7 releases):**
|
|
392
|
-
```
|
|
393
|
-
releases/
|
|
394
|
-
├── 20260301_100000/ (oldest)
|
|
395
|
-
├── 20260302_100000/
|
|
396
|
-
├── 20260303_100000/
|
|
397
|
-
├── 20260304_100000/
|
|
398
|
-
├── 20260305_100000/
|
|
399
|
-
├── 20260306_100000/
|
|
400
|
-
└── 20260307_100000/ (newest, current)
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
**After cleanup (`keep_releases: 3`):**
|
|
404
|
-
```
|
|
405
|
-
releases/
|
|
406
|
-
├── 20260305_100000/ (kept)
|
|
407
|
-
├── 20260306_100000/ (kept)
|
|
408
|
-
└── 20260307_100000/ (kept, current)
|
|
409
|
-
```
|
|
410
|
-
*Older releases automatically removed*
|
|
411
|
-
|
|
412
|
-
**Monitoring Cleanup:**
|
|
413
|
-
```bash
|
|
414
|
-
# Check current releases
|
|
415
|
-
ls -la releases/
|
|
416
|
-
|
|
417
|
-
# View cleanup logs in shipfe.log
|
|
418
|
-
tail -f shipfe.log | grep -i "cleanup\|remove"
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
## Configuration Best Practices
|
|
422
|
-
|
|
423
|
-
### For Production Deployments
|
|
424
|
-
|
|
425
|
-
**Recommended Configuration:**
|
|
426
|
-
```json
|
|
427
|
-
{
|
|
428
|
-
"enable_shared": true,
|
|
429
|
-
"keep_releases": 10,
|
|
430
|
-
"hashed_asset_patterns": [
|
|
431
|
-
"**/*.js",
|
|
432
|
-
"**/*.css",
|
|
433
|
-
"**/*.png",
|
|
434
|
-
"**/*.jpg",
|
|
435
|
-
"**/*.svg",
|
|
436
|
-
"**/*.woff2"
|
|
437
|
-
]
|
|
438
|
-
}
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
**Why this works:**
|
|
442
|
-
- Shared assets reduce disk usage by 60-80%
|
|
443
|
-
- 10 releases provide rollback capability
|
|
444
|
-
- Hashed patterns cover common static assets
|
|
445
|
-
- Automatic cleanup prevents disk space issues
|
|
446
|
-
|
|
447
|
-
### For Development/Staging
|
|
448
|
-
|
|
449
|
-
**Recommended Configuration:**
|
|
450
|
-
```json
|
|
451
|
-
{
|
|
452
|
-
"enable_shared": false,
|
|
453
|
-
"keep_releases": 3,
|
|
454
|
-
"delete_old": false
|
|
455
|
-
}
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
**Why this works:**
|
|
459
|
-
- Faster deployments (no asset hashing)
|
|
460
|
-
- Fewer releases to manage
|
|
461
|
-
- Easier debugging without shared assets complexity
|
|
462
|
-
|
|
463
|
-
### For Memory-Constrained Servers
|
|
464
|
-
|
|
465
|
-
**Recommended Configuration:**
|
|
466
|
-
```json
|
|
467
|
-
{
|
|
468
|
-
"enable_shared": true,
|
|
469
|
-
"keep_releases": 2,
|
|
470
|
-
"hashed_asset_patterns": ["**/*.{js,css}"]
|
|
471
|
-
}
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
**Why this works:**
|
|
475
|
-
- Minimal releases reduce storage
|
|
476
|
-
- Only essential assets shared
|
|
477
|
-
- Balances performance and disk usage
|
|
478
|
-
|
|
479
|
-
## Troubleshooting
|
|
480
|
-
|
|
481
|
-
### Common Issues
|
|
482
|
-
|
|
483
|
-
**1. Permission Denied Errors**
|
|
484
|
-
```
|
|
485
|
-
Error: Permission denied (publickey)
|
|
486
|
-
```
|
|
487
|
-
**Solutions:**
|
|
488
|
-
- Verify SSH key is added to `~/.ssh/authorized_keys` on server
|
|
489
|
-
- Check SSH key permissions: `chmod 600 ~/.ssh/id_rsa`
|
|
490
|
-
- Test SSH connection: `ssh user@host`
|
|
491
|
-
|
|
492
|
-
**2. Shared Assets Not Working**
|
|
493
|
-
```
|
|
494
|
-
Warning: Failed to create hard link for shared asset
|
|
495
|
-
```
|
|
496
|
-
**Solutions:**
|
|
497
|
-
- Ensure `enable_shared: true` in config
|
|
498
|
-
- Check server filesystem supports hard links
|
|
499
|
-
- Verify write permissions on shared directory
|
|
500
|
-
|
|
501
|
-
**3. Cleanup Not Working**
|
|
502
|
-
```
|
|
503
|
-
Warning: Failed to remove old release
|
|
504
|
-
```
|
|
505
|
-
**Solutions:**
|
|
506
|
-
- Check file permissions on releases directory
|
|
507
|
-
- Ensure no processes are using old release files
|
|
508
|
-
- Verify `keep_releases` is set correctly
|
|
509
|
-
|
|
510
|
-
**4. Snapshot Creation Fails**
|
|
511
|
-
```
|
|
512
|
-
Error: Failed to create snapshot
|
|
513
|
-
```
|
|
514
|
-
**Solutions:**
|
|
515
|
-
- Check available disk space
|
|
516
|
-
- Verify write permissions on releases directory
|
|
517
|
-
- Ensure tar command is available on server
|
|
518
|
-
|
|
519
|
-
### Debug Mode
|
|
520
|
-
|
|
521
|
-
Enable detailed logging:
|
|
522
|
-
```bash
|
|
523
|
-
shipfe deploy --debug
|
|
524
|
-
```
|
|
525
|
-
|
|
526
|
-
Check logs:
|
|
527
|
-
```bash
|
|
528
|
-
tail -f shipfe.log
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
### Performance Optimization
|
|
532
|
-
|
|
533
|
-
**Slow Deployments:**
|
|
534
|
-
- Enable shared assets for large static files
|
|
535
|
-
- Use `hashed_asset_patterns` to target specific files
|
|
536
|
-
- Consider excluding large non-changing files from patterns
|
|
537
|
-
|
|
538
|
-
**High Disk Usage:**
|
|
539
|
-
- Reduce `keep_releases` count
|
|
540
|
-
- Enable shared assets
|
|
541
|
-
- Use `delete_old: true` for single-release deployments
|
|
542
|
-
|
|
543
|
-
**Network Issues:**
|
|
544
|
-
- Compress large files before deployment
|
|
545
|
-
- Use faster SSH ciphers if supported
|
|
546
|
-
- Consider deploying during off-peak hours
|
|
547
|
-
|
|
548
|
-
### Resource Snapshots
|
|
549
|
-
|
|
550
|
-
Each deployment generates a `shipfe.snapshot.json` file containing the complete manifest of deployed files and hashed assets. This snapshot provides full visibility into what was deployed and enables various operational capabilities.
|
|
551
|
-
|
|
552
|
-
**Example snapshot:**
|
|
553
|
-
```json
|
|
554
|
-
{
|
|
555
|
-
"id": "20260303_035045",
|
|
556
|
-
"timestamp": "2026-03-03T03:50:45Z",
|
|
557
|
-
"files": [
|
|
558
|
-
"index.html",
|
|
559
|
-
"manifest.json",
|
|
560
|
-
"assets/app-abc123.js",
|
|
561
|
-
"assets/style-def456.css",
|
|
562
|
-
"assets/logo.png"
|
|
563
|
-
],
|
|
564
|
-
"hashed_assets": [
|
|
565
|
-
"assets/app-abc123.js",
|
|
566
|
-
"assets/style-def456.css"
|
|
567
|
-
]
|
|
568
|
-
}
|
|
569
|
-
```
|
|
570
|
-
|
|
571
|
-
**Snapshot Fields:**
|
|
572
|
-
- **`id`**: Unique deployment identifier (timestamp-based)
|
|
573
|
-
- **`timestamp`**: ISO 8601 timestamp of deployment
|
|
574
|
-
- **`files`**: Complete list of all deployed files
|
|
575
|
-
- **`hashed_assets`**: Subset of files identified as hashed/cacheable assets
|
|
576
|
-
|
|
577
|
-
**Use Cases:**
|
|
578
|
-
|
|
579
|
-
1. **Deployment Verification**:
|
|
580
|
-
```bash
|
|
581
|
-
# Check what was deployed in a specific release
|
|
582
|
-
cat releases/20260303_035045/shipfe.snapshot.json
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
2. **Asset Inventory**:
|
|
586
|
-
```bash
|
|
587
|
-
# List all hashed assets across all releases
|
|
588
|
-
find releases/ -name "shipfe.snapshot.json" -exec jq -r '.hashed_assets[]' {} \; | sort | uniq
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
3. **Rollback Validation**:
|
|
592
|
-
```bash
|
|
593
|
-
# Verify rollback target has expected assets
|
|
594
|
-
jq '.files[]' releases/20260303_035045/shipfe.snapshot.json
|
|
595
|
-
```
|
|
596
|
-
|
|
597
|
-
4. **Storage Analysis**:
|
|
598
|
-
```bash
|
|
599
|
-
# Calculate deployment sizes
|
|
600
|
-
find releases/20260303_035045/ -type f -exec ls -lh {} \; | awk '{sum += $5} END {print sum}'
|
|
601
|
-
```
|
|
602
|
-
|
|
603
|
-
**Integration with CI/CD:**
|
|
604
|
-
Snapshots enable automated verification in deployment pipelines:
|
|
605
|
-
- Compare deployed files against build artifacts
|
|
606
|
-
- Validate asset integrity post-deployment
|
|
607
|
-
- Generate deployment reports and changelogs
|
|
608
|
-
|
|
609
|
-
### Atomic Deployment
|
|
610
|
-
|
|
611
|
-
Shipfe supports atomic deployment to minimize downtime. When using `--atomic`, the deployment creates a timestamped release directory and updates a `current` symlink for zero-downtime switching.
|
|
22
|
+
2. 在 `shipfe.config.json` 中配置部署
|
|
612
23
|
|
|
24
|
+
3. 部署:
|
|
613
25
|
```bash
|
|
614
|
-
# Atomic deployment to default environment
|
|
615
|
-
shipfe deploy --atomic
|
|
616
|
-
|
|
617
|
-
# Atomic deployment to specific environment
|
|
618
|
-
shipfe deploy --profile prod --atomic
|
|
619
|
-
```
|
|
620
|
-
|
|
621
|
-
**Directory Structure:**
|
|
622
|
-
```
|
|
623
|
-
remote_deploy_path/
|
|
624
|
-
├── releases/
|
|
625
|
-
│ ├── 20260303_034945/
|
|
626
|
-
│ │ ├── index.html
|
|
627
|
-
│ │ ├── assets/
|
|
628
|
-
│ │ │ └── app.js -> ../../../shared/assets/app-abc123.js
|
|
629
|
-
│ │ └── shipfe.snapshot.json
|
|
630
|
-
│ ├── 20260303_035012/
|
|
631
|
-
│ └── 20260303_035045/
|
|
632
|
-
├── shared/
|
|
633
|
-
│ └── assets/
|
|
634
|
-
│ ├── app-abc123.js
|
|
635
|
-
│ └── style-def456.css
|
|
636
|
-
└── current -> releases/20260303_035045
|
|
637
|
-
```
|
|
638
|
-
|
|
639
|
-
Your web server should serve from `remote_deploy_path/current`.
|
|
640
|
-
|
|
641
|
-
**Or use environment variable for all servers:**
|
|
642
|
-
```bash
|
|
643
|
-
export SSH_PRIVATE_KEY="$(cat ~/.ssh/prod_key)"
|
|
644
|
-
shipfe deploy --profile prod
|
|
645
|
-
```
|
|
646
|
-
|
|
647
|
-
### Authentication
|
|
648
|
-
|
|
649
|
-
Shipfe supports multiple SSH authentication methods for each server individually. For each server, authentication methods are tried in this order:
|
|
650
|
-
|
|
651
|
-
1. **Password authentication**: If `password` is set in that server's config
|
|
652
|
-
2. **SSH Private Key from environment**: If `SSH_PRIVATE_KEY` environment variable is set (applies to all servers)
|
|
653
|
-
3. **SSH Key file**: If `key_path` is set in that server's config
|
|
654
|
-
|
|
655
|
-
#### Usage Examples:
|
|
656
|
-
|
|
657
|
-
```bash
|
|
658
|
-
# Each server can use different authentication
|
|
659
|
-
shipfe deploy --profile prod
|
|
660
|
-
|
|
661
|
-
# Or override with environment variable for all servers
|
|
662
|
-
export SSH_PRIVATE_KEY="$(cat ~/.ssh/prod_key)"
|
|
663
26
|
shipfe deploy --profile prod
|
|
664
27
|
```
|
|
665
28
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
1. **Generate SSH key pairs** for each server:
|
|
669
|
-
```bash
|
|
670
|
-
# For server 1
|
|
671
|
-
ssh-keygen -t rsa -b 4096 -f ~/.ssh/server1_key -C "server1"
|
|
672
|
-
|
|
673
|
-
# For server 2
|
|
674
|
-
ssh-keygen -t rsa -b 4096 -f ~/.ssh/server2_key -C "server2"
|
|
675
|
-
```
|
|
676
|
-
|
|
677
|
-
2. **Copy public keys to respective servers**:
|
|
678
|
-
```bash
|
|
679
|
-
ssh-copy-id -i ~/.ssh/server1_key.pub user@server1.com
|
|
680
|
-
ssh-copy-id -i ~/.ssh/server2_key.pub user@server2.com
|
|
681
|
-
```
|
|
29
|
+
## 文档
|
|
682
30
|
|
|
683
|
-
|
|
684
|
-
```json
|
|
685
|
-
{
|
|
686
|
-
"servers": [
|
|
687
|
-
{
|
|
688
|
-
"host": "server1.com",
|
|
689
|
-
"key_path": "~/.ssh/server1_key"
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
"host": "server2.com",
|
|
693
|
-
"key_path": "~/.ssh/server2_key"
|
|
694
|
-
}
|
|
695
|
-
]
|
|
696
|
-
}
|
|
697
|
-
```
|
|
31
|
+
📖 [完整文档](https://master-jian.github.io/shipfe-rust/)
|
|
698
32
|
|
|
699
|
-
##
|
|
33
|
+
## 常用命令
|
|
700
34
|
|
|
701
|
-
-
|
|
702
|
-
-
|
|
703
|
-
-
|
|
704
|
-
- SSH-based deployment
|
|
705
|
-
- Automatic backup and rollback
|
|
706
|
-
- Detailed logging
|
|
707
|
-
- Shared asset deduplication
|
|
708
|
-
- Resource snapshot generation
|
|
709
|
-
- Configurable release retention
|
|
710
|
-
- Automatic cleanup of unused assets
|
|
35
|
+
- `shipfe deploy --profile <env>` - 部署到指定环境
|
|
36
|
+
- `shipfe deploy --atomic` - 原子部署
|
|
37
|
+
- `shipfe rollback --profile <env> --to <timestamp>` - 回滚到指定版本
|
|
711
38
|
|
|
712
|
-
##
|
|
39
|
+
## 许可证
|
|
713
40
|
|
|
714
41
|
MIT
|