Last active
August 29, 2015 14:07
-
-
Save styliii/63bd59a4d485be4b48bb to your computer and use it in GitHub Desktop.
Heroku Setup for Sandbox Environment
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
# encoding: utf-8 | |
namespace :dev do | |
namespace :heroku do | |
HEROKU_CMD = "GEM_HOME='' BUNDLE_GEMFILE='' GEM_PATH='' RUBYOPT='' /usr/bin/heroku" | |
desc "initialize heroku instance" | |
task :init => :environment do | |
STDOUT.puts "What do you want to call your environment?".colorize(:yellow) | |
input = STDIN.gets.strip | |
exit if input.blank? | |
puts Cocaine::CommandLine.new(HEROKU_CMD, "create #{input}").run | |
end | |
desc "provision add-ons" | |
task :addons => :environment do | |
addons = %w{your_list_of_addons} | |
addons.each do |addon| | |
puts Cocaine::CommandLine.new(HEROKU_CMD, "addons:add #{addon}").run | |
end | |
end | |
desc "setup heroku config" | |
task :config => :environment do | |
heroku_conf = {} | |
pow_conf = {} | |
heroku_get = Cocaine::CommandLine.new(HEROKU_CMD, "config") | |
heroku_get.run.lines.each do |line| | |
/^(?<key>[A-Z_]+):\s+(?<val>.+)/ =~ line | |
if key | |
heroku_conf[key] = val | |
end | |
end | |
File.open(File.join(Rails.root,".powenv"),'r').readlines.each do |line| | |
/^export\s+(?<key>[A-Z_]+)=(?<val>.+)/ =~ line | |
if key | |
pow_conf[key] = val | |
end | |
end | |
heroku_conf.merge!(pow_conf) | |
heroku_conf.each do |k,v| | |
heroku_set = Cocaine::CommandLine.new(HEROKU_CMD, "config:set #{k}=#{v}") | |
puts heroku_set.run | |
end | |
%w{RACK_ENV=devstage RAILS_ENV=devstage}.each do |i| | |
heroku_set = Cocaine::CommandLine.new(HEROKU_CMD, "config:set #{i}") | |
puts heroku_set.run | |
end | |
end | |
desc "app db config" | |
task :db_setup => :environment do | |
%w{db:schema:load db:seed seed_admins}.each do |i| | |
heroku_set = Cocaine::CommandLine.new(HEROKU_CMD, "run rake #{i}") | |
puts heroku_set.run | |
end | |
end | |
desc "push current branch" | |
task :push do | |
git_branch = Cocaine::CommandLine.new('git', 'branch').run | |
/^\*\s?(?<current_branch>\S+)/ =~ git_branch | |
puts Cocaine::CommandLine.new("git", "push heroku #{current_branch}:master").run | |
end | |
desc "setup developer environment" | |
task :setup => :environment do | |
puts "Setting up your heroku environment".colorize(:blue) | |
Rake::Task["dev:heroku:init"].invoke | |
puts "Adding additional infrastructure compoments".colorize(:blue) | |
Rake::Task["dev:heroku:addons"].invoke | |
puts "Syncing your environment variables".colorize(:blue) | |
Rake::Task["dev:heroku:config"].invoke | |
puts "Pushing your local branch".colorize(:blue) | |
Rake::Task["dev:heroku:push"].invoke | |
puts "Setup database".colorize(:blue) | |
Rake::Task["dev:heroku:db_setup"].invoke | |
puts "Spin up worker".colorize(:blue) | |
puts Cocaine::CommandLine.new(HEROKU_CMD, "ps:scale worker=1").run | |
puts "Finalizing app with restart".colorize(:blue) | |
puts Cocaine::CommandLine.new(HEROKU_CMD, "restart").run | |
eos = %Q{ | |
▄████ ▓█████▄▄▄█████▓ ▄▄▄▄ ▓█████ ██▒ █▓▓█████ ██▓ | |
██▒ ▀█▒▓█ ▀▓ ██▒ ▓▒▓█████▄ ▓█ ▀▓██░ █▒▓█ ▀ ▓██▒ | |
▒██░▄▄▄░▒███ ▒ ▓██░ ▒░▒██▒ ▄██▒███ ▓██ █▒░▒███ ▒██░ | |
░▓█ ██▓▒▓█ ▄░ ▓██▓ ░ ▒██░█▀ ▒▓█ ▄ ▒██ █░░▒▓█ ▄ ▒██░ | |
░▒▓███▀▒░▒████▒ ▒██▒ ░ ░▓█ ▀█▓░▒████▒ ▒▀█░ ░▒████▒░██████▒ | |
░▒ ▒ ░░ ▒░ ░ ▒ ░░ ░▒▓███▀▒░░ ▒░ ░ ░ ▐░ ░░ ▒░ ░░ ▒░▓ ░ | |
░ ░ ░ ░ ░ ░ ▒░▒ ░ ░ ░ ░ ░ ░░ ░ ░ ░░ ░ ▒ ░ | |
░ ░ ░ ░ ░ ░ ░ ░ ░░ ░ ░ ░ | |
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ | |
░ ░} | |
puts eos.force_encoding('UTF-8').colorize(:red) | |
puts "ready to go \\m/,".colorize(:red) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup
pow.env
gem "cocaine"
to yourGemfile