Skip to content

Instantly share code, notes, and snippets.

@julian7
Created July 14, 2010 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julian7/475613 to your computer and use it in GitHub Desktop.
Save julian7/475613 to your computer and use it in GitHub Desktop.
rvm_gemset_create_on_use_flag=1
rvm use 1.9.2@APPNAME > /dev/null
alias god='god -p APPNAME'
# put the following line to your ~/.rvmrc if you want to have alias setting here:
# unalias god 2>/dev/null
# #{Rails.root}/lib/generators/<appname>/configurations_generator.rb
class Appname::ConfigurationsGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
def unicorn_god
template 'unicorn.god', 'config/unicorn.god'
end
end
# put it to #{Rails.root}/config/deploy.rb
deploy.template = :rails3tags
deploy.repository = "path@to.repo/access/path.git"
# if you use built-in caches for javascripts and stylesheets, set cache_dirs
deploy.cache_dirs = %w(public/javascripts/main.js public/stylesheets/main.css)
case ENV['environment']
when 'production'
deploy.application = "APPNAME"
deploy.user = "USERNAME"
deploy.hosts = ["PROD.SERVER.NAME"]
deploy.path = "/home/#{deploy.user}/apps"
deploy.server = :godlike
deploy.god_group = "APPNAME"
deploy.tag = "rls-VERSION"
before_restarting_server do
run "rails g APPNAME:configurations #{ENV['environment']} -f"
run "which -s newrelic_cmd && newrelic_cmd deployments"
end
when 'staging'
deploy.application = "APPNAME-staging"
deploy.user = "USERNAME"
deploy.hosts = ["STG.SERVER.NAME"]
deploy.path = "/home/#{deploy.user}/apps"
deploy.server = :godlike
deploy.god_group = "APPNAME"
deploy.tag = "stg-VERSION"
before_restarting_server do
run "rails g APPNAME:configurations #{ENV['environment']} -f"
run "which -s newrelic_cmd && newrelic_cmd deployments"
end
end
# put it to #{Rails.root}/lib/inploy/godlike.rb
module Inploy
module Servers
module Godlike
attr_accessor :god_group
def god_cmd
"god -p #{god_group}"
end
def start_server
run "#{god_cmd} status > /dev/null || #{god_cmd}"
end
def restart_server
start_server
Dir.glob('config/*.god').each do |conf|
run "#{god_cmd} load #{conf}"
end
run "#{god_cmd} restart #{god_group}"
end
end
end
end
# put it to #{Rails.root}/lib/inploy/rails3tags.rb
module Inploy
module Templates
module Rails3tags
attr_accessor :tag
def inploy_task(subtask)
"rake inploy:local:#{subtask} RAILS_ENV=#{environment} environment=#{environment}#{skip_steps_cmd}"
end
def install_gems_cmd
'bundle install --without test development'
end
def remote_setup
commands = []
commands << "cd #{path}"
commands << "git clone --depth 1 #{repository} #{application}"
commands << "cd #{application}"
if !@tag.nil? and !@tag.empty?
commands << "git checkout -f #{tag}"
elsif !branch.eql? 'master'
commands << "git checkout -f -b #{branch} origin/#{branch}"
end
commands << install_gems_cmd
remote_run commands.join(" && ")
end
def remote_update
commands = []
commands << "cd #{application_path}"
commands << install_gems_cmd
commands << inploy_task(:update)
remote_run commands.join(' && ')
end
def install_gems
end
def update_code
run ["git checkout -f", "git pull origin #{tag || branch}"].join(' && ')
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment