kdeploy 1.0.0 → 1.0.2

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: e14af235c838f2eedcd245709e574da869a894aeb8a56546ad3e91a3ca539b81
4
- data.tar.gz: eb26703e45873b1f531436ec824cc4b5d24dc9e08a1719aede9b67946208ad9c
3
+ metadata.gz: 8ae2bd2f567f7b160a845830a1f3ffd63a5f46037018ab2ca42aec65f65e5c3c
4
+ data.tar.gz: 3865ed7280339e8a225a12709982a9570d116fc7cd5f0adbc648673123976fb5
5
5
  SHA512:
6
- metadata.gz: aba8d30f09879f60a61362bb2e36276bf648efac29c81a1c9f69958813465124ccd7463c1e3811936f9194bef95d1bc6a6c3cf4cfc713829122c6f80ec86d4d6
7
- data.tar.gz: '09eb4d286a72d68e382a6453114de89f58e9f2d9c7e455e84f6fbe474fcf46537aff910bb2002d03ddca2ec05708d4c2fc67bd3617f84d80b4efcec38f20d5b3'
6
+ metadata.gz: d58d7a011c9b57e318a97e74ce394b8862f3f4025708008be4eb5b4d4b2970d1087e0a7255d2970091aee8f2bb813b31353cd8aab0e9605bc6eba8cb8da83e8f
7
+ data.tar.gz: d69468308df5ef175023159cd5ee4860d3b65187374928a6aacd3bbcd38095d701d6a303465e20079a5355f39d8a5ffcc7322cf3628930ab2d012080adf87bc1
data/README.md CHANGED
@@ -15,6 +15,9 @@
15
15
 
16
16
  A lightweight agentless deployment automation tool written in Ruby.
17
17
 
