kdeploy 0.3.0 → 0.5.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 +33 -16
- data/exe/kdeploy +2 -2
- data/lib/kdeploy/cli.rb +42 -7
- data/lib/kdeploy/dsl.rb +6 -10
- data/lib/kdeploy/initializer.rb +61 -31
- data/lib/kdeploy/template.rb +1 -0
- data/lib/kdeploy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e4e44b572cceb902d9267bfac535bceffcb116b0e5ef8f4de78aafece8dfead
|
4
|
+
data.tar.gz: c57baa1fccd958c63f60253c682c975bb993f6cc5802ac73d96ed797aea527cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a194eb2b3b5f89853493f4ec34e0053db6c1ae25dddeca768bedc9809eb51ad138aafce09c0bcd3f80a43c5872ad02b57b98bfbc0a0f324634a7015425d037a
|
7
|
+
data.tar.gz: 97880efd10a46ac87bec1de2312d338ddb2603eac34610e4cd17cd505f7dc8648844b001a37e95633b9410b08f3f55aaa887f11e888d0ea8bf5a66a64451c730
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@ A lightweight agentless deployment automation tool written in Ruby.
|
|
12
12
|
- 🔄 **ERB Template Support**: Dynamic configuration generation
|
13
13
|
- 🎯 **Role-based Deployment**: Target specific server roles
|
14
14
|
- 🔍 **Dry Run Mode**: Preview tasks before execution
|
15
|
+
- 🎨 **Color-coded Output**: Green for success, Red for errors, Yellow for warnings
|
15
16
|
|
16
17
|
## 📦 Installation
|
17
18
|
|
@@ -66,11 +67,43 @@ end
|
|
66
67
|
3. Run the deployment:
|
67
68
|
|
68
69
|
```bash
|
70
|
+
# Execute all tasks in deploy.rb
|
69
71
|
$ kdeploy execute deploy.rb
|
72
|
+
|
73
|
+
# Execute a specific task
|
74
|
+
$ kdeploy execute deploy.rb deploy_web
|
70
75
|
```
|
71
76
|
|
72
77
|
## 📖 Usage Guide
|
73
78
|
|
79
|
+
### Task Execution
|
80
|
+
|
81
|
+
```bash
|
82
|
+
# Execute all tasks in the file
|
83
|
+
kdeploy execute deploy.rb
|
84
|
+
|
85
|
+
# Execute a specific task
|
86
|
+
kdeploy execute deploy.rb deploy_web
|
87
|
+
|
88
|
+
# Execute with dry run (preview mode)
|
89
|
+
kdeploy execute deploy.rb --dry-run
|
90
|
+
|
91
|
+
# Execute on specific hosts
|
92
|
+
kdeploy execute deploy.rb --limit web01,web02
|
93
|
+
|
94
|
+
# Execute with custom parallel count
|
95
|
+
kdeploy execute deploy.rb --parallel 5
|
96
|
+
```
|
97
|
+
|
98
|
+
When executing without specifying a task name (`kdeploy execute deploy.rb`), Kdeploy will:
|
99
|
+
1. Execute all defined tasks in the file
|
100
|
+
2. Run tasks in the order they were defined
|
101
|
+
3. Show task name before each task execution
|
102
|
+
4. Display color-coded output for better readability:
|
103
|
+
- 🟢 Green: Normal output and success messages
|
104
|
+
- 🔴 Red: Errors and failure messages
|
105
|
+
- 🟡 Yellow: Warnings and notices
|
106
|
+
|
74
107
|
### Host Definition
|
75
108
|
|
76
109
|
```ruby
|
@@ -156,22 +189,6 @@ task :deploy_config do
|
|
156
189
|
end
|
157
190
|
```
|
158
191
|
|
159
|
-
### Command Line Options
|
160
|
-
|
161
|
-
```bash
|
162
|
-
# Execute with dry run
|
163
|
-
kdeploy execute deploy.rb --dry-run
|
164
|
-
|
165
|
-
# Limit to specific hosts
|
166
|
-
kdeploy execute deploy.rb --limit web01,web02
|
167
|
-
|
168
|
-
# Set parallel execution count
|
169
|
-
kdeploy execute deploy.rb --parallel 5
|
170
|
-
|
171
|
-
# Execute specific task
|
172
|
-
kdeploy execute deploy.rb deploy_web
|
173
|
-
```
|
174
|
-
|
175
192
|
## 🔧 Development
|
176
193
|
|
177
194
|
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.
|
data/exe/kdeploy
CHANGED
data/lib/kdeploy/cli.rb
CHANGED
@@ -103,7 +103,7 @@ module Kdeploy
|
|
103
103
|
|
104
104
|
runner = Runner.new(hosts, self.class.kdeploy_tasks, parallel: options[:parallel])
|
105
105
|
results = runner.run(task)
|
106
|
-
print_results(results)
|
106
|
+
print_results(results, task)
|
107
107
|
end
|
108
108
|
rescue StandardError => e
|
109
109
|
puts Kdeploy::Banner.show_error(e.message)
|
@@ -122,11 +122,11 @@ module Kdeploy
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def filter_hosts(limit, task_hosts)
|
125
|
-
hosts = self.class.kdeploy_hosts.
|
125
|
+
hosts = self.class.kdeploy_hosts.slice(*task_hosts)
|
126
126
|
return hosts unless limit
|
127
127
|
|
128
128
|
host_names = limit.split(',').map(&:strip)
|
129
|
-
hosts.
|
129
|
+
hosts.slice(*host_names)
|
130
130
|
end
|
131
131
|
|
132
132
|
def print_dry_run(hosts, task_name)
|
@@ -167,10 +167,13 @@ module Kdeploy
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
-
def print_results(results)
|
170
|
+
def print_results(results, task_name)
|
171
171
|
puts Kdeploy::Banner.show
|
172
172
|
pastel = Pastel.new
|
173
173
|
|
174
|
+
puts "#{pastel.bright_cyan('Task:')} #{pastel.bright_white(task_name)}"
|
175
|
+
puts
|
176
|
+
|
174
177
|
results.each do |host, result|
|
175
178
|
status = if result[:status] == :success
|
176
179
|
pastel.green('✓ Success')
|
@@ -184,10 +187,42 @@ module Kdeploy
|
|
184
187
|
result[:output].each do |cmd|
|
185
188
|
puts " #{pastel.bright_yellow('$')} #{cmd[:command]}"
|
186
189
|
if cmd[:output].is_a?(Hash)
|
187
|
-
|
188
|
-
|
190
|
+
unless cmd[:output][:stdout].empty?
|
191
|
+
cmd[:output][:stdout].each_line do |line|
|
192
|
+
line = line.strip
|
193
|
+
next if line.empty?
|
194
|
+
|
195
|
+
# 根据输出内容的特征来决定颜色
|
196
|
+
colored_line = if line.match?(/error|fail|fatal|critical/i)
|
197
|
+
pastel.red(line)
|
198
|
+
elsif line.match?(/warn|deprecat|notice/i)
|
199
|
+
pastel.yellow(line)
|
200
|
+
else
|
201
|
+
pastel.green(line)
|
202
|
+
end
|
203
|
+
puts " #{colored_line}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
unless cmd[:output][:stderr].empty?
|
207
|
+
cmd[:output][:stderr].each_line do |line|
|
208
|
+
puts " #{pastel.red(line)}" unless line.strip.empty?
|
209
|
+
end
|
210
|
+
end
|
189
211
|
elsif cmd[:output]
|
190
|
-
|
212
|
+
cmd[:output].each_line do |line|
|
213
|
+
line = line.strip
|
214
|
+
next if line.empty?
|
215
|
+
|
216
|
+
# 根据输出内容的特征来决定颜色
|
217
|
+
colored_line = if line.match?(/error|fail|fatal|critical/i)
|
218
|
+
pastel.red(line)
|
219
|
+
elsif line.match?(/warn|deprecat|notice/i)
|
220
|
+
pastel.yellow(line)
|
221
|
+
else
|
222
|
+
pastel.green(line)
|
223
|
+
end
|
224
|
+
puts " #{colored_line}"
|
225
|
+
end
|
191
226
|
end
|
192
227
|
puts
|
193
228
|
end
|
data/lib/kdeploy/dsl.rb
CHANGED
@@ -79,20 +79,16 @@ module Kdeploy
|
|
79
79
|
hosts = Set.new
|
80
80
|
|
81
81
|
# 添加指定的主机
|
82
|
-
|
83
|
-
|
84
|
-
hosts.add(host) if kdeploy_hosts.key?(host)
|
85
|
-
end
|
82
|
+
task[:hosts]&.each do |host|
|
83
|
+
hosts.add(host) if kdeploy_hosts.key?(host)
|
86
84
|
end
|
87
85
|
|
88
86
|
# 添加角色中的主机
|
89
|
-
|
90
|
-
|
91
|
-
next unless role_hosts = kdeploy_roles[role]
|
87
|
+
task[:roles]&.each do |role|
|
88
|
+
next unless (role_hosts = kdeploy_roles[role])
|
92
89
|
|
93
|
-
|
94
|
-
|
95
|
-
end
|
90
|
+
role_hosts.each do |host|
|
91
|
+
hosts.add(host) if kdeploy_hosts.key?(host)
|
96
92
|
end
|
97
93
|
end
|
98
94
|
|
data/lib/kdeploy/initializer.rb
CHANGED
@@ -28,8 +28,8 @@ module Kdeploy
|
|
28
28
|
# frozen_string_literal: true
|
29
29
|
|
30
30
|
# Define hosts
|
31
|
-
host
|
32
|
-
host
|
31
|
+
host 'web01', user: 'ubuntu', ip: '10.0.0.1', key: '~/.ssh/id_rsa'
|
32
|
+
host 'web02', user: 'ubuntu', ip: '10.0.0.2', key: '~/.ssh/id_rsa'
|
33
33
|
|
34
34
|
# Define roles
|
35
35
|
role :web, %w[web01 web02]
|
@@ -37,48 +37,48 @@ module Kdeploy
|
|
37
37
|
|
38
38
|
# Define inventory
|
39
39
|
inventory do
|
40
|
-
host
|
40
|
+
host 'db01', user: 'root', ip: '10.0.0.3', key: '~/.ssh/id_rsa'
|
41
41
|
end
|
42
42
|
|
43
43
|
# Define deployment task for web servers
|
44
44
|
task :deploy_web, roles: :web do
|
45
45
|
# Stop service
|
46
|
-
run
|
46
|
+
run 'sudo systemctl stop nginx'
|
47
47
|
|
48
48
|
# Upload configuration using ERB template
|
49
|
-
upload_template
|
50
|
-
domain_name:
|
49
|
+
upload_template './config/nginx.conf.erb', '/etc/nginx/nginx.conf',
|
50
|
+
domain_name: 'example.com',
|
51
51
|
port: 3000,
|
52
52
|
worker_processes: 4,
|
53
53
|
worker_connections: 2048
|
54
54
|
|
55
55
|
# Upload static configuration
|
56
|
-
upload
|
56
|
+
upload './config/app.conf', '/etc/nginx/conf.d/app.conf'
|
57
57
|
|
58
58
|
# Restart service
|
59
|
-
run
|
59
|
+
run 'sudo systemctl start nginx'
|
60
60
|
|
61
61
|
# Check status
|
62
|
-
run
|
62
|
+
run 'sudo systemctl status nginx'
|
63
63
|
end
|
64
64
|
|
65
65
|
# Define backup task for database servers
|
66
66
|
task :backup_db, roles: :db do
|
67
|
-
run
|
68
|
-
run
|
69
|
-
run
|
67
|
+
run 'tar -czf /tmp/backup.tar.gz /var/lib/postgresql/data'
|
68
|
+
run 'aws s3 cp /tmp/backup.tar.gz s3://my-backups/'
|
69
|
+
run 'rm /tmp/backup.tar.gz'
|
70
70
|
end
|
71
71
|
|
72
72
|
# Define task for specific hosts
|
73
73
|
task :maintenance, on: %w[web01] do
|
74
|
-
run
|
75
|
-
run
|
76
|
-
run
|
74
|
+
run 'sudo systemctl stop nginx'
|
75
|
+
run 'sudo apt-get update && sudo apt-get upgrade -y'
|
76
|
+
run 'sudo systemctl start nginx'
|
77
77
|
end
|
78
78
|
|
79
79
|
# Define task for all hosts
|
80
80
|
task :update do
|
81
|
-
run
|
81
|
+
run 'sudo apt-get update && sudo apt-get upgrade -y'
|
82
82
|
end
|
83
83
|
RUBY
|
84
84
|
end
|
@@ -159,7 +159,7 @@ module Kdeploy
|
|
159
159
|
|
160
160
|
This is a deployment project created with Kdeploy.
|
161
161
|
|
162
|
-
## Structure
|
162
|
+
## 📁 Structure
|
163
163
|
|
164
164
|
```
|
165
165
|
.
|
@@ -170,7 +170,7 @@ module Kdeploy
|
|
170
170
|
└── README.md # This file
|
171
171
|
```
|
172
172
|
|
173
|
-
## Configuration Templates
|
173
|
+
## 🔧 Configuration Templates
|
174
174
|
|
175
175
|
The project uses ERB templates for dynamic configuration. For example, in `nginx.conf.erb`:
|
176
176
|
|
@@ -187,27 +187,57 @@ module Kdeploy
|
|
187
187
|
worker_processes: 4
|
188
188
|
```
|
189
189
|
|
190
|
-
## Usage
|
190
|
+
## 🚀 Usage
|
191
|
+
|
192
|
+
### Task Execution
|
191
193
|
|
192
194
|
```bash
|
193
|
-
#
|
194
|
-
kdeploy execute deploy.rb
|
195
|
+
# Execute all tasks in the file
|
196
|
+
kdeploy execute deploy.rb
|
195
197
|
|
196
|
-
#
|
198
|
+
# Execute a specific task
|
197
199
|
kdeploy execute deploy.rb deploy_web
|
198
200
|
|
199
|
-
#
|
200
|
-
kdeploy execute deploy.rb
|
201
|
-
|
202
|
-
# Run maintenance on web01
|
203
|
-
kdeploy execute deploy.rb maintenance
|
201
|
+
# Execute with dry run (preview mode)
|
202
|
+
kdeploy execute deploy.rb --dry-run
|
204
203
|
|
205
|
-
#
|
206
|
-
kdeploy execute deploy.rb
|
204
|
+
# Execute on specific hosts
|
205
|
+
kdeploy execute deploy.rb --limit web01,web02
|
207
206
|
|
208
|
-
#
|
209
|
-
kdeploy execute deploy.rb
|
207
|
+
# Execute with custom parallel count
|
208
|
+
kdeploy execute deploy.rb --parallel 5
|
210
209
|
```
|
210
|
+
|
211
|
+
When executing without specifying a task name (`kdeploy execute deploy.rb`), Kdeploy will:
|
212
|
+
1. Execute all defined tasks in the file
|
213
|
+
2. Run tasks in the order they were defined
|
214
|
+
3. Show task name before each task execution
|
215
|
+
4. Display color-coded output for better readability:
|
216
|
+
- 🟢 Green: Normal output and success messages
|
217
|
+
- 🔴 Red: Errors and failure messages
|
218
|
+
- 🟡 Yellow: Warnings and notices
|
219
|
+
|
220
|
+
### Available Tasks
|
221
|
+
|
222
|
+
- **deploy_web**: Deploy and configure Nginx web servers
|
223
|
+
```bash
|
224
|
+
kdeploy execute deploy.rb deploy_web
|
225
|
+
```
|
226
|
+
|
227
|
+
- **backup_db**: Backup database to S3
|
228
|
+
```bash
|
229
|
+
kdeploy execute deploy.rb backup_db
|
230
|
+
```
|
231
|
+
|
232
|
+
- **maintenance**: Run maintenance on specific host
|
233
|
+
```bash
|
234
|
+
kdeploy execute deploy.rb maintenance
|
235
|
+
```
|
236
|
+
|
237
|
+
- **update**: Update all hosts
|
238
|
+
```bash
|
239
|
+
kdeploy execute deploy.rb update
|
240
|
+
```
|
211
241
|
MD
|
212
242
|
end
|
213
243
|
|
data/lib/kdeploy/template.rb
CHANGED
data/lib/kdeploy/version.rb
CHANGED