Skip to content

Instantly share code, notes, and snippets.



Forked from stas/deploy.rb
Created Sep 24, 2015
What would you like to do?
Mina Deploy Task (Rails + Puma + Delay Job + rbenv)
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv' # for rbenv support. (
# require 'mina/rvm' # for rvm support. (
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
# branch - Branch name to deploy. (needed by mina/git)
set :codename, 'myAwesomeProject'
set :port, '8000'
set :user, 'deployer'
set :domain, ''
set :deploy_to, "/home/#{user}/#{codename}"
set :repository, ''
set :branch, 'master'
set :pid_file, "#{deploy_to}/shared/tmp/pids/#{rails_env}.pid"
set :app_port, '3001'
set :app_path, lambda { "#{deploy_to}/#{current_path}" }
# Manually create these paths in shared/
# (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, ['config/database.yml', 'log', 'tmp']
# Optional settings:
# set :user, 'foobar' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
# If you're using rbenv, use this to load the rbenv environment.
# Be sure to commit your .rbenv-version to your repository.
invoke :'rbenv:load'
# For those using RVM, use this to load an RVM version@gemset.
# invoke :'rvm:use[ruby-1.9.3-p125@default]'
# Put any custom mkdir's in here for when `mina setup` is ran.
# For Rails apps, we'll make some of the shared paths that are shared between
# all releases.
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/shared/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
queue! %[mkdir -p "#{deploy_to}/shared/tmp/pids"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]
queue! %[mkdir -p "#{deploy_to}/shared/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
queue! %[touch "#{deploy_to}/shared/config/database.yml"]
queue! %[echo "-----> Be sure to edit 'shared/config/database.yml'."]
desc "Deploys the current version to the server."
task :deploy => :environment do
deploy do
to :prepare do
invoke :stop
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
to :launch do
invoke :start
desc 'Starts the application'
task :start => :environment do
queue "cd #{app_path} ; bundle exec rackup -s puma " +
"-p #{app_port} -P #{pid_file} -E #{rails_env} -D"
queue "cd #{app_path} ; RAILS_ENV=#{rails_env} ./script/delayed_job start"
desc 'Stops the application'
task :stop => :environment do
queue "cd #{app_path} ; RAILS_ENV=#{rails_env} ./script/delayed_job stop"
queue %[kill -9 `cat #{pid_file}`]
desc 'Restarts the application'
task :restart => :environment do
invoke :stop
invoke :start
desc 'Installs dependent OS packages/libs along with latest rbenv'
task 'rbenv:prepare' do
queue! 'echo "Make sure these are installed:"'
queue! 'echo "git-core libxml2-dev libxslt1-dev libreadline-dev libssl-dev ' +
'openssl zlib1g-dev zlib1g libyaml-dev build-essential libpq-dev"'
queue 'git clone git:// ~/.rbenv'
queue 'git clone git:// ' +
queue %[echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile]
queue %[source ~/.bash_profile]
queue %[echo 'eval "$(rbenv init -)"' >> ~/.bash_profile]
desc 'Uses rbenv-build to install ruby-1.9.3-p327'
task 'rbenv:install:1.9.3-p327' => :environment do
invoke 'rbenv:prepare'
queue 'rbenv install 1.9.3-p327'
queue 'rbenv local 1.9.3-p327'
queue 'gem install bundler'
queue 'rbenv rehash'
# For help in making your deploy script, see the Mina documentation:
# -
# -
# -
# -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.