Kdeploy
_ _
/\ /\__| | ___ _ __ | | ___ _ _
/ //_/ _` |/ _ \ '_ \| |/ _ \| | | |
/ __ \ (_| | __/ |_) | | (_) | |_| |
\/ \/\__,_|\___| .__/|_|\___/ \__, |
|_| |___/
β‘ Lightweight Agentless Deployment Tool
π Deploy with confidence, scale with ease
A lightweight agentless deployment automation tool written in Ruby.
π Features
- π 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
π¦ Installation
Add this line to your application's Gemfile:
gem 'kdeploy'
And then execute:
bundle install
Or install it yourself as:
gem install kdeploy
Shell Completion
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]
π Quick Start
- 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
π Usage Guide
Task Execution
# 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
Host Definition
# 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
Role Management
# 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
Task Definition
# 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
Template Support
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
π§ Development
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
.
π€ Contributing
- 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
π License
The gem is available as open source under the terms of the MIT License.
π Code of Conduct
Everyone interacting in the Kdeploy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.