_ _
/\ /\__| | ___ _ __ | | ___ _ _
/ //_/ _` |/ _ \ '_ \| |/ _ \| | | |
/ __ \ (_| | __/ |_) | | (_) | |_| |
\/ \/\__,_|\___| .__/|_|\___/ \__, |
|_| |___/
⚡ Lightweight Agentless Deployment Tool
🚀 Deploy with confidence, scale with ease
A lightweight agentless deployment automation tool written in Ruby.
- 🔑 Agentless Remote Deployment: Uses SSH for secure remote execution
- 📝 Elegant Ruby DSL: Simple and expressive task definition
- 🚀 Concurrent Execution: Efficient parallel task processing
- 📤 File Upload Support: Easy file and template deployment
- 📊 Task Status Tracking: Real-time execution monitoring
- 🔄 ERB Template Support: Dynamic configuration generation
- 🎯 Role-based Deployment: Target specific server roles
- 🔍 Dry Run Mode: Preview tasks before execution
- 🎨 Color-coded Output: Green for success, Red for errors, Yellow for warnings
Add this line to your application's Gemfile:
gem 'kdeploy'
And then execute:
bundle install
Or install it yourself as:
gem install kdeploy
To enable command completion, add the following to your shell config:
For Bash (~/.bashrc
):
source "$(gem contents kdeploy | grep kdeploy.bash)"
For Zsh (~/.zshrc
):
source "$(gem contents kdeploy | grep kdeploy.zsh)"
autoload -Uz compinit && compinit
After adding the configuration:
- For Bash:
source ~/.bashrc
- For Zsh:
source ~/.zshrc
Now you can use Tab completion for:
- Commands:
kdeploy [TAB]
- File paths:
kdeploy execute [TAB]
- Options:
kdeploy execute deploy.rb [TAB]
- Initialize a new project:
kdeploy init my-deployment
- Edit the deployment configuration:
# deploy.rb
# Define hosts
host "web01", user: "ubuntu", ip: "10.0.0.1", key: "~/.ssh/id_rsa"
host "web02", user: "ubuntu", ip: "10.0.0.2", key: "~/.ssh/id_rsa"
# Define roles
role :web, %w[web01 web02]
# Define tasks
# 推荐多行命令用 heredoc(run <<~SHELL)
task :deploy, roles: :web do
run <<~SHELL
sudo systemctl stop nginx
echo "Deploying..."
sudo systemctl start nginx
SHELL
upload_template "./config/nginx.conf.erb", "/etc/nginx/nginx.conf",
domain_name: "example.com",
port: 3000
end
- Run the deployment:
kdeploy execute deploy.rb
- Demo:
https://github.com/kevin197011/kdeploy-app
# Execute all tasks in the file
kdeploy execute deploy.rb
# Execute a specific task
kdeploy execute deploy.rb deploy_web
# Execute with dry run (preview mode)
kdeploy execute deploy.rb --dry-run
# Execute on specific hosts
kdeploy execute deploy.rb --limit web01,web02
# Execute with custom parallel count (default: 10)
kdeploy execute deploy.rb --parallel 10
# Single host
host "web01",
user: "ubuntu",
ip: "10.0.0.1",
key: "~/.ssh/id_rsa"
# Multiple hosts
%w[web01 web02 web03].each do |name|
host name,
user: "ubuntu",
ip: "10.0.0.#{name[-1]}",
key: "~/.ssh/id_rsa"
end
# Define roles
role :web, %w[web01 web02]
role :db, %w[db01 db02]
role :all, %w[web01 web02 db01 db02]
# Use roles in tasks
task :deploy_web, roles: :web do
# Tasks for web servers
end
task :backup_db, roles: :db do
# Tasks for database servers
end
# Basic task
task :simple do
run "echo 'Hello, World!'"
end
# Role-based task
task :deploy, roles: :web do
run <<~SHELL
sudo systemctl stop nginx
sudo systemctl start nginx
SHELL
upload "./config/nginx.conf", "/etc/nginx/nginx.conf"
end
# Host-specific task
task :maintenance, on: %w[web01] do
run <<~SHELL
sudo apt-get update
sudo apt-get upgrade -y
SHELL
end
Create an ERB template (config/nginx.conf.erb
):
server {
listen 80;
server_name <%= domain_name %>;
location / {
proxy_pass http://localhost:<%= port %>;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Use the template in your task:
task :deploy_config do
upload_template "./config/nginx.conf.erb", "/etc/nginx/sites-available/myapp.conf",
domain_name: "example.com",
port: 3000
end
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.
To install this gem onto your local machine, run bundle exec rake install
.
- Fork it
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create a new Pull Request
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Kdeploy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.