Skip to content

Instantly share code, notes, and snippets.

@redrick
Created November 6, 2015 08:33
Show Gist options
  • Save redrick/8163ec616b02d62a622c to your computer and use it in GitHub Desktop.
Save redrick/8163ec616b02d62a622c to your computer and use it in GitHub Desktop.
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
require 'mina/rvm' # for rvm support. (http://rvm.io)
# 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 :user, 'USER_NAME'
set :domain, 'DOMAIN'
set :deploy_to, '/var/www/REPO'
set :repository, '[email protected]:COMPANY/REPO'
set :branch, 'master'
set :rails_env, 'staging'
# For system-wide RVM install.
# set :rvm_path, '/usr/local/rvm/bin/rvm'
# 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', 'config/secrets.yml', 'log']
# Optional settings:
# set :user, 'foobar' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
set :forward_agent, true # SSH forward_agent.
# 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 .ruby-version or .rbenv-version to your repository.
# invoke :'rbenv:load'
# For those using RVM, use this to load an RVM version@gemset.
invoke :'rvm:use[ruby-2.2.1@default]'
# queue! %[bash -l -c "rvm use ruby-2.2.1@default"]
end
# 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_path}/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]
queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
queue! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"]
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml' and 'secrets.yml'."]
if repository
repo_host = repository.split(%r{@|://}).last.split(%r{:|\/}).first
repo_port = /:([0-9]+)/.match(repository) && /:([0-9]+)/.match(repository)[1] || '22'
queue %[
if ! ssh-keygen -H -F #{repo_host} &>/dev/null; then
ssh-keyscan -t rsa -p #{repo_port} -H #{repo_host} >> ~/.ssh/known_hosts
fi
]
end
end
desc "Deploys the current version to the server."
task :deploy => :environment do
to :before_hook do
# Put things to run locally before ssh
end
deploy do
# 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'
invoke :'deploy:cleanup'
to :launch do
invoke :'passenger:restart'
end
end
end
desc "Restarts the passenger server."
task :restart do
set :term_mode, :pretty
to :before do
queue %(
echo "-----> Copying files"
#{echo_cmd %[cp deploy/last_version deploy/last_version_2]}
)
end
invoke :'passenger:restart'
to :after do
queue "echo '-----> After'"
end
end
desc "Restart Nginx and Postgresql"
task :restart_services do
queue "sudo service nginx restart"
queue "sudo service postgresql restart"
end
namespace :passenger do
task :restart do
queue %{
echo "-----> Restarting passenger"
#{echo_cmd %[mkdir -p tmp]}
#{echo_cmd %[touch tmp/restart.txt]}
}
end
end
# For help in making your deploy script, see the Mina documentation:
#
# - http://nadarei.co/mina
# - http://nadarei.co/mina/tasks
# - http://nadarei.co/mina/settings
# - http://nadarei.co/mina/helpers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment