kdeploy 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3be52250612f3eb627a5044db454c87f7258396f9a0c066be85df9ff8f33b9d
4
- data.tar.gz: c802622e109e4e5d0620456a732e2b8b870b77ec0e422fe461ff1edf6993cd7e
3
+ metadata.gz: 13ad6844e1610898cc64413ee752b17e5b0c83e75b3f503abe73681c79be3bc4
4
+ data.tar.gz: 2fda0c6eb62f2a2ac9a592cce564769d950a7b2f88510f1c251f0dcaceccca86
5
5
  SHA512:
6
- metadata.gz: cc0fba2a35c4bff14238ef9c4f088d1f2fc52f1625e3c7e38394d5100d57db3556fc634af21afcb4b991b1f24e6339c1649c8cc52a58a20a29eb0b8e24d8e956
7
- data.tar.gz: 52cb3084e8bf51f50e92556b13e241451dd6c6bfa6df7ed9041a042ea96eb4f1fe5c8d310af9e706a3e2396eea963f0bc552e6c72efb5aa29eead6da014f553b
6
+ metadata.gz: 3bb78e52644c736b6d9f6a18e506de11e2c331e464a19f9d09c7f4da334d7efb464a8875bac9375717b9cec7a3ed5a42fe68e968d68fb30c2c40ceea9a4aa20e
7
+ data.tar.gz: 6654fae1a9d1eb08b45a790bb12d08050350148069080a848e48cdb921f7b593a5d77d5f5cb50e8605c9a55417aaacc596eb21f3a96ec1369167bcb00aed2af5
data/exe/kdeploy CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "kdeploy"
4
+ require 'kdeploy'
5
5
 
6
- Kdeploy::CLI.start(ARGV)
6
+ Kdeploy::CLI.start(ARGV)
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.select { |name, _| task_hosts.include?(name) }
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.select { |name, _| host_names.include?(name) }
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
- puts " #{cmd[:output][:stdout]}" unless cmd[:output][:stdout].empty?
188
- puts " #{pastel.red(cmd[:output][:stderr])}" unless cmd[:output][:stderr].empty?
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
- puts " #{cmd[:output]}"
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
- if task[:hosts]
83
- task[:hosts].each do |host|
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
- if task[:roles]
90
- task[:roles].each do |role|
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
- role_hosts.each do |host|
94
- hosts.add(host) if kdeploy_hosts.key?(host)
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
 
@@ -28,8 +28,8 @@ module Kdeploy
28
28
  # frozen_string_literal: true
29
29
 
30
30
  # Define hosts
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"
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 "db01", user: "root", ip: "10.0.0.3", key: "~/.ssh/id_rsa"
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 "sudo systemctl stop nginx"
46
+ run 'sudo systemctl stop nginx'
47
47
 
48
48
  # Upload configuration using ERB template
49
- upload_template "./config/nginx.conf.erb", "/etc/nginx/nginx.conf",
50
- domain_name: "example.com",
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 "./config/app.conf", "/etc/nginx/conf.d/app.conf"
56
+ upload './config/app.conf', '/etc/nginx/conf.d/app.conf'
57
57
 
58
58
  # Restart service
59
- run "sudo systemctl start nginx"
59
+ run 'sudo systemctl start nginx'
60
60
 
61
61
  # Check status
62
- run "sudo systemctl status nginx"
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 "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"
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 "sudo systemctl stop nginx"
75
- run "sudo apt-get update && sudo apt-get upgrade -y"
76
- run "sudo systemctl start nginx"
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 "sudo apt-get update && sudo apt-get upgrade -y"
81
+ run 'sudo apt-get update && sudo apt-get upgrade -y'
82
82
  end
83
83
  RUBY
84
84
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'erb'
4
4
  require 'ostruct'
5
+ require 'tempfile'
5
6
 
6
7
  module Kdeploy
7
8
  class Template
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kdeploy
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdeploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norton