Last active
September 27, 2015 21:18
-
-
Save asux/1333475 to your computer and use it in GitHub Desktop.
Vlad deploy.rb for PHP applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :shared_paths, { | |
'log' => 'log', | |
'pids' => 'tmp/pids', | |
'sockets' => 'tmp/sockets', | |
} | |
set :symlinks, { | |
'rvmrc' => '.rvmrc', | |
} | |
set :skip_scm, false | |
set :perm_owner, 'git' | |
set :perm_group, 'git' | |
set :user, "git" | |
set :domain, "#{user}@domain.com" | |
set :application, "my-app" | |
set :repository, "#{domain}:#{application}.git" | |
set :application_root, "/var/www/#{application}" | |
set :stages, {:staging => {:branch => 'master'}} | |
def colorize(text, color_code) | |
"#{color_code}#{text}\e[0m" | |
end | |
def red(text); colorize(text, "\e[31m"); end | |
def green(text); colorize(text, "\e[32m"); end | |
def say(msg) | |
puts green(">>> #{msg}") | |
end | |
def rake(command) | |
cmd = "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake #{command}" | |
cmd << " --trace" if ENV['VERBOSE'] | |
run cmd | |
end | |
def invoke(task) | |
Rake::Task[task].invoke | |
end | |
desc "Base deployment cycle" | |
task "vlad:deploy:base" do | |
say "Deploying for environment: #{rails_env}" | |
invoke "vlad:update" | |
say "Symlinking shared files" | |
invoke "vlad:symlink" | |
# say "Notify NewRelic deployment" | |
# invoke "vlad:new_relic" | |
# say "Starting app server (unicorn)" | |
# invoke "vlad:start_app" | |
say "Cleaning up" | |
invoke "vlad:cleanup" | |
end | |
stages.each do |stage, opts| | |
desc "Set #{stage} stage variables" | |
task "vlad:stage:#{stage}" do | |
set :deploy_to, "#{application_root}/#{stage}" | |
set :revision, "origin/#{opts[:branch]}" | |
set :rails_env, stage | |
end | |
desc "Deploy #{stage} stage" | |
task "vlad:deploy:#{stage}" => ["vlad:stage:#{stage}", "vlad:deploy:base"] | |
end | |
desc "Deploy defualt stage (staging)" | |
task 'vlad:deploy' => ['vlad:deploy:staging'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment