kdeploy 0.2.0 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +122 -318
- data/exe/kdeploy +6 -0
- data/k.md +149 -0
- data/lib/kdeploy/banner.rb +44 -14
- data/lib/kdeploy/cli.rb +179 -1395
- data/lib/kdeploy/dsl.rb +62 -530
- data/lib/kdeploy/executor.rb +73 -0
- data/lib/kdeploy/initializer.rb +229 -0
- data/lib/kdeploy/runner.rb +40 -180
- data/lib/kdeploy/template.rb +19 -161
- data/lib/kdeploy/version.rb +1 -2
- data/lib/kdeploy.rb +9 -100
- metadata +74 -52
- data/.editorconfig +0 -12
- data/.rspec +0 -3
- data/.rubocop.yml +0 -100
- data/LICENSE +0 -21
- data/README_CN.md +0 -1030
- data/Rakefile +0 -46
- data/bin/kdeploy +0 -7
- data/kdeploy.gemspec +0 -49
- data/lib/kdeploy/command.rb +0 -182
- data/lib/kdeploy/configuration.rb +0 -83
- data/lib/kdeploy/host.rb +0 -85
- data/lib/kdeploy/inventory.rb +0 -243
- data/lib/kdeploy/logger.rb +0 -100
- data/lib/kdeploy/pipeline.rb +0 -249
- data/lib/kdeploy/ssh_connection.rb +0 -187
- data/lib/kdeploy/statistics.rb +0 -439
- data/lib/kdeploy/task.rb +0 -240
- data/scripts/common_tasks.rb +0 -218
- data/scripts/deploy.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13ad6844e1610898cc64413ee752b17e5b0c83e75b3f503abe73681c79be3bc4
|
4
|
+
data.tar.gz: 2fda0c6eb62f2a2ac9a592cce564769d950a7b2f88510f1c251f0dcaceccca86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bb78e52644c736b6d9f6a18e506de11e2c331e464a19f9d09c7f4da334d7efb464a8875bac9375717b9cec7a3ed5a42fe68e968d68fb30c2c40ceea9a4aa20e
|
7
|
+
data.tar.gz: 6654fae1a9d1eb08b45a790bb12d08050350148069080a848e48cdb921f7b593a5d77d5f5cb50e8605c9a55417aaacc596eb21f3a96ec1369167bcb00aed2af5
|
data/README.md
CHANGED
@@ -1,43 +1,17 @@
|
|
1
1
|
# Kdeploy
|
2
2
|
|
3
|
-
|
4
|
-
_ _
|
5
|
-
/\ /\__| | ___ _ __ | | ___ _ _
|
6
|
-
/ //_/ _` |/ _ \ '_ \| |/ _ \| | | |
|
7
|
-
/ __ \ (_| | __/ |_) | | (_) | |_| |
|
8
|
-
\/ \/\__,_|\___| .__/|_|\___/ \__, |
|
9
|
-
|_| |___/
|
10
|
-
|
11
|
-
⚡ Lightweight Agentless Deployment Tool
|
12
|
-
🚀 Deploy with confidence, scale with ease
|
13
|
-
```
|
3
|
+
A lightweight agentless deployment automation tool written in Ruby.
|
14
4
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
-
|
25
|
-
- 🎨 **Modern Interface**: Beautiful ASCII art and colored output interface
|
26
|
-
- 🔧 **DSL Syntax**: Concise and elegant Ruby DSL configuration syntax
|
27
|
-
- ⚡ **Concurrent Execution**: Support for multi-host parallel operations and intelligent concurrency control
|
28
|
-
- 🛠️ **Batch Operations**: Efficient batch Shell command execution
|
29
|
-
- 🔒 **Secure Connection**: SSH-based secure connections with key authentication
|
30
|
-
- 📝 **Real-time Output**: Command execution results with real-time display and detailed timing statistics
|
31
|
-
- 🎯 **Role Management**: Flexible role-based host grouping management
|
32
|
-
- 📋 **Inventory Management**: Powerful YAML format host inventory with group and variable inheritance
|
33
|
-
- 🧩 **Heredoc Syntax**: Support for multi-line Shell scripts using heredoc syntax
|
34
|
-
- 🎨 **ERB Templates**: Built-in ERB template engine for dynamic configuration file generation
|
35
|
-
- 🏷️ **Variable Substitution**: Support for both `{{variable}}` and `${variable}` template syntax
|
36
|
-
- 🖥️ **Mixed Execution**: Support for local command execution and hybrid deployment scenarios
|
37
|
-
- 📊 **Statistics Analysis**: Automatic deployment statistics collection with performance analysis and trend monitoring
|
38
|
-
- 🔄 **Script Library**: Rich pre-made script templates covering the complete deployment lifecycle
|
39
|
-
- 🧩 **Modular Architecture**: Support for modular script organization with reusable task components
|
40
|
-
- 🛡️ **Error Recovery**: Intelligent error handling and automatic retry mechanism
|
5
|
+
## 🌟 Features
|
6
|
+
|
7
|
+
- 🔑 **Agentless Remote Deployment**: Uses SSH for secure remote execution
|
8
|
+
- 📝 **Elegant Ruby DSL**: Simple and expressive task definition
|
9
|
+
- 🚀 **Concurrent Execution**: Efficient parallel task processing
|
10
|
+
- 📤 **File Upload Support**: Easy file and template deployment
|
11
|
+
- 📊 **Task Status Tracking**: Real-time execution monitoring
|
12
|
+
- 🔄 **ERB Template Support**: Dynamic configuration generation
|
13
|
+
- 🎯 **Role-based Deployment**: Target specific server roles
|
14
|
+
- 🔍 **Dry Run Mode**: Preview tasks before execution
|
41
15
|
|
42
16
|
## 📦 Installation
|
43
17
|
|
@@ -47,345 +21,175 @@ Add this line to your application's Gemfile:
|
|
47
21
|
gem 'kdeploy'
|
48
22
|
```
|
49
23
|
|
50
|
-
|
24
|
+
And then execute:
|
51
25
|
|
52
26
|
```bash
|
53
|
-
bundle install
|
27
|
+
$ bundle install
|
54
28
|
```
|
55
29
|
|
56
|
-
Or install it
|
30
|
+
Or install it yourself as:
|
57
31
|
|
58
32
|
```bash
|
59
|
-
gem install kdeploy
|
33
|
+
$ gem install kdeploy
|
60
34
|
```
|
61
35
|
|
62
36
|
## 🚀 Quick Start
|
63
37
|
|
64
|
-
|
38
|
+
1. Initialize a new project:
|
65
39
|
|
66
40
|
```bash
|
67
|
-
kdeploy init
|
68
|
-
cd myapp
|
41
|
+
$ kdeploy init my-deployment
|
69
42
|
```
|
70
43
|
|
71
|
-
|
44
|
+
2. Edit the deployment configuration:
|
72
45
|
|
73
|
-
```
|
74
|
-
|
75
|
-
├── deploy.rb # Main deployment script
|
76
|
-
├── inventory.yml # Host inventory configuration
|
77
|
-
├── config/ # Configuration directory
|
78
|
-
│ └── kdeploy.yml # Global configuration file
|
79
|
-
├── scripts/ # 🆕 Complete script library
|
80
|
-
│ ├── common_tasks.rb # 🆕 Common task module (reusable)
|
81
|
-
│ ├── setup.rb # Server initialization
|
82
|
-
│ ├── database.rb # Database management
|
83
|
-
│ ├── backup.rb # Backup operations
|
84
|
-
│ ├── monitoring.rb # Monitoring and health checks
|
85
|
-
│ ├── rollback.rb # Rollback operations
|
86
|
-
│ └── cleanup.rb # Cleanup maintenance
|
87
|
-
└── templates/ # ERB template files
|
88
|
-
├── nginx.conf.erb # Nginx configuration template
|
89
|
-
├── app.service.erb # Systemd service template
|
90
|
-
├── deploy.sh.erb # Deployment script template
|
91
|
-
└── backup.sh.erb # Backup script template
|
92
|
-
```
|
93
|
-
|
94
|
-
### 2. Configure Server Inventory
|
95
|
-
|
96
|
-
Edit `inventory.yml` to configure host inventory:
|
97
|
-
|
98
|
-
```yaml
|
99
|
-
# Global variables
|
100
|
-
vars:
|
101
|
-
application: myapp
|
102
|
-
version: 1.0.0
|
103
|
-
deploy_to: /opt/myapp
|
104
|
-
environment: production
|
105
|
-
|
106
|
-
# Host groups
|
107
|
-
groups:
|
108
|
-
webservers:
|
109
|
-
hosts:
|
110
|
-
- web1.example.com
|
111
|
-
- web2.example.com
|
112
|
-
vars:
|
113
|
-
nginx_port: 80
|
114
|
-
app_port: 3000
|
115
|
-
|
116
|
-
databases:
|
117
|
-
hosts:
|
118
|
-
- db1.example.com
|
119
|
-
vars:
|
120
|
-
postgres_port: 5432
|
121
|
-
backup_enabled: true
|
122
|
-
|
123
|
-
production:
|
124
|
-
children:
|
125
|
-
- webservers
|
126
|
-
- databases
|
127
|
-
vars:
|
128
|
-
environment: production
|
129
|
-
|
130
|
-
# Host configurations
|
131
|
-
hosts:
|
132
|
-
web1.example.com:
|
133
|
-
user: deploy
|
134
|
-
port: 22
|
135
|
-
roles: [web, app]
|
136
|
-
ssh:
|
137
|
-
key_file: ~/.ssh/id_rsa
|
138
|
-
verify_host_key: false
|
139
|
-
vars:
|
140
|
-
server_id: 1
|
141
|
-
|
142
|
-
web2.example.com:
|
143
|
-
user: deploy
|
144
|
-
port: 22
|
145
|
-
roles: [web, app]
|
146
|
-
ssh:
|
147
|
-
key_file: ~/.ssh/id_rsa
|
148
|
-
verify_host_key: false
|
149
|
-
vars:
|
150
|
-
server_id: 2
|
151
|
-
|
152
|
-
db1.example.com:
|
153
|
-
user: deploy
|
154
|
-
port: 22
|
155
|
-
roles: [database]
|
156
|
-
ssh:
|
157
|
-
key_file: ~/.ssh/id_rsa
|
158
|
-
verify_host_key: false
|
159
|
-
vars:
|
160
|
-
server_id: 3
|
161
|
-
master: true
|
162
|
-
```
|
46
|
+
```ruby
|
47
|
+
# deploy.rb
|
163
48
|
|
164
|
-
|
49
|
+
# Define hosts
|
50
|
+
host "web01", user: "ubuntu", ip: "10.0.0.1", key: "~/.ssh/id_rsa"
|
51
|
+
host "web02", user: "ubuntu", ip: "10.0.0.2", key: "~/.ssh/id_rsa"
|
165
52
|
|
166
|
-
|
53
|
+
# Define roles
|
54
|
+
role :web, %w[web01 web02]
|
167
55
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
56
|
+
# Define tasks
|
57
|
+
task :deploy, roles: :web do
|
58
|
+
run "sudo systemctl stop nginx"
|
59
|
+
upload_template "./config/nginx.conf.erb", "/etc/nginx/nginx.conf",
|
60
|
+
domain_name: "example.com",
|
61
|
+
port: 3000
|
62
|
+
run "sudo systemctl start nginx"
|
63
|
+
end
|
172
64
|
```
|
173
65
|
|
174
|
-
|
175
|
-
```bash
|
176
|
-
# Database operations
|
177
|
-
kdeploy deploy scripts/database.rb # Create database, migrate, backup
|
178
|
-
```
|
66
|
+
3. Run the deployment:
|
179
67
|
|
180
|
-
#### 🚀 Application Deployment
|
181
68
|
```bash
|
182
|
-
|
183
|
-
kdeploy deploy deploy.rb
|
69
|
+
$ kdeploy execute deploy.rb
|
184
70
|
```
|
185
71
|
|
186
|
-
|
187
|
-
```bash
|
188
|
-
# System and application health checks
|
189
|
-
kdeploy deploy scripts/monitoring.rb
|
190
|
-
```
|
72
|
+
## 📖 Usage Guide
|
191
73
|
|
192
|
-
|
193
|
-
```bash
|
194
|
-
# Application and data backup
|
195
|
-
kdeploy deploy scripts/backup.rb
|
196
|
-
```
|
197
|
-
|
198
|
-
#### 🔙 Rollback Operations
|
199
|
-
```bash
|
200
|
-
# Emergency rollback and recovery
|
201
|
-
kdeploy deploy scripts/rollback.rb
|
202
|
-
```
|
203
|
-
|
204
|
-
#### 🧹 Cleanup Maintenance
|
205
|
-
```bash
|
206
|
-
# System cleanup and maintenance
|
207
|
-
kdeploy deploy scripts/cleanup.rb
|
208
|
-
```
|
74
|
+
### Host Definition
|
209
75
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
76
|
+
```ruby
|
77
|
+
# Single host
|
78
|
+
host "web01",
|
79
|
+
user: "ubuntu",
|
80
|
+
ip: "10.0.0.1",
|
81
|
+
key: "~/.ssh/id_rsa"
|
214
82
|
|
215
|
-
#
|
216
|
-
|
83
|
+
# Multiple hosts
|
84
|
+
%w[web01 web02 web03].each do |name|
|
85
|
+
host name,
|
86
|
+
user: "ubuntu",
|
87
|
+
ip: "10.0.0.#{name[-1]}",
|
88
|
+
key: "~/.ssh/id_rsa"
|
89
|
+
end
|
217
90
|
```
|
218
91
|
|
219
|
-
###
|
220
|
-
|
221
|
-
```bash
|
222
|
-
# 1. Validate configuration
|
223
|
-
kdeploy validate deploy.rb
|
224
|
-
|
225
|
-
# 2. First-time server setup
|
226
|
-
kdeploy deploy scripts/setup.rb
|
227
|
-
|
228
|
-
# 3. Setup database
|
229
|
-
kdeploy deploy scripts/database.rb
|
92
|
+
### Role Management
|
230
93
|
|
231
|
-
|
232
|
-
|
94
|
+
```ruby
|
95
|
+
# Define roles
|
96
|
+
role :web, %w[web01 web02]
|
97
|
+
role :db, %w[db01 db02]
|
98
|
+
role :all, %w[web01 web02 db01 db02]
|
233
99
|
|
234
|
-
#
|
235
|
-
|
100
|
+
# Use roles in tasks
|
101
|
+
task :deploy_web, roles: :web do
|
102
|
+
# Tasks for web servers
|
103
|
+
end
|
236
104
|
|
237
|
-
|
238
|
-
|
105
|
+
task :backup_db, roles: :db do
|
106
|
+
# Tasks for database servers
|
107
|
+
end
|
239
108
|
```
|
240
109
|
|
241
|
-
|
242
|
-
|
243
|
-
Kdeploy provides powerful built-in statistics functionality that automatically tracks all deployment activities:
|
244
|
-
|
245
|
-
### 📈 Automatically Collected Statistics
|
246
|
-
|
247
|
-
- ✅ **Success/Failure Statistics**: Success rates at deployment, task, and command levels
|
248
|
-
- ⏱️ **Performance Metrics**: Detailed execution time and performance data
|
249
|
-
- 📅 **Historical Trends**: Performance trend analysis grouped by date
|
250
|
-
- 🎯 **Failure Analysis**: Identify most common failing tasks and error patterns
|
251
|
-
- 🌍 **Global Statistics**: Cumulative statistics across sessions
|
252
|
-
|
253
|
-
### 🔍 Statistics Commands
|
254
|
-
|
255
|
-
```bash
|
256
|
-
# View statistics summary
|
257
|
-
kdeploy stats summary
|
110
|
+
### Task Definition
|
258
111
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
# View failure statistics
|
266
|
-
kdeploy stats failures
|
112
|
+
```ruby
|
113
|
+
# Basic task
|
114
|
+
task :simple do
|
115
|
+
run "echo 'Hello, World!'"
|
116
|
+
end
|
267
117
|
|
268
|
-
#
|
269
|
-
|
118
|
+
# Role-based task
|
119
|
+
task :deploy, roles: :web do
|
120
|
+
run "sudo systemctl stop nginx"
|
121
|
+
upload "./config/nginx.conf", "/etc/nginx/nginx.conf"
|
122
|
+
run "sudo systemctl start nginx"
|
123
|
+
end
|
270
124
|
|
271
|
-
#
|
272
|
-
|
125
|
+
# Host-specific task
|
126
|
+
task :maintenance, on: %w[web01] do
|
127
|
+
run "sudo apt-get update"
|
128
|
+
run "sudo apt-get upgrade -y"
|
129
|
+
end
|
130
|
+
```
|
273
131
|
|
274
|
-
|
275
|
-
kdeploy stats export --export monthly_report.json
|
132
|
+
### Template Support
|
276
133
|
|
277
|
-
|
278
|
-
kdeploy stats clear
|
134
|
+
Create an ERB template (`config/nginx.conf.erb`):
|
279
135
|
|
280
|
-
|
281
|
-
|
136
|
+
```erb
|
137
|
+
server {
|
138
|
+
listen 80;
|
139
|
+
server_name <%= domain_name %>;
|
282
140
|
|
283
|
-
|
284
|
-
|
141
|
+
location / {
|
142
|
+
proxy_pass http://localhost:<%= port %>;
|
143
|
+
proxy_set_header Host $host;
|
144
|
+
proxy_set_header X-Real-IP $remote_addr;
|
145
|
+
}
|
146
|
+
}
|
285
147
|
```
|
286
148
|
|
287
|
-
|
149
|
+
Use the template in your task:
|
288
150
|
|
289
|
-
```
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
📦 Deployment Summary:
|
296
|
-
Total Deployments: 15
|
297
|
-
Successful: 13 (86.7%)
|
298
|
-
Failed: 2 (13.3%)
|
299
|
-
Average Duration: 45.2s
|
300
|
-
|
301
|
-
🔧 Task Summary:
|
302
|
-
Total Tasks: 89
|
303
|
-
Successful: 84 (94.4%)
|
304
|
-
Failed: 5 (5.6%)
|
305
|
-
Average Duration: 12.8s
|
306
|
-
|
307
|
-
🌍 Global Statistics:
|
308
|
-
Total Deployments: 156
|
309
|
-
Session Duration: 2h 34m
|
310
|
-
Most Active Day: 2025-06-28 (8 deployments)
|
151
|
+
```ruby
|
152
|
+
task :deploy_config do
|
153
|
+
upload_template "./config/nginx.conf.erb", "/etc/nginx/sites-available/myapp.conf",
|
154
|
+
domain_name: "example.com",
|
155
|
+
port: 3000
|
156
|
+
end
|
311
157
|
```
|
312
158
|
|
313
|
-
|
314
|
-
|
315
|
-
### Common Issues
|
316
|
-
|
317
|
-
1. **SSH Connection Failed**
|
318
|
-
```bash
|
319
|
-
# Check SSH connection
|
320
|
-
ssh -vvv user@hostname
|
321
|
-
|
322
|
-
# Verify keys
|
323
|
-
ssh-add -l
|
324
|
-
```
|
325
|
-
|
326
|
-
2. **Permission Issues**
|
327
|
-
```ruby
|
328
|
-
# Use sudo for commands
|
329
|
-
run 'sudo systemctl restart nginx'
|
330
|
-
|
331
|
-
# Check file permissions
|
332
|
-
run 'ls -la {{deploy_to}}'
|
333
|
-
```
|
334
|
-
|
335
|
-
3. **Timeout Issues**
|
336
|
-
```ruby
|
337
|
-
# Increase timeout
|
338
|
-
run 'long_command', timeout: 300
|
339
|
-
|
340
|
-
# Or set in configuration file
|
341
|
-
command_timeout: 600
|
342
|
-
```
|
343
|
-
|
344
|
-
### Debugging Tips
|
159
|
+
### Command Line Options
|
345
160
|
|
346
161
|
```bash
|
347
|
-
#
|
348
|
-
kdeploy deploy
|
349
|
-
|
350
|
-
# Dry run mode
|
351
|
-
kdeploy deploy script.rb --dry-run
|
162
|
+
# Execute with dry run
|
163
|
+
kdeploy execute deploy.rb --dry-run
|
352
164
|
|
353
|
-
#
|
354
|
-
kdeploy
|
165
|
+
# Limit to specific hosts
|
166
|
+
kdeploy execute deploy.rb --limit web01,web02
|
355
167
|
|
356
|
-
#
|
357
|
-
kdeploy
|
168
|
+
# Set parallel execution count
|
169
|
+
kdeploy execute deploy.rb --parallel 5
|
358
170
|
|
359
|
-
#
|
360
|
-
|
171
|
+
# Execute specific task
|
172
|
+
kdeploy execute deploy.rb deploy_web
|
361
173
|
```
|
362
174
|
|
363
|
-
##
|
364
|
-
|
365
|
-
We welcome community contributions! Please follow these guidelines:
|
366
|
-
|
367
|
-
1. Fork the project
|
368
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
369
|
-
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
370
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
371
|
-
5. Create a Pull Request
|
175
|
+
## 🔧 Development
|
372
176
|
|
373
|
-
|
177
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
374
178
|
|
375
|
-
|
179
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
376
180
|
|
377
|
-
##
|
181
|
+
## 🤝 Contributing
|
378
182
|
|
379
|
-
|
380
|
-
-
|
381
|
-
-
|
382
|
-
|
183
|
+
1. Fork it
|
184
|
+
2. Create your feature branch (`git checkout -b feature/my-new-feature`)
|
185
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
186
|
+
4. Push to the branch (`git push origin feature/my-new-feature`)
|
187
|
+
5. Create a new Pull Request
|
383
188
|
|
384
|
-
##
|
189
|
+
## 📝 License
|
385
190
|
|
386
|
-
|
387
|
-
- GitHub Discussions: [Community Discussions](https://github.com/kevin197011/kdeploy/discussions)
|
191
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
388
192
|
|
389
|
-
|
193
|
+
## 🔍 Code of Conduct
|
390
194
|
|
391
|
-
|
195
|
+
Everyone interacting in the Kdeploy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kdeploy/blob/main/CODE_OF_CONDUCT.md).
|
data/exe/kdeploy
ADDED
data/k.md
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
以下是将 Kdeploy 项目的开发需求整理成的标准 Markdown 格式文档,可保存为 `dev_requirements.md`:
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
```markdown
|
6
|
+
# 📦 Kdeploy 开发需求文档
|
7
|
+
|
8
|
+
> **项目名称**:Kdeploy
|
9
|
+
> **项目类型**:Ruby Gem
|
10
|
+
> **定位**:轻量级 agentless 运维部署工具
|
11
|
+
> **灵感来源**:Ansible、Chef、Puppet
|
12
|
+
> **目标用户**:DevOps、SRE、系统运维工程师
|
13
|
+
|
14
|
+
---
|
15
|
+
|
16
|
+
## 🧭 项目目标
|
17
|
+
|
18
|
+
- 提供 **无 agent** 的远程部署解决方案
|
19
|
+
- 使用 **优雅的 Ruby DSL** 编写部署任务
|
20
|
+
- 支持任务的 **并发执行**
|
21
|
+
- 能够进行任务 **状态统计与结果输出**
|
22
|
+
- 管理 **完整的部署生命周期**(准备、执行、清理、回滚等)
|
23
|
+
- 简洁、轻量、便于嵌入其他工具链
|
24
|
+
- 可支持 **多主机、多环境配置管理**
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## 📁 项目结构
|
29
|
+
|
30
|
+
```
|
31
|
+
|
32
|
+
kdeploy/
|
33
|
+
├── bin/
|
34
|
+
│ └── kdeploy # 主执行文件
|
35
|
+
├── lib/
|
36
|
+
│ ├── kdeploy/
|
37
|
+
│ │ ├── dsl.rb # DSL 定义
|
38
|
+
│ │ ├── executor.rb # 并发执行器
|
39
|
+
│ │ ├── inventory.rb # 主机清单管理
|
40
|
+
│ │ ├── lifecycle.rb # 生命周期管理
|
41
|
+
│ │ ├── logger.rb # 日志与输出
|
42
|
+
│ │ └── version.rb
|
43
|
+
│ └── kdeploy.rb # 主入口
|
44
|
+
├── tasks/
|
45
|
+
│ └── deploy.rb # 示例任务(用户自定义)
|
46
|
+
├── spec/
|
47
|
+
│ └── kdeploy\_spec.rb # RSpec 测试
|
48
|
+
├── kdeploy.gemspec
|
49
|
+
└── README.md
|
50
|
+
|
51
|
+
````
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
## 🔧 功能模块设计
|
56
|
+
|
57
|
+
### 1. DSL 任务定义
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
host 'web01', user: 'ubuntu', ip: '10.0.0.1'
|
61
|
+
|
62
|
+
task :deploy_web do
|
63
|
+
run 'sudo systemctl stop nginx'
|
64
|
+
upload './nginx.conf', '/etc/nginx/nginx.conf'
|
65
|
+
run 'sudo systemctl start nginx'
|
66
|
+
end
|
67
|
+
````
|
68
|
+
|
69
|
+
### 2. 并发执行器
|
70
|
+
|
71
|
+
* 线程池并发执行远程任务
|
72
|
+
* 自动记录成功/失败状态
|
73
|
+
* 支持最大并发数限制
|
74
|
+
|
75
|
+
### 3. 生命周期管理
|
76
|
+
|
77
|
+
* `prepare`:初始化(如环境检查)
|
78
|
+
* `run`:主要任务执行
|
79
|
+
* `cleanup`:清理临时文件或状态
|
80
|
+
* `rollback`:失败回滚(可选)
|
81
|
+
|
82
|
+
### 4. 主机清单
|
83
|
+
|
84
|
+
支持静态或动态清单,如:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
inventory do
|
88
|
+
host 'web01', user: 'ubuntu', ip: '10.0.0.1'
|
89
|
+
host 'db01', user: 'root', ip: '10.0.0.2'
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
### 5. 输出日志与状态统计
|
94
|
+
|
95
|
+
* 控制台美化输出(使用 `pastel`、`tty-table` 等)
|
96
|
+
* 最终报告:执行成功/失败主机、任务耗时、回滚信息等
|
97
|
+
|
98
|
+
---
|
99
|
+
|
100
|
+
## 🖥️ 命令行工具设计
|
101
|
+
|
102
|
+
执行文件:`bin/kdeploy`
|
103
|
+
|
104
|
+
```bash
|
105
|
+
kdeploy run tasks/deploy.rb --limit web01,web02 --parallel 5 --dry-run
|
106
|
+
```
|
107
|
+
|
108
|
+
| 参数 | 说明 |
|
109
|
+
| ------------- | ------------- |
|
110
|
+
| `run` | 执行某个 DSL 任务文件 |
|
111
|
+
| `--limit` | 限定主机 |
|
112
|
+
| `--parallel` | 设置并发线程数 |
|
113
|
+
| `--dry-run` | 预览任务,不真正执行 |
|
114
|
+
| `--rollback` | 启动回滚 |
|
115
|
+
| `--inventory` | 使用特定主机清单文件 |
|
116
|
+
|
117
|
+
---
|
118
|
+
|
119
|
+
## 🧩 可扩展性设计
|
120
|
+
|
121
|
+
* 支持插件机制:可注册自定义任务类型
|
122
|
+
* 可支持其他协议(如 WinRM、Docker、Kubernetes 等)
|
123
|
+
* 日后可支持多环境配置(dev/stage/prod)
|
124
|
+
* 支持本地/远程日志聚合
|
125
|
+
|
126
|
+
---
|
127
|
+
|
128
|
+
## 📦 开发计划建议
|
129
|
+
|
130
|
+
| 阶段 | 内容 |
|
131
|
+
| ---------- | ----------------------------------------- |
|
132
|
+
| 1️⃣ 初始化 | 使用 `bundle gem .` 生成项目骨架,添加执行文件 |
|
133
|
+
| 2️⃣ DSL 实现 | 定义基本任务语法(`host`, `task`, `run`, `upload`) |
|
134
|
+
| 3️⃣ SSH 执行 | 实现基础 SSH 执行器(使用 `net-ssh`) |
|
135
|
+
| 4️⃣ 并发执行 | 引入线程池或 `concurrent-ruby` |
|
136
|
+
| 5️⃣ 生命周期 | 支持 prepare/run/cleanup/rollback 阶段 |
|
137
|
+
| 6️⃣ 状态统计 | 记录执行状态并输出汇总表 |
|
138
|
+
| 7️⃣ CLI 工具 | 实现 `bin/kdeploy` 命令入口 |
|
139
|
+
| 8️⃣ 测试与发布 | 使用 RSpec 添加测试,推送到 RubyGems |
|
140
|
+
|
141
|
+
---
|
142
|
+
|
143
|
+
## 📝 初始化命令
|
144
|
+
|
145
|
+
```bash
|
146
|
+
bundle gem . --test=rspec --mit --coc --no-ext
|
147
|
+
```
|
148
|
+
|
149
|
+
|