Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created December 13, 2013 00:23

Revisions

  1. juliocesar created this gist Dec 13, 2013.
    74 changes: 74 additions & 0 deletions Capfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    # Capistrano deployment file
    # ==========================
    #
    # Deployment requires that you can log in as "web", which means you'll
    # need it's password.

    require 'bundler/capistrano'

    set :rvm_ruby_string, :local # Use the same ruby as used locally for deployment
    set :rvm_autolibs_flag, "read-only" # More info: rvm help autolibs

    before 'deploy:setup', 'rvm:install_rvm' # Install RVM
    before 'deploy:setup', 'rvm:install_ruby' # Install Ruby and create gemset, OR:
    before 'deploy:setup', 'rvm:create_gemset' # Only create gemset

    require 'rvm/capistrano'

    load 'deploy'

    set :application, 'app-name'
    set :deploy_to, '/path/to/where/app/will/live'
    set :user, 'web'
    set :scm, :none
    set :repository, '.'
    set :deploy_via, :copy
    set :use_sudo, false
    set :app_server, :passenger

    server 'xxx.xxx.xxx.xxx', :app, :web

    namespace :gems do
    desc 'Runs bundler'
    task :bundler do
    run "cd #{current_path} && RAILS_ENV=production bundle install --deployment"
    end
    end

    namespace :deploy do
    desc 'Creates APP/tmp dir'
    task :create_tmp do
    run "mkdir -p #{current_path}/tmp"
    end

    desc 'Copies the database config into place'
    task :copy_db_config do
    run "cp ~/database.yml #{current_path}/config/database.yml"
    end

    desc 'Restarts Apache'
    task :restart do
    run "touch #{current_path}/tmp/restart.txt"
    end

    desc 'Ensures site is enabled and starts Apache'
    task :start do
    sudo 'a2ensite lector.io'
    sudo 'apache2ctl graceful'
    end

    desc 'Disables the virtual host'
    task :stop do
    sudo 'a2dissite lector.io'
    sudo 'apache2ctl graceful'
    end

    desc 'Compiles assets'
    task :compile_assets do
    run "RAILS_ENV=production bundle exec rake assets:precompile"
    end
    end

    after "deploy:symlink",
    "deploy:compile_assets",
    "deploy:create_tmp", "deploy:copy_db_config", "gems:bundler"