Last active
December 29, 2015 01:09
-
-
Save dbellotti/7590874 to your computer and use it in GitHub Desktop.
Revisions
-
dbellotti renamed this gist
Nov 21, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # sample rake tasks for deploying to cloud foundry require 'fileutils' namespace :cf do -
dbellotti created this gist
Nov 21, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ require 'fileutils' namespace :cf do desc 'Deploy to staging on Cloud Foundry' task :deploy_staging do deploy('staging') end desc 'Deploy to production on Cloud Foundry' task :deploy_production do deploy('production') end def deploy(environment) cf_target = 'api.run.pivotal.io' deploy_space = 'space_name' deploy_org = "pivotallabs" deploy_repo_subdir = "tmp/cf_deploy" tmp_copy_dir = "/tmp/cf_deploy" check_for_cli check_for_dirty_git # Copy repo to tmp dir so we can continue working while it deploys puts "Copying repo to #{deploy_repo_subdir}..." FileUtils.rm_rf("#{Rails.root.to_s}/#{deploy_repo_subdir}") FileUtils.cp_r Rails.root.to_s, tmp_copy_dir FileUtils.mv tmp_copy_dir, "#{Rails.root.to_s}/#{deploy_repo_subdir}" # Change working directory to copied repo Dir.chdir("#{Rails.root.to_s}/#{deploy_repo_subdir}") # Delete symbolic links before deploy because cf doesn't like them sh 'find . -type l -exec rm -f {} \;' sh "cf target #{cf_target} -o #{deploy_org} -s #{deploy_space}" sh "cf push -m config/cf-#{environment}.yml" end def check_for_cli sh 'cf -v' do |ok, res| raise "The CloudFoundry CLI is required. Run: gem install cf" unless ok end end def check_for_dirty_git if `git status --porcelain`.present? puts "Unstaged or uncommitted changes will be deployed! continue? (y/n)" raise "Aborted!" unless STDIN.gets.strip == "y" end end end