Skip to content

Instantly share code, notes, and snippets.

@danielres
Created March 11, 2011 13:53
Show Gist options
  • Save danielres/865899 to your computer and use it in GitHub Desktop.
Save danielres/865899 to your computer and use it in GitHub Desktop.
random personal notes and reminders related to my funny adventures with Heroku
# $APP=$1
# S3_KEY=$2
# S3_SECRET=$3
# S3_BUCKET=$4
# GEMS=$5
gem install heroku --no-rdoc --no-ri
refinerycms $APP --heroku -g aws-s3,refinerycms-inquiries
# ,$5
cd $APP
heroku keys:add ~/.ssh/id_rsa.pub
echo "Refinery.s3_backend = true" >> config/environments/production.rb
heroku config:add \
S3_KEY=$S3_KEY \
S3_SECRET=$S3_SECRET \
S3_BUCKET=$S3_BUCKET
git push heroku master
heroku rename px-$APP
# usage:
# 1)define environment variables:
# export S3_KEY="xxx"
# export S3_SECRET="xxx"
# export ROH_SUPERUSER_NAME="xxx"
# export ROH_SUPERUSER_EMAIL="xxx"
# export ROH_SUPERUSER_PASS="xxx"
# export ROH_SMTP_ADDRESS="xxx"
# export ROH_SMTP_USER_NAME="xxx"
# export ROH_SMTP_PASSWORD="xxx"
# export ROH_APP_PREFIX="xxx-"
# 2)source this file:
# source <(curl https://gist.github.com/raw/865899/refinery_on_heroku.sh)
# 3)execute:
# roh myapp "My site title"
#REFINERY ON HEROKU
function roh {
##PARAMS
export ROH_APP=$1
export ROH_SITE_NAME=$2
export ROH_GEMS=$3
export ROH_S3_BUCKET="$ROH_APP_PREFIX$ROH_APP"
##GENERATE
gem install heroku frahugo-s3sync --no-rdoc --no-ri
refinerycms $ROH_APP --heroku
cd $ROH_APP
##HEROKU: SSH AUTH
heroku keys:add ~/.ssh/id_rsa.pub
##S3
#FOR ALL ENVIRONMENTS
echo -e "\n ENV['S3_BUCKET']='$ROH_S3_BUCKET' \n" >> config/environment.rb
#FOR HEROKU
echo -e "\n Refinery.s3_backend = true \n " >> config/environments/production.rb && git commit -a -m "set s3_backend = true in production.rb"
#echo -e "\n Refinery.s3_backend = true \n " >> config/environments/development.rb && git commit -a -m "set s3_backend = true in development.rb"
heroku config:add S3_KEY=$S3_KEY S3_SECRET=$S3_SECRET # S3_BUCKET=$ROH_S3_BUCKET
s3cmd createbucket $ROH_S3_BUCKET
#FOR LOCAL DEV
export S3_BUCKET="$ROH_S3_BUCKET"
##EXTRA GEMS
refinery_install_inquiries
refinery_install_theming base
refinery_install_pixarea_compass_themes
##SMTP
refinery_setup_smtp
##HEROKU: PUBLISH
git push heroku master
heroku rename $ROH_APP
heroku rake db:migrate
roh_insert_superuser
roh_insert_default_settings
roh_restrict_all_settings
roh_unrestrict_settings "analytics_page_code i18n_translation_current_locale i18n_translation_default_frontend_locale i18n_translation_default_locale i18n_translation_frontend_locales menu_hide_children show_contact_privacy_link site_name theme"
##HEROKU: ADDONS
heroku_install_addons
}
function roh_insert_superuser {
heroku console --app $ROH_APP "
Role.create(:title => 'Refinery')
Role.create(:title => 'Superuser')
su = User.create(
:username => '$ROH_SUPERUSER_NAME',
:email => '$ROH_SUPERUSER_EMAIL',
:password => '$ROH_SUPERUSER_PASS'
)
su.roles << Role.find_by_title('Refinery')
su.roles << Role.find_by_title('Superuser')
su.save
"
}
function roh_insert_default_settings {
#needs global variable set:
#export $ROH_SITE_NAME="My Company"
heroku console --app $ROH_APP "
s=RefinerySetting.find_by_name('approximate_ascii')
s.value=true
s.save
s=RefinerySetting.find_by_name('frontend_refinery_stylesheets_enabled')
s.value=false
s.save
s=RefinerySetting.find_by_name('i18n_translation_current_locale')
s.value=:fr
s.save
s=RefinerySetting.find_by_name('i18n_translation_default_frontend_locale')
s.value=:fr
s.save
s=RefinerySetting.find_by_name('i18n_translation_default_locale')
s.value=:fr
s.save
s=RefinerySetting.find_by_name('i18n_translation_frontend_locales')
s.value=[:fr,:en]
s.save
s=RefinerySetting.find_by_name('site_name')
s.value=\"$ROH_SITE_NAME\"
s.save
s=RefinerySetting.find_by_name('use_google_ajax_libraries')
s.value=true
s.save
s=RefinerySetting.find_by_name('use_marketable_urls')
s.value=true
s.save
s=RefinerySetting.find_or_create_by_name('theme')
s.value='base'
s.save
"
}
function roh_restrict_all_settings {
heroku console "settings=RefinerySetting.all; settings.each{|s| s.restricted=true; s.save }"
}
function roh_unrestrict_settings {
SETTINGS=$1
for setting in $SETTINGS
do
command=$command"s=RefinerySetting.find_by_name('$setting'); s.restricted=false; s.save;"
done
heroku console "$command"
}
function refinery_uncomment_gem {
local GEM=$1
sed "s/# gem '$1'/gem '$1'/" Gemfile -i
}
function refinery_install_inquiries {
refinery_uncomment_gem refinerycms-inquiries && bundle
rails g refinerycms_inquiries
rake db:migrate
git add . && git commit -m "installed refinerycms_inquiries"
}
function refinery_install_theming {
local THEME=$1
refinery_uncomment_gem refinerycms-theming && bundle
rails g refinery_theme $THEME
git add . && git commit -m "installed refinerycms theme $THEME"
}
function refinery_install_pixarea_compass_themes {
echo "gem 'pixarea-compass-themes'" >> Gemfile && bundle
cd themes
compass create pixarea-themes -r pixarea-compass-themes -u pixarea-compass-themes --syntax sass
cd ..
}
function refinery_setup_smtp {
heroku config:add SMTP_ADDRESS=$ROH_SMTP_ADDRESS SMTP_USER_NAME=$ROH_SMTP_USER_NAME SMTP_PASSWORD=$ROH_SMTP_PASSWORD
echo "
# config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => ENV['SMTP_ADDRESS'],
:port => 25,
:user_name => ENV['SMTP_USER_NAME'],
:password => ENV['SMTP_PASSWORD'],
:authentication => :login
}
# config.action_mailer.raise_delivery_errors = true
" >> config/environment.rb
git add config/environment.rb
git commit -m "added smtp configuration in config/environment.rb"
}
function heroku_install_addons {
heroku addons:add releases:basic
heroku addons:add sendgrid:free
heroku addons:add custom_domains
heroku addons:add pgbackups
echo -e "----to add domains: \n heroku domains:add www.example.com \n heroku domains:add example.com"
}
# REMOVE REFINERY ON HEROKU APP
function roh_rmapp {
APP=$1
PREFIX=$ROH_APP_PREFIX
heroku destroy --app $APP --confirm $APP
rm -rf $APP
s3cmd deletebucket $PREFIX$APP
}
# DUPLICATE REFINERY ON HEROKU APP
function roh_cp {
SOURCE_APP=$1
TARGET_APP=$2
if [ -r $SOURCE_APP ]; then echo "Error: source dir already exists"; return; fi
if [ -r $TARGET_APP ]; then echo "Error: target dir already exists"; return; fi
ROH_S3_TARGET_APP_BUCKET="$ROH_APP_PREFIX$TARGET_APP"
# git clone source
git clone git@heroku.com:$SOURCE_APP.git
cd $SOURCE_APP
# pull db
heroku db:pull --app $SOURCE_APP --confirm $SOURCE_APP
# pg dump db
#heroku addons:add pgbackups
#heroku pgbackups:capture --expire && string=`heroku pgbackups | tail -1` && set -- string
#backup_id=$1 && backup_url=`heroku pgbackups:url $backup_id`
#wget $backup_url -O db/pgbackup.dump
# renaming all local stuff that have to be renamed
cd ..
cp -r $SOURCE_APP $TARGET_APP
cd $TARGET_APP
sed -i s/"url = git@heroku.com:$SOURCE_APP.git"/"url = git@heroku.com:$TARGET_APP.git"/ .git/config
# new heroku app
heroku create $TARGET_APP
heroku_install_addons
# push db
heroku db:push --app $TARGET_APP --confirm $TARGET_APP
# create S3 bucket
s3cmd createbucket px-$TARGET_APP
# heroku app config
heroku config:add S3_SECRET=$S3_SECRET S3_KEY=$S3_KEY S3_BUCKET=$ROH_S3_TARGET_APP_BUCKET
# update S3_BUCKET
sed s/"ENV\['S3_BUCKET']=.*"/"ENV['S3_BUCKET']='$ROH_S3_TARGET_APP_BUCKET'"/ config/environment.rb
# push to new heroku app
git push origin master
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment