forked from ryanirelan/hivelogic-ee-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.rb
136 lines (108 loc) · 6.17 KB
/
deploy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
################################################################################
# Capistrano recipe for deploying ExpressionEngine websites from GitHub #
# By Dan Benjamin - http://example.com/ #
################################################################################
##### Settings #####
# the name of your website - should also be the name of the directory
set :application, "example.com"
# the name of your system directory, which you may have customized
set :ee_system, "system"
# the path to your new deployment directory on the server
# by default, the name of the application (e.g. "/var/www/sites/example.com")
set :deploy_to, "/var/www/sites/#{application}"
# the path to the old (non-capistrano) ExpressionEngine installation
set :ee_previous_path, "/var/www/sites/oldsite"
# the git-clone url for your repository
set :repository, "[email protected]:you/project.git"
# the branch you want to clone (default is master)
set :branch, "master"
# the name of the deployment user-account on the server
set :user, "deploy"
##### You shouldn't need to edit below unless you're customizing #####
# Additional SCM settings
set :scm, :git
set :ssh_options, { :forward_agent => true }
set :deploy_via, :remote_cache
set :copy_strategy, :checkout
set :keep_releases, 3
set :use_sudo, false
set :copy_compression, :bz2
# Roles
role :app, "#{application}"
role :web, "#{application}"
role :db, "#{application}", :primary => true
# Deployment process
after "deploy:update", "deploy:cleanup"
after "deploy", "deploy:set_permissions", "deploy:create_symlinks"
# Custom deployment tasks
namespace :deploy do
desc "This is here to overide the original :restart"
task :restart, :roles => :app do
# do nothing but overide the default
end
task :finalize_update, :roles => :app do
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
# overide the rest of the default method
end
desc "Create additional EE directories and set permissions after initial setup"
task :after_setup, :roles => :app do
# create upload directories
run "mkdir -p #{deploy_to}/#{shared_dir}/config"
run "mkdir -p #{deploy_to}/#{shared_dir}/assets"
run "mkdir -p #{deploy_to}/#{shared_dir}/assets/images"
run "mkdir -p #{deploy_to}/#{shared_dir}/assets/images/avatars/uploads"
run "mkdir -p #{deploy_to}/#{shared_dir}/assets/images/captchas"
run "mkdir -p #{deploy_to}/#{shared_dir}/assets/images/member_photos"
run "mkdir -p #{deploy_to}/#{shared_dir}/assets/images/pm_attachments"
run "mkdir -p #{deploy_to}/#{shared_dir}/assets/images/signature_attachments"
run "mkdir -p #{deploy_to}/#{shared_dir}/assets/images/uploads"
# set permissions
run "chmod 777 #{deploy_to}/#{shared_dir}/assets/images/avatars/uploads"
run "chmod 777 #{deploy_to}/#{shared_dir}/assets/images/captchas"
run "chmod 777 #{deploy_to}/#{shared_dir}/assets/images/member_photos"
run "chmod 777 #{deploy_to}/#{shared_dir}/assets/images/pm_attachments"
run "chmod 777 #{deploy_to}/#{shared_dir}/assets/images/signature_attachments"
run "chmod 777 #{deploy_to}/#{shared_dir}/assets/images/uploads"
end
desc "Copy user-uploaded content from existing installation to shared directory"
task :copy_content, :roles => :app do
# copy the content
run "cp -n #{ee_previous_path}/images/avatars/uploads/* #{deploy_to}/#{shared_dir}/assets/images/avatars/uploads"
run "cp -n #{ee_previous_path}/images/captchas/* #{deploy_to}/#{shared_dir}/assets/images/captchas"
run "cp -n #{ee_previous_path}/images/member_photos/* #{deploy_to}/#{shared_dir}/assets/images/member_photos"
run "cp -n #{ee_previous_path}/images/pm_attachments/* #{deploy_to}/#{shared_dir}/assets/images/pm_attachments"
run "cp -n #{ee_previous_path}/images/signature_attachments/* #{deploy_to}/#{shared_dir}/assets/images/signature_attachments"
run "cp -n #{ee_previous_path}/images/uploads/* #{deploy_to}/#{shared_dir}/assets/images/uploads"
# reset permissions
run "chmod -R 777 #{deploy_to}/#{shared_dir}/assets/images/avatars/uploads"
run "chmod -R 777 #{deploy_to}/#{shared_dir}/assets/images/captchas"
run "chmod -R 777 #{deploy_to}/#{shared_dir}/assets/images/member_photos"
run "chmod -R 777 #{deploy_to}/#{shared_dir}/assets/images/pm_attachments"
run "chmod -R 777 #{deploy_to}/#{shared_dir}/assets/images/signature_attachments"
run "chmod -R 777 #{deploy_to}/#{shared_dir}/assets/images/uploads"
end
desc "Set the correct permissions for the config files and cache folder"
task :set_permissions, :roles => :app do
run "chmod 666 #{current_release}/path.php"
run "chmod 777 #{current_release}/#{ee_system}/cache/"
run "chmod 666 #{current_release}/#{ee_system}/config_bak.php"
end
desc "Create symlinks to shared data such as config files and uploaded images"
task :create_symlinks, :roles => :app do
# the config file
run "ln -s #{deploy_to}/#{shared_dir}/config/config.php #{current_release}/#{ee_system}/config.php"
# standard image upload directories
run "ln -s #{deploy_to}/#{shared_dir}/assets/images/avatars/uploads #{current_release}/images/avatars/uploads"
run "ln -s #{deploy_to}/#{shared_dir}/assets/images/captchas #{current_release}/images/captchas"
run "ln -s #{deploy_to}/#{shared_dir}/assets/images/member_photos #{current_release}/images/member_photos"
run "ln -s #{deploy_to}/#{shared_dir}/assets/images/pm_attachments #{current_release}/images/pm_attachments"
run "ln -s #{deploy_to}/#{shared_dir}/assets/images/signature_attachments #{current_release}/images/signature_attachments"
run "ln -s #{deploy_to}/#{shared_dir}/assets/images/uploads #{current_release}/images/uploads"
end
desc "Clear the ExpressionEngine caches"
task :clear_cache, :roles => :app do
run "if [ -e #{current_release}/#{ee_system}/cache/db_cache ]; then rm -r #{current_release}/#{ee_system}/cache/db_cache/*; fi"
run "if [ -e #{current_release}/#{ee_system}/cache/page_cache ]; then rm -r #{current_release}/#{ee_system}/cache/page_cache/*; fi"
run "if [ -e #{current_release}/#{ee_system}/cache/magpie_cache ]; then rm -r #{current_release}/#{ee_system}/cache/magpie_cache/*; fi"
end
end