Last active
September 15, 2015 10:53
-
-
Save dlupu/cdd6e1507c8cc3c7c617 to your computer and use it in GitHub Desktop.
Rakefile to deploy to @Scalingo with support for multiple remotes (staging, production, etc). Suggestions & Improvements are welcomed.
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
# Deploy to scalingo | |
# example : rake deploy REMOTE=staging | |
# last version available here : https://gist.github.com/dlupu/cdd6e1507c8cc3c7c617 | |
namespace :deploy do | |
task :detect_app do | |
SCALINGO_REPOSITORY_REGEXP = /\Agit@scalingo.com:(?<app_name>.*)\.git\z/ | |
remote_name = ENV['REMOTE'] | |
if remote_name.nil? | |
puts 'REMOTE environment variable is missing, assuming REMOTE is `scalingo`.' | |
puts "HINT : next time add REMOTE=<remote name> to your command in order to avoid seeing this message" | |
remote_name = 'scalingo' | |
end | |
if `git remote`.split("\n").include? remote_name | |
APP_GIT_REPO = `git config --get remote.#{remote_name}.url `.gsub!("\n", '') | |
match = SCALINGO_REPOSITORY_REGEXP.match(APP_GIT_REPO) | |
unless match && (APP_NAME = match['app_name']) | |
puts "Error: '#{APP_GIT_REPO}' is not a Scalingo remote. Please choose another remote among the project's git remotes :" | |
puts `git remote -v 2>&1 ` | |
next | |
end | |
else | |
puts "ERROR : Could not find any remote named '#{remote_name}' among the project's git remotes :" | |
puts `git remote -v 2>&1 ` | |
next | |
end | |
end | |
task :push do | |
puts 'Deploying site to Scalingo ...' | |
puts `git push -f #{APP_GIT_REPO} master 2>&1 ` | |
end | |
task :restart do | |
puts 'Restarting app servers ...' | |
puts `scalingo restart --app #{APP_NAME} 2>&1 ` | |
end | |
task :migrate do | |
puts 'Running database migrations ...' | |
puts `scalingo --app #{APP_NAME} run bundle exec rake db:migrate 2>&1` | |
end | |
task :off do | |
# maintainance mode not supported yet | |
puts 'Stopping (aka. scale to 0) the application ...' | |
puts `scalingo --app #{APP_NAME} scale web:1 2>&1 ` | |
end | |
task :on do | |
# maintainance mode not supported yet | |
puts 'Starting (aka. scale to 1) tbe application ...' | |
puts `scalingo --app #{APP_NAME} scale web:1 2>&1` | |
end | |
end | |
task :deploy => ['deploy:detect_app', 'deploy:push', 'deploy:migrate', 'deploy:restart'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment