kdeploy 1.2.38 → 1.2.39
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 +57 -73
- data/README_EN.md +69 -68
- data/lib/kdeploy/executor.rb +5 -3
- 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: a38f6cd05a9b367146a9589800c65ebbc62a1c4192b6be8347d1156031c54d6b
|
|
4
|
+
data.tar.gz: 1cde973c19e35e14d299fbc2c8e307f2a69093d8a442d542a9db262f057213a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9db48da0d7a90fa51389c2311b0aaea919cc87d4e47360ce3323f5202a96d3998e955819a5d39528f998f9edb2d4f90808bfd5dfdab1b2ea47c4f443a57452b5
|
|
7
|
+
data.tar.gz: 98d5a5c755f1a75e2491f4a8d09e1842851bf077316f6a50f11f964ebaef334f6b6666017d8a78b4918dcef4f17d8e181e4d60e5867212db3bea163d6c860c0e
|
data/README.md
CHANGED
|
@@ -98,6 +98,12 @@ kdeploy version
|
|
|
98
98
|
|
|
99
99
|
您应该看到版本信息和横幅。
|
|
100
100
|
|
|
101
|
+
**若找不到 `kdeploy` 命令**:gem 的可执行目录可能不在 PATH 中。将以下内容加入 `~/.zshrc` 或 `~/.bashrc` 后执行 `source ~/.zshrc`:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
export PATH="$(ruby -e 'puts Gem.bindir'):$PATH"
|
|
105
|
+
```
|
|
106
|
+
|
|
101
107
|
### Shell 自动补全
|
|
102
108
|
|
|
103
109
|
Kdeploy 在安装期间自动配置 shell 自动补全。如果需要,可以手动添加到 shell 配置中:
|
|
@@ -137,35 +143,30 @@ kdeploy init my-deployment
|
|
|
137
143
|
|
|
138
144
|
### 2. 配置主机和任务
|
|
139
145
|
|
|
140
|
-
编辑 `deploy.rb
|
|
146
|
+
编辑 `deploy.rb`(使用 Chef 风格资源 DSL):
|
|
141
147
|
|
|
142
148
|
```ruby
|
|
143
149
|
# 定义主机
|
|
144
150
|
host "web01", user: "ubuntu", ip: "10.0.0.1", key: "~/.ssh/id_rsa"
|
|
145
151
|
host "web02", user: "ubuntu", ip: "10.0.0.2", key: "~/.ssh/id_rsa"
|
|
146
|
-
|
|
147
|
-
# 定义角色
|
|
148
152
|
role :web, %w[web01 web02]
|
|
149
153
|
|
|
150
154
|
# 定义部署任务
|
|
151
|
-
task :
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
port: 3000
|
|
160
|
-
|
|
161
|
-
run "sudo systemctl start nginx"
|
|
155
|
+
task :deploy_web, roles: :web do
|
|
156
|
+
package "nginx"
|
|
157
|
+
directory "/etc/nginx/conf.d"
|
|
158
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb",
|
|
159
|
+
variables: { domain_name: "example.com", port: 3000 }
|
|
160
|
+
file "/etc/nginx/conf.d/app.conf", source: "./config/app.conf"
|
|
161
|
+
run "nginx -t", sudo: true
|
|
162
|
+
service "nginx", action: %i[enable restart]
|
|
162
163
|
end
|
|
163
164
|
```
|
|
164
165
|
|
|
165
166
|
### 3. 运行部署
|
|
166
167
|
|
|
167
168
|
```bash
|
|
168
|
-
kdeploy execute deploy.rb
|
|
169
|
+
kdeploy execute deploy.rb deploy_web
|
|
169
170
|
```
|
|
170
171
|
|
|
171
172
|
## 📖 使用指南
|
|
@@ -356,7 +357,7 @@ end
|
|
|
356
357
|
|
|
357
358
|
```ruby
|
|
358
359
|
task :deploy_web, roles: :web do
|
|
359
|
-
|
|
360
|
+
service "nginx", action: :restart
|
|
360
361
|
end
|
|
361
362
|
```
|
|
362
363
|
|
|
@@ -364,29 +365,22 @@ end
|
|
|
364
365
|
|
|
365
366
|
```ruby
|
|
366
367
|
task :maintenance, on: %w[web01] do
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
sudo systemctl start nginx
|
|
371
|
-
SHELL
|
|
368
|
+
service "nginx", action: :stop
|
|
369
|
+
run "apt-get update && apt-get upgrade -y", sudo: true
|
|
370
|
+
service "nginx", action: %i[start enable]
|
|
372
371
|
end
|
|
373
372
|
```
|
|
374
373
|
|
|
375
374
|
#### 多命令任务
|
|
376
375
|
|
|
377
376
|
```ruby
|
|
378
|
-
task :
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
# 启动服务
|
|
386
|
-
run "sudo systemctl start nginx"
|
|
387
|
-
|
|
388
|
-
# 验证状态
|
|
389
|
-
run "sudo systemctl status nginx"
|
|
377
|
+
task :deploy_web, roles: :web do
|
|
378
|
+
package "nginx"
|
|
379
|
+
directory "/etc/nginx/conf.d"
|
|
380
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb", variables: { port: 3000 }
|
|
381
|
+
file "/etc/nginx/conf.d/app.conf", source: "./config/app.conf"
|
|
382
|
+
run "nginx -t", sudo: true
|
|
383
|
+
service "nginx", action: %i[enable restart]
|
|
390
384
|
end
|
|
391
385
|
```
|
|
392
386
|
|
|
@@ -636,11 +630,8 @@ http {
|
|
|
636
630
|
|
|
637
631
|
```ruby
|
|
638
632
|
task :deploy_config do
|
|
639
|
-
|
|
640
|
-
domain_name: "example.com",
|
|
641
|
-
port: 3000,
|
|
642
|
-
worker_processes: 4,
|
|
643
|
-
worker_connections: 2048
|
|
633
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb",
|
|
634
|
+
variables: { domain_name: "example.com", port: 3000, worker_processes: 4, worker_connections: 2048 }
|
|
644
635
|
end
|
|
645
636
|
```
|
|
646
637
|
|
|
@@ -703,15 +694,11 @@ verify_host_key: true
|
|
|
703
694
|
|
|
704
695
|
```ruby
|
|
705
696
|
task :deploy do
|
|
706
|
-
if ENV['ENVIRONMENT'] == 'production'
|
|
707
|
-
run "sudo systemctl stop nginx"
|
|
708
|
-
end
|
|
697
|
+
service "nginx", action: :stop if ENV['ENVIRONMENT'] == 'production'
|
|
709
698
|
|
|
710
|
-
|
|
699
|
+
file "/etc/nginx/nginx.conf", source: "./config/nginx.conf"
|
|
711
700
|
|
|
712
|
-
if ENV['ENVIRONMENT'] == 'production'
|
|
713
|
-
run "sudo systemctl start nginx"
|
|
714
|
-
end
|
|
701
|
+
service "nginx", action: :start if ENV['ENVIRONMENT'] == 'production'
|
|
715
702
|
end
|
|
716
703
|
```
|
|
717
704
|
|
|
@@ -734,9 +721,10 @@ end
|
|
|
734
721
|
|
|
735
722
|
```ruby
|
|
736
723
|
task :deploy do
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
run "
|
|
724
|
+
service "nginx", action: :stop
|
|
725
|
+
file "/etc/nginx/nginx.conf", source: "./config/nginx.conf"
|
|
726
|
+
run "nginx -t" || raise "Nginx 配置无效"
|
|
727
|
+
service "nginx", action: :start
|
|
740
728
|
end
|
|
741
729
|
```
|
|
742
730
|
|
|
@@ -814,10 +802,9 @@ end
|
|
|
814
802
|
### 3. 使用模板进行动态配置
|
|
815
803
|
|
|
816
804
|
```ruby
|
|
817
|
-
# ✅ 好的做法 -
|
|
818
|
-
|
|
819
|
-
domain_name: "example.com",
|
|
820
|
-
port: 3000
|
|
805
|
+
# ✅ 好的做法 - 使用 template 资源
|
|
806
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb",
|
|
807
|
+
variables: { domain_name: "example.com", port: 3000 }
|
|
821
808
|
|
|
822
809
|
# ❌ 避免 - 硬编码值
|
|
823
810
|
run "echo 'server_name example.com;' > /etc/nginx/nginx.conf"
|
|
@@ -827,12 +814,10 @@ run "echo 'server_name example.com;' > /etc/nginx/nginx.conf"
|
|
|
827
814
|
|
|
828
815
|
```ruby
|
|
829
816
|
task :deploy do
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
upload "./config/nginx.conf", "/etc/nginx/nginx.conf"
|
|
835
|
-
run "sudo systemctl reload nginx"
|
|
817
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb", variables: { port: 3000 }
|
|
818
|
+
file "/etc/nginx/conf.d/app.conf", source: "./config/app.conf"
|
|
819
|
+
run "nginx -t", sudo: true # 配置无效时 run 会抛异常
|
|
820
|
+
service "nginx", action: :reload
|
|
836
821
|
end
|
|
837
822
|
```
|
|
838
823
|
|
|
@@ -1070,7 +1055,14 @@ bundle exec rubocop -a
|
|
|
1070
1055
|
|
|
1071
1056
|
### 示例项目
|
|
1072
1057
|
|
|
1073
|
-
|
|
1058
|
+
本仓库的 [sample/](sample/) 目录提供完整示例,包含 Nginx、Node Exporter、目录同步等任务,支持 Vagrant 本地测试:
|
|
1059
|
+
|
|
1060
|
+
```bash
|
|
1061
|
+
cd sample
|
|
1062
|
+
vagrant up
|
|
1063
|
+
kdeploy execute deploy.rb deploy_web --dry-run # 预览
|
|
1064
|
+
kdeploy execute deploy.rb deploy_web # 执行
|
|
1065
|
+
```
|
|
1074
1066
|
|
|
1075
1067
|
### 常见部署场景
|
|
1076
1068
|
|
|
@@ -1111,12 +1103,9 @@ end
|
|
|
1111
1103
|
|
|
1112
1104
|
```ruby
|
|
1113
1105
|
task :update_config, roles: :web do
|
|
1114
|
-
|
|
1115
|
-
environment: "production",
|
|
1116
|
-
|
|
1117
|
-
redis_url: ENV['REDIS_URL']
|
|
1118
|
-
|
|
1119
|
-
run "sudo systemctl reload app"
|
|
1106
|
+
template "/etc/app/config.yml", source: "./config/app.yml.erb",
|
|
1107
|
+
variables: { environment: "production", database_url: ENV['DATABASE_URL'], redis_url: ENV['REDIS_URL'] }
|
|
1108
|
+
service "app", action: :reload
|
|
1120
1109
|
end
|
|
1121
1110
|
```
|
|
1122
1111
|
|
|
@@ -1124,16 +1113,11 @@ end
|
|
|
1124
1113
|
|
|
1125
1114
|
```ruby
|
|
1126
1115
|
task :deploy_app, roles: :web do
|
|
1127
|
-
# 同步应用程序代码,忽略开发文件
|
|
1128
1116
|
sync "./app", "/var/www/app",
|
|
1129
1117
|
ignore: [".git", "*.log", "node_modules", ".env.local", "*.tmp"],
|
|
1130
1118
|
delete: true
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
sync "./config", "/etc/app",
|
|
1134
|
-
exclude: ["*.example", "*.bak"]
|
|
1135
|
-
|
|
1136
|
-
run "sudo systemctl restart app"
|
|
1119
|
+
sync "./config", "/etc/app", exclude: ["*.example", "*.bak"]
|
|
1120
|
+
service "app", action: :restart
|
|
1137
1121
|
end
|
|
1138
1122
|
```
|
|
1139
1123
|
|
|
@@ -1146,7 +1130,7 @@ end
|
|
|
1146
1130
|
- **GitHub**: https://github.com/kevin197011/kdeploy
|
|
1147
1131
|
- **RubyGems**: https://rubygems.org/gems/kdeploy
|
|
1148
1132
|
- **Issues**: https://github.com/kevin197011/kdeploy/issues
|
|
1149
|
-
-
|
|
1133
|
+
- **示例**: [sample/](sample/) 目录(含 Vagrant 配置)
|
|
1150
1134
|
|
|
1151
1135
|
## 🙏 致谢
|
|
1152
1136
|
|
data/README_EN.md
CHANGED
|
@@ -97,6 +97,12 @@ kdeploy version
|
|
|
97
97
|
|
|
98
98
|
You should see the version information and banner.
|
|
99
99
|
|
|
100
|
+
**If `kdeploy` is not found**: the gem executable directory may not be in your PATH. Add to `~/.zshrc` or `~/.bashrc` then run `source ~/.zshrc`:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
export PATH="$(ruby -e 'puts Gem.bindir'):$PATH"
|
|
104
|
+
```
|
|
105
|
+
|
|
100
106
|
### Shell Completion
|
|
101
107
|
|
|
102
108
|
Kdeploy automatically configures shell completion during installation. If needed, manually add to your shell config:
|
|
@@ -136,35 +142,30 @@ This creates a new directory with:
|
|
|
136
142
|
|
|
137
143
|
### 2. Configure Hosts and Tasks
|
|
138
144
|
|
|
139
|
-
Edit `deploy.rb
|
|
145
|
+
Edit `deploy.rb` (using Chef-style resource DSL):
|
|
140
146
|
|
|
141
147
|
```ruby
|
|
142
148
|
# Define hosts
|
|
143
149
|
host "web01", user: "ubuntu", ip: "10.0.0.1", key: "~/.ssh/id_rsa"
|
|
144
150
|
host "web02", user: "ubuntu", ip: "10.0.0.2", key: "~/.ssh/id_rsa"
|
|
145
|
-
|
|
146
|
-
# Define roles
|
|
147
151
|
role :web, %w[web01 web02]
|
|
148
152
|
|
|
149
153
|
# Define deployment task
|
|
150
|
-
task :
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
port: 3000
|
|
159
|
-
|
|
160
|
-
run "sudo systemctl start nginx"
|
|
154
|
+
task :deploy_web, roles: :web do
|
|
155
|
+
package "nginx"
|
|
156
|
+
directory "/etc/nginx/conf.d"
|
|
157
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb",
|
|
158
|
+
variables: { domain_name: "example.com", port: 3000 }
|
|
159
|
+
file "/etc/nginx/conf.d/app.conf", source: "./config/app.conf"
|
|
160
|
+
run "nginx -t", sudo: true
|
|
161
|
+
service "nginx", action: %i[enable restart]
|
|
161
162
|
end
|
|
162
163
|
```
|
|
163
164
|
|
|
164
165
|
### 3. Run Deployment
|
|
165
166
|
|
|
166
167
|
```bash
|
|
167
|
-
kdeploy execute deploy.rb
|
|
168
|
+
kdeploy execute deploy.rb deploy_web
|
|
168
169
|
```
|
|
169
170
|
|
|
170
171
|
## 📖 Usage Guide
|
|
@@ -355,7 +356,7 @@ end
|
|
|
355
356
|
|
|
356
357
|
```ruby
|
|
357
358
|
task :deploy_web, roles: :web do
|
|
358
|
-
|
|
359
|
+
service "nginx", action: :restart
|
|
359
360
|
end
|
|
360
361
|
```
|
|
361
362
|
|
|
@@ -363,29 +364,22 @@ end
|
|
|
363
364
|
|
|
364
365
|
```ruby
|
|
365
366
|
task :maintenance, on: %w[web01] do
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
sudo systemctl start nginx
|
|
370
|
-
SHELL
|
|
367
|
+
service "nginx", action: :stop
|
|
368
|
+
run "apt-get update && apt-get upgrade -y", sudo: true
|
|
369
|
+
service "nginx", action: %i[start enable]
|
|
371
370
|
end
|
|
372
371
|
```
|
|
373
372
|
|
|
374
373
|
#### Task with Multiple Commands
|
|
375
374
|
|
|
376
375
|
```ruby
|
|
377
|
-
task :
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
# Start service
|
|
385
|
-
run "sudo systemctl start nginx"
|
|
386
|
-
|
|
387
|
-
# Verify status
|
|
388
|
-
run "sudo systemctl status nginx"
|
|
376
|
+
task :deploy_web, roles: :web do
|
|
377
|
+
package "nginx"
|
|
378
|
+
directory "/etc/nginx/conf.d"
|
|
379
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb", variables: { port: 3000 }
|
|
380
|
+
file "/etc/nginx/conf.d/app.conf", source: "./config/app.conf"
|
|
381
|
+
run "nginx -t", sudo: true
|
|
382
|
+
service "nginx", action: %i[enable restart]
|
|
389
383
|
end
|
|
390
384
|
```
|
|
391
385
|
|
|
@@ -542,8 +536,8 @@ task :deploy_nginx, roles: :web do
|
|
|
542
536
|
directory "/etc/nginx/conf.d"
|
|
543
537
|
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb", variables: { port: 3000 }
|
|
544
538
|
file "/etc/nginx/conf.d/app.conf", source: "./config/app.conf"
|
|
545
|
-
run "nginx -t"
|
|
546
|
-
service "nginx", action: [
|
|
539
|
+
run "nginx -t", sudo: true
|
|
540
|
+
service "nginx", action: %i[enable restart]
|
|
547
541
|
end
|
|
548
542
|
```
|
|
549
543
|
|
|
@@ -593,11 +587,8 @@ http {
|
|
|
593
587
|
|
|
594
588
|
```ruby
|
|
595
589
|
task :deploy_config do
|
|
596
|
-
|
|
597
|
-
domain_name: "example.com",
|
|
598
|
-
port: 3000,
|
|
599
|
-
worker_processes: 4,
|
|
600
|
-
worker_connections: 2048
|
|
590
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb",
|
|
591
|
+
variables: { domain_name: "example.com", port: 3000, worker_processes: 4, worker_connections: 2048 }
|
|
601
592
|
end
|
|
602
593
|
```
|
|
603
594
|
|
|
@@ -658,15 +649,11 @@ Use Ruby conditionals in your deployment files:
|
|
|
658
649
|
|
|
659
650
|
```ruby
|
|
660
651
|
task :deploy do
|
|
661
|
-
if ENV['ENVIRONMENT'] == 'production'
|
|
662
|
-
run "sudo systemctl stop nginx"
|
|
663
|
-
end
|
|
652
|
+
service "nginx", action: :stop if ENV['ENVIRONMENT'] == 'production'
|
|
664
653
|
|
|
665
|
-
|
|
654
|
+
file "/etc/nginx/nginx.conf", source: "./config/nginx.conf"
|
|
666
655
|
|
|
667
|
-
if ENV['ENVIRONMENT'] == 'production'
|
|
668
|
-
run "sudo systemctl start nginx"
|
|
669
|
-
end
|
|
656
|
+
service "nginx", action: :start if ENV['ENVIRONMENT'] == 'production'
|
|
670
657
|
end
|
|
671
658
|
```
|
|
672
659
|
|
|
@@ -689,9 +676,10 @@ end
|
|
|
689
676
|
|
|
690
677
|
```ruby
|
|
691
678
|
task :deploy do
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
run "
|
|
679
|
+
service "nginx", action: :stop
|
|
680
|
+
file "/etc/nginx/nginx.conf", source: "./config/nginx.conf"
|
|
681
|
+
run "nginx -t", sudo: true # run raises on invalid config
|
|
682
|
+
service "nginx", action: :start
|
|
695
683
|
end
|
|
696
684
|
```
|
|
697
685
|
|
|
@@ -807,10 +795,9 @@ end
|
|
|
807
795
|
### 3. Use Templates for Dynamic Configuration
|
|
808
796
|
|
|
809
797
|
```ruby
|
|
810
|
-
# ✅ Good - Use
|
|
811
|
-
|
|
812
|
-
domain_name: "example.com",
|
|
813
|
-
port: 3000
|
|
798
|
+
# ✅ Good - Use template resource
|
|
799
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb",
|
|
800
|
+
variables: { domain_name: "example.com", port: 3000 }
|
|
814
801
|
|
|
815
802
|
# ❌ Avoid - Hardcoding values
|
|
816
803
|
run "echo 'server_name example.com;' > /etc/nginx/nginx.conf"
|
|
@@ -820,12 +807,10 @@ run "echo 'server_name example.com;' > /etc/nginx/nginx.conf"
|
|
|
820
807
|
|
|
821
808
|
```ruby
|
|
822
809
|
task :deploy do
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
upload "./config/nginx.conf", "/etc/nginx/nginx.conf"
|
|
828
|
-
run "sudo systemctl reload nginx"
|
|
810
|
+
template "/etc/nginx/nginx.conf", source: "./config/nginx.conf.erb", variables: { port: 3000 }
|
|
811
|
+
file "/etc/nginx/conf.d/app.conf", source: "./config/app.conf"
|
|
812
|
+
run "nginx -t", sudo: true # run raises on invalid config
|
|
813
|
+
service "nginx", action: :reload
|
|
829
814
|
end
|
|
830
815
|
```
|
|
831
816
|
|
|
@@ -1076,9 +1061,16 @@ Types: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`
|
|
|
1076
1061
|
|
|
1077
1062
|
## 📚 Examples
|
|
1078
1063
|
|
|
1079
|
-
### Example
|
|
1064
|
+
### Example Project
|
|
1065
|
+
|
|
1066
|
+
The [sample/](sample/) directory in this repo provides a complete example with Nginx, Node Exporter, directory sync tasks, and Vagrant support for local testing:
|
|
1080
1067
|
|
|
1081
|
-
|
|
1068
|
+
```bash
|
|
1069
|
+
cd sample
|
|
1070
|
+
vagrant up
|
|
1071
|
+
kdeploy execute deploy.rb deploy_web --dry-run # Preview
|
|
1072
|
+
kdeploy execute deploy.rb deploy_web # Execute
|
|
1073
|
+
```
|
|
1082
1074
|
|
|
1083
1075
|
### Common Deployment Scenarios
|
|
1084
1076
|
|
|
@@ -1119,12 +1111,21 @@ end
|
|
|
1119
1111
|
|
|
1120
1112
|
```ruby
|
|
1121
1113
|
task :update_config, roles: :web do
|
|
1122
|
-
|
|
1123
|
-
environment: "production",
|
|
1124
|
-
|
|
1125
|
-
|
|
1114
|
+
template "/etc/app/config.yml", source: "./config/app.yml.erb",
|
|
1115
|
+
variables: { environment: "production", database_url: ENV['DATABASE_URL'], redis_url: ENV['REDIS_URL'] }
|
|
1116
|
+
service "app", action: :reload
|
|
1117
|
+
end
|
|
1118
|
+
```
|
|
1119
|
+
|
|
1120
|
+
#### Directory Sync Deployment
|
|
1126
1121
|
|
|
1127
|
-
|
|
1122
|
+
```ruby
|
|
1123
|
+
task :deploy_app, roles: :web do
|
|
1124
|
+
sync "./app", "/var/www/app",
|
|
1125
|
+
ignore: [".git", "*.log", "node_modules", ".env.local", "*.tmp"],
|
|
1126
|
+
delete: true
|
|
1127
|
+
sync "./config", "/etc/app", exclude: ["*.example", "*.bak"]
|
|
1128
|
+
service "app", action: :restart
|
|
1128
1129
|
end
|
|
1129
1130
|
```
|
|
1130
1131
|
|
|
@@ -1137,7 +1138,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
1137
1138
|
- **GitHub**: https://github.com/kevin197011/kdeploy
|
|
1138
1139
|
- **RubyGems**: https://rubygems.org/gems/kdeploy
|
|
1139
1140
|
- **Issues**: https://github.com/kevin197011/kdeploy/issues
|
|
1140
|
-
- **
|
|
1141
|
+
- **Sample**: [sample/](sample/) directory (includes Vagrant config)
|
|
1141
1142
|
|
|
1142
1143
|
## 🙏 Acknowledgments
|
|
1143
1144
|
|
data/lib/kdeploy/executor.rb
CHANGED
|
@@ -232,10 +232,12 @@ module Kdeploy
|
|
|
232
232
|
# 如果命令已经以 sudo 开头,不重复添加
|
|
233
233
|
return command if command.strip.start_with?('sudo')
|
|
234
234
|
|
|
235
|
-
#
|
|
236
|
-
|
|
235
|
+
# 多行、shell 控制结构、或包含 && / || / ; 的复合命令需整段在 sudo 下执行
|
|
236
|
+
needs_wrap = command.include?("\n") ||
|
|
237
|
+
command.match?(/\b(if|for|while|case|function)\b/) ||
|
|
238
|
+
command.match?(/\s(&&|\|\||;)\s/)
|
|
237
239
|
|
|
238
|
-
if
|
|
240
|
+
if needs_wrap
|
|
239
241
|
# 转义命令中的单引号,然后用 bash -c 执行
|
|
240
242
|
escaped_command = command.gsub("'", "'\"'\"'")
|
|
241
243
|
if @sudo_password
|
data/lib/kdeploy/version.rb
CHANGED