Deploy applications with caphub, capistrano and webhooks
- Clone this repository
git clone https://github.com/liocuevas/cap-deploy-tool.git - Run:
cd path/to/deploy
npm install
bundle install
cd cdt
bundle install- Edit
deploys.jsonfile and add the Github repositories to listen
{
"deploys": [{
"name": "Your deploy name",
"type": "github",
"repo": "[the repo url in https format, example https://github.com/owner/repo-name]",
"basepath": "[path to where the deploy command will run]",
"command": "bundle exec cap project-name:staging deploy",
"branch": "[what branch to react to]"
}]
}- Edit
gitlab.jsonfile and add the Gitlab repositories to listen
{
"host" : "0.0.0.0",
"port" : 8889,
"repositories" : {
"[repository name]" : {
"name":"[my super cool name]",
"basepath" : "[path to where the command will run]",
"command" : "bundle exec cap project-name:staging deploy",
"branch" : "[what branch to react to]"
}
}
}- Edit
bitbucket.jsonfile and add the Bitbucket repositories to listen
{
"port" : 8989,
"repositories" : {
"[repository name]" : {
"name":"[my super cool name]",
"basepath" : "[path to where the command will run]",
"command" : "bundle exec cap project-name:staging deploy",
"branch" : "[what branch to react to]"
}
}
}- Create inside
cdt/config/deploya folder with the project name and inside the folder the staging.rb and production.rb (if the project is a wp-deploy https://github.com/Mixd/wp-deploy you will need to create an additional file named database.yml)
############################################
#Setup Server
############################################
set :stage, :staging
set :stage_url, "http://test.com"
server "host", user: "ssh_user", roles: %w{web app db}
set :deploy_to, "/path/to/folder"
set :tmp_dir, "#{fetch(:deploy_to)}/tmp"
############################################
# Setup Git
############################################
set :repo_url, "repo ssh url"
set :repo_link, "repository link"
set :branch, "develop"
############################################
# Setup Hipchat
############################################
set :hipchat_room, "Default Hipchat Room"
############################################
# Run tasks at the end of the deploy
############################################
before "deploy:finished", "cdt:create_robots"
after "deploy:finished", "cdt:send_hipchat_message"############################################
#Setup Server
############################################
set :stage, :staging
set :stage_url, "http://test.com"
server "host", user: "ssh_user", roles: %w{web app db}
set :deploy_to, "/path/to/folder"
set :tmp_dir, "#{fetch(:deploy_to)}/tmp"
############################################
# Setup Git
############################################
load 'lib/submodule_strategy.rb'
set :git_strategy, SubmoduleStrategy
set :repo_url, "repo ssh url"
set :repo_link, "repository link"
set :branch, "development"
############################################
# Setup Hipchat
############################################
set :hipchat_room, "Default Hipchat Room"
############################################
# Setup WP Deploy Tasks
############################################
set :app_wp_name, 'my-app-name'
set :linked_files, %w{wp-config.php .htaccess}
set :linked_dirs, %w{content/uploads}
namespace :deploy do
desc "create WordPress files for symlinking"
task :create_wp_files do
on roles(:app) do
invoke 'wp:generate_remote_files'
execute :touch, "#{shared_path}/wp-config.php"
execute :touch, "#{shared_path}/.htaccess"
end
end
after 'check:make_linked_dirs', :create_wp_files
end
############################################
# Run tasks at the end of the deploy
############################################
before "deploy:finished", "cdt:create_robots"
after "deploy:finished", "cdt:send_hipchat_message"- Copy the example file from
cdt/config/database.yml.exampleto cdt/config/deploy/YOUR_APP_NAME/database.yml
staging:
host: localhost
database: db_name
username: db_user
password: 'root'
production:
host: localhost
database: db_name
username: db_user
password: 'root'
local:
host: localhost
database: db_name
username: db_user
password: 'root'- Inside
cdt/you can run manually the tasks from the command-linecap -T: List the available tasksbundle exec cap project-name:stage-name deploy [options] ex --trace