18
+ [![Gem Version](https://badge.fury.io/rb/kdeploy.svg)](https://badge.fury.io/rb/kdeploy)
19
+ [![Ruby](https://github.com/kevin197011/kdeploy/actions/workflows/gem-push.yml/badge.svg)](https://github.com/kevin197011/kdeploy/actions/workflows/gem-push.yml)
20
+
18
21
  ## 🌟 Features
19
22
 
20
23
  - 🔑 **Agentless Remote Deployment**: Uses SSH for secure remote execution
@@ -38,13 +41,13 @@ gem 'kdeploy'
38
41
  And then execute:
39
42
 
40
43
  ```bash
41
- $ bundle install
44
+ bundle install
42
45
  ```
43
46
 
44
47
  Or install it yourself as:
45
48
 
46
49
  ```bash
47
- $ gem install kdeploy
50
+ gem install kdeploy
48
51
  ```
49
52
 
50
53
  ### Shell Completion
@@ -76,7 +79,7 @@ Now you can use Tab completion for:
76
79
  1. Initialize a new project:
77
80
 
78
81
  ```bash
79
- $ kdeploy init my-deployment
82
+ kdeploy init my-deployment
80
83
  ```
81
84
 
82
85
  2. Edit the deployment configuration:
@@ -104,11 +107,7 @@ end
104
107
  3. Run the deployment:
105
108
 
106
109
  ```bash
107
- # Execute all tasks in deploy.rb
108
- $ kdeploy execute deploy.rb
109
-
110
- # Execute a specific task
111
- $ kdeploy execute deploy.rb deploy_web
110
+ kdeploy execute deploy.rb
112
111
  ```
113
112
 
114
113
  ## 📖 Usage Guide
@@ -1,8 +1,10 @@
1
1
  #compdef kdeploy
2
2
 
3
3
  _kdeploy() {
4
- local -a commands options
4
+ local curcontext="$curcontext" state line
5
+ typeset -A opt_args
5
6
 
7
+ local -a commands
6
8
  commands=(
7
9
  'init:Initialize a new deployment project'
8
10
  'execute:Execute deployment tasks from file'
@@ -10,24 +12,25 @@ _kdeploy() {
10
12
  'version:Show version information'
11
13
  )
12
14
 
15
+ local -a options
13
16
  options=(
14
17
  '--dry-run[Show what would be done without executing]'
15
18
  '--limit[Limit to specific hosts (comma-separated)]'
16
19
  '--parallel[Number of parallel executions (default: 5)]'
17
20
  )
18
21
 
19
- _arguments -C \
20
- '1: :->cmds' \
21
- '*:: :->args'
22
+ _arguments \
23
+ '1: :->command' \
24
+ '*: :->args'
22
25
 
23
- case "$state" in
24
- cmds)
26
+ case $state in
27
+ command)
25
28
  _describe -t commands 'kdeploy commands' commands
26
29
  ;;
27
30
  args)
28
- case $words[1] in
31
+ case $words[2] in
29
32
  execute)
30
- if (( CURRENT == 2 )); then
33
+ if [[ $CURRENT -eq 3 ]]; then
31
34
  _files -g "*.rb"
32
35
  else
33
36
  _values 'options' $options
@@ -44,4 +47,4 @@ _kdeploy() {
44
47
  esac
45
48
  }
46
49
 
47
- _kdeploy "$@"
50
+ compdef _kdeploy kdeploy
@@ -156,19 +156,6 @@ module Kdeploy
156
156
  def create_readme
157
157
  File.write(File.join(@target_dir, 'README.md'), <<~MD)
158
158
  # Deployment Project
159
- ```
160
- _ _
161
- /\ /\__| | ___ _ __ | | ___ _ _
162
- / //_/ _` |/ _ \ '_ \| |/ _ \| | | |
163
- / __ \ (_| | __/ |_) | | (_) | |_| |
164
- \/ \/\__,_|\___| .__/|_|\___/ \__, |
165
- |_| |___/
166
-
167
-
168
- ⚡ Lightweight Agentless Deployment Tool
169
- 🚀 Deploy with confidence, scale with ease
170
-
171
- ```
172
159
 
173
160
  This is a deployment project created with Kdeploy.
174
161
 
@@ -226,9 +213,9 @@ module Kdeploy
226
213
  2. Run tasks in the order they were defined
227
214
  3. Show task name before each task execution
228
215
  4. Display color-coded output for better readability:
229
- - 🟢 Green: Normal output and success messages
230
- - 🔴 Red: Errors and failure messages
231
- - 🟡 Yellow: Warnings and notices
216
+ - 🟢 Green: Normal output and success messages
217
+ - 🔴 Red: Errors and failure messages
218
+ - 🟡 Yellow: Warnings and notices
232
219
 
233
220
  ### Available Tasks
234
221
 
@@ -23,12 +23,17 @@ module Kdeploy
23
23
  source_line = "source \"#{completion_path}\""
24
24
 
25
25
  # 检查是否已经配置
26
- return if File.read(bashrc_path).include?(source_line)
27
-
28
- # 添加配置
29
- File.open(bashrc_path, 'a') do |f|
30
- f.puts "\n# Kdeploy completion"
31
- f.puts source_line
26
+ content = File.read(bashrc_path)
27
+ if content.match?(/source.*kdeploy\.bash/)
28
+ # 更新现有的配置
29
+ new_content = content.gsub(/source.*kdeploy\.bash.*$/, source_line)
30
+ File.write(bashrc_path, new_content)
31
+ else
32
+ # 添加新配置
33
+ File.open(bashrc_path, 'a') do |f|
34
+ f.puts "\n# Kdeploy completion"
35
+ f.puts source_line
36
+ end
32
37
  end
33
38
  puts "✅ Bash completion configured in #{bashrc_path}"
34
39
  rescue StandardError => e
@@ -49,12 +54,16 @@ module Kdeploy
49
54
  content = File.read(zshrc_path)
50
55
 
51
56
  # 检查是否已经配置
52
- return if source_lines.all? { |line| content.include?(line) }
53
-
54
- # 添加配置
55
- File.open(zshrc_path, 'a') do |f|
56
- f.puts "\n# Kdeploy completion"
57
- source_lines.each { |line| f.puts line unless content.include?(line) }
57
+ if content.match?(/source.*kdeploy\.zsh/)
58
+ # 更新现有的配置
59
+ new_content = content.gsub(/source.*kdeploy\.zsh.*$/, source_lines[0])
60
+ File.write(zshrc_path, new_content)
61
+ else
62
+ # 添加新配置
63
+ File.open(zshrc_path, 'a') do |f|
64
+ f.puts "\n# Kdeploy completion"
65
+ source_lines.each { |line| f.puts line unless content.include?(line) }
66
+ end
58
67
  end
59
68
  puts "✅ Zsh completion configured in #{zshrc_path}"
60
69
  rescue StandardError => e
@@ -62,17 +71,30 @@ module Kdeploy
62
71
  end
63
72
 
64
73
  def find_completion_file(filename)
65
- # 在开发环境中使用相对路径
66
- dev_path = File.expand_path("../completions/#{filename}", __FILE__)
67
- return dev_path if File.exist?(dev_path)
68
-
69
- # 在安装环境中使用 GEM_HOME
70
- if ENV['GEM_HOME']
71
- installed_path = File.join(ENV['GEM_HOME'], 'gems/kdeploy-*/lib/kdeploy/completions', filename)
72
- completion_files = Dir.glob(installed_path)
73
- return completion_files.first if completion_files.any?
74
+ # 尝试所有可能的路径
75
+ paths = [
76
+ # 开发环境路径
77
+ File.expand_path("../completions/#{filename}", __FILE__),
78
+ # RubyGems 安装路径
79
+ *Gem.path.map { |path| File.join(path, "gems/kdeploy-*/lib/kdeploy/completions/#{filename}") },
80
+ # 系统路径
81
+ "/usr/local/share/kdeploy/completions/#{filename}",
82
+ "/usr/share/kdeploy/completions/#{filename}"
83
+ ]
84
+
85
+ # 使用 Dir.glob 处理通配符路径
86
+ paths.each do |path|
87
+ if path.include?('*')
88
+ matches = Dir.glob(path)
89
+ return matches.first if matches.any?
90
+ elsif File.exist?(path)
91
+ return path
92
+ end
74
93
  end
75
94
 
95
+ puts "⚠️ Could not find completion file: #{filename}"
96
+ puts 'Searched paths:'
97
+ paths.each { |path| puts " - #{path}" }
76
98
  nil
77
99
  end
78
100
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kdeploy
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdeploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-06-30 00:00:00.000000000 Z
11
+ date: 2025-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -177,7 +177,6 @@ files:
177
177
  - README.md
178
178
  - exe/kdeploy
179
179
  - ext/mkrf_conf.rb
180
- - k.md
181
180
  - lib/kdeploy.rb
182
181
  - lib/kdeploy/banner.rb
183
182
  - lib/kdeploy/cli.rb
data/k.md DELETED
@@ -1,149 +0,0 @@
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
-