deploy.rb
3.99 KB
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
set :application, 'crlg-web'
set :repo_url, 'git@git.gotenzing.com:jeffmbalicki/st_joseph.git'
# Branch options
# Prompts for the branch name (defaults to current branch)
#ask :branch, -> { `git rev-parse --abbrev-ref HEAD`.chomp }
# Hardcodes branch to always be master
# This could be overridden in a stage config file
set :branch, :master
set :keep_releases, 2
set :deploy_to, -> { "/var/www/html/production/#{fetch(:application)}" }
# Use :debug for more verbose output when troubleshooting
set :log_level, :info
# Put all shared files/directories here (e.g. uploads that need to go on the NFS drive)
set :linked_files, fetch(:linked_files, []).push('.env')
set :linked_dirs, fetch(:linked_dirs, []).push('wp-content/wflogs','wp-content/uploads', 'wp-content/storage', 'wp-content/languages', 'wp-content/cache' , 'wp-content/wp-rocket-config')
namespace :deploy do
desc 'Sync servers'
task :sync do
on roles(:web), in: :sequence, wait: 5 do
execute("si #{fetch(:application)}")
end
end
end
namespace :deploy do
desc 'Sync servers'
task :sync_again do
on roles(:web), in: :sequence, wait: 5 do
execute("si #{fetch(:application)}")
end
end
end
namespace :deploy do
desc 'Install composer packages'
task :install_theme_packages do
on roles(:web), in: :sequence, wait: 5 do
execute "cd '#{release_path}/wp-content/themes/crlg'; /usr/bin/php74 /home/tenzing_www/bin/composer install --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader"
end
end
end
namespace :deploy do
desc 'Install composer packages in root'
task :install_packages do
on roles(:web), in: :sequence, wait: 5 do
execute "cd '#{release_path}'; /usr/bin/php73 /home/tenzing_www/composer.phar install --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader"
end
end
end
# Override `git#create_release` to handle submodules
namespace :git do
desc 'Copy repo to releases'
task create_release: :'git:update' do
on roles(:all) do
with fetch(:git_environmental_variables) do
within repo_path do
execute :git, :clone, '-b', fetch(:branch), '--recursive', '.', release_path
end
end
end
end
end
# The above restart task is not run by default
# Uncomment the following line to run it on deploys if needed
# after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
desc 'Remove Git Files'
task :cleanup do
on roles(:web), in: :sequence, wait: 5 do
execute "cd '#{release_path}/'; rm -Rf .git/ "
end
end
end
#namespace :deploy do
# desc 'set file permissions'
# task :set_permissions do
# on roles(:web), in: :sequence, wait: 5 do
# execute "cd '#{release_path}/'; chmod -Rf 777 .htaccess wordfence-waf.php wp-content/advanced-cache.php "
# end
# end
# end
namespace :deploy do
desc 'Update WordPress template root paths to point to the new release'
task :update_option_paths do
on roles(:app) do
within fetch(:release_path) do
if test :wp, :core, 'is-installed'
[:stylesheet_root, :template_root].each do |option|
# Only change the value if it's an absolute path
# i.e. The relative path "/themes" must remain unchanged
# Also, the option might not be set, in which case we leave it like that
value = capture :wp, :option, :get, option, raise_on_non_zero_exit: false
if value != '' && value != '/themes'
execute :wp, :option, :set, option, fetch(:release_path).join('web/wp/wp-content/themes')
end
end
end
end
end
end
end
# The above update_option_paths task is not run by default
# Note that you need to have WP-CLI installed on your server
# Uncomment the following line to run it on deploys if needed
# after 'deploy:publishing', 'deploy:update_option_paths'
after 'deploy:updated', 'deploy:install_packages'
after 'deploy:updated', 'deploy:sync'
#after 'deploy:updated', 'deploy:set_permissions'
after 'deploy:finished', 'deploy:sync_again'