Skip to content

Instantly share code, notes, and snippets.

@mul14
Created March 22, 2015 00:52
Show Gist options
  • Save mul14/427f504de5f8b5d5cbc4 to your computer and use it in GitHub Desktop.
Save mul14/427f504de5f8b5d5cbc4 to your computer and use it in GitHub Desktop.
Deploy Laravel 4 with mina http://mina-deploy.github.io/mina/
require 'mina/git'
# Fix the SSH password prompt problem
set :term_mode, nil
# 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 :domain, '192.168.10.10'
set :deploy_to, '/var/www/yourpath.com'
set :repository, 'git://repository...'
set :branch, 'master'
# 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, [
'.env.php',
'app/storage/cache',
'app/storage/logs',
'app/storage/sessions',
'app/storage/views',
'public'
]
# Optional settings:
set :user, 'vagrant' # 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-1.9.3-p125@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}/app/storage/cache"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/app/storage/logs"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/app/storage/sessions"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/app/storage/views"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/app/storage/cache"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/app/storage/logs"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/app/storage/sessions"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/app/storage/views"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/public"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/public"]
queue! %[touch "#{deploy_to}/#{shared_path}/.env.php"]
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/.env.php'."]
end
desc "Deploys the current version to the server."
task :deploy => :environment do
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 :'deploy:cleanup'
to :launch do
queue "cd #{deploy_to}/#{current_path}/"
queue 'composer update --no-scripts'
queue 'composer dump'
queue 'php artisan dump'
queue 'php artisan optimize'
queue 'php artisan migrate'
queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
end
end
end
desc "Rolls back the latest release"
task :rollback => :environment do
queue! %[echo "-----> Rolling back to previous release for instance: #{domain}"]
# Delete existing sym link and create a new symlink pointing to the previous release
queue %[echo -n "-----> Creating new symlink from the previous release: "]
queue %[ls "#{deploy_to}/releases" -Art | sort | tail -n 2 | head -n 1]
queue! %[ls -Art "#{deploy_to}/releases" | sort | tail -n 2 | head -n 1 | xargs -I active ln -nfs "#{deploy_to}/releases/active" "#{deploy_to}/current"]
# Remove latest release folder (active release)
queue %[echo -n "-----> Deleting active release: "]
queue %[ls "#{deploy_to}/releases" -Art | sort | tail -n 1]
queue! %[ls "#{deploy_to}/releases" -Art | sort | tail -n 1 | xargs -I active rm -rf "#{deploy_to}/releases/active"]
end
task :up => :environment do
queue! %[php artisan up]
end
task :down => :environment do
queue! %[php artisan down]
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