Skip to content

Instantly share code, notes, and snippets.

@purwandi
Created November 19, 2012 13:09
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save purwandi/4110547 to your computer and use it in GitHub Desktop.
Save purwandi/4110547 to your computer and use it in GitHub Desktop.
Laravel Capistrano Receipes

$ mkdir /home/purwandi/www/app

Selanjutnya melakukan setup dulu dengan melakukan langkah sebagai berikut

$cd /home/purwandi/www/app
$capify
set :application, "App Name" # Your app name
set :repository, "git@github.com:xxxxx/xxx.git" # Your git repository
set :document_root, "/home/user/www/awesome_app"
set :deploy_via, :remote_cache
# SSH Settings
set :user, "user_ssh"
set :password, "password_ssh"
set :use_sudo, false
set :ssh_options, {:forward_agent => true}
set :copy_exclude, [".git",".gitignore"] # or any match like [".svn","/documents-on-repo-but-dont-deploy"]
set :keep_releases, 10 # only keep 10 version to save space
default_run_options[:pty] = true
role :app, "192.168.1.2"
role :web, "192.168.1.2"
# We need to over write a lot of the core functionality here
# since we don't need migrations, lots of the symlink stuff
# and server restarting.
# cap develop deploy:setup
# cap develop deploy:check
# cap develop deploy
task :develop do
set :branch, "develop"
set :deploy_to, "#{document_root}/develop"
end
# cap staging deploy:setup
# cap staging deploy:check
# cap staging deploy
task :staging do
set :branch, "staging"
set :deploy_to, "#{document_root}/staging"
end
# cap production deploy:setup
# cap production deploy:check
# cap production deploy
task :production do
set :branch, "master"
set :deploy_to, "#{document_root}/production"
end
# This is strictly for PHP deploys
namespace :deploy do
task :update do
transaction do
update_code
symlink
laravel_migrate
end
end
task :finalize_update do
transaction do
run "chmod -R g+w #{releases_path}/#{release_name}"
end
end
task :symlink do
transaction do
run "ln -nfs #{current_release} #{deploy_to}/#{current_dir}"
end
end
task :laravel_migrate do
transaction do
run "php #{deploy_to}/#{current_dir}/artisan migrate:install"
run "php #{deploy_to}/#{current_dir}/artisan migrate"
end
end
task :laravel_rollback do
run "php #{deploy_to}/#{current_dir}/artisan migrate:rollback"
end
task :restart do
transaction do
# set writable storage dir
run "chmod -R 777 #{deploy_to}/#{current_dir}/storage/cache"
run "chmod -R 777 #{deploy_to}/#{current_dir}/storage/database"
run "chmod -R 777 #{deploy_to}/#{current_dir}/storage/logs"
run "chmod -R 777 #{deploy_to}/#{current_dir}/storage/sessions"
run "chmod -R 777 #{deploy_to}/#{current_dir}/storage/views"
run "chmod -R 777 #{deploy_to}/#{current_dir}/storage/work"
# remove some junk file
run "rm -f #{deploy_to}/#{current_dir}/storage/cache/*"
run "rm -f #{deploy_to}/#{current_dir}/storage/views/*"
end
end
end
after "deploy:rollback", "deploy:laravel_rollback"
@williamli
Copy link

is it safe to do a after "deploy:rollback", "deploy:laravel_rollback"? not every deploy will have a larval db migration

@williamli
Copy link

what i find interesting is that you can use call 'php artisan down' before update and call 'php artisan up' after each update

@hotrush
Copy link

hotrush commented Jan 21, 2014

hm, what the best way to use different configs for each environment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment