Class: Shuttle::Wordpress
Constant Summary
Shuttle::WordpressVip::VIP_URL
Shuttle::WordpressCli::CLI_GIT, Shuttle::WordpressCli::CLI_PATH
Constants included
from Helpers
Helpers::LEVEL_COLORS
Instance Attribute Summary
Attributes inherited from Deploy
#config, #environment, #ssh, #target, #version
Instance Method Summary
collapse
#plugin_custom_install, #plugin_install, #plugin_installed?
#vip_get_config, #vip_install, #vip_installed?, #vip_link, #vip_path, #vip_required?, #vip_update
#core_install, #core_installed?, #core_path, #core_remove
#cli_checkout_code, #cli_install, #cli_installed?, #cli_uninstall
Methods inherited from Strategy
#changes_at?, #checkout_code, #cleanup_release, #cleanup_releases, #connect, #debug?, #deploy_running?, #disable_history, #execute_commands, #execute_hook, #export_environment, #keep_releases, #link_release, #release_lock, #rollback, #update_code, #update_code_svn, #write_lock, #write_release, #write_revision
Methods inherited from Deploy
#available_releases, #initialize, #last_version
#current_path, #deploy_path, #release_path, #scm_path, #shared_path, #version_path
Methods included from Helpers
#deployer_hostname, #error, #git_installed?, #git_remote, #log, #release_exists?, #stream_output, #svn_installed?, #warn
Instance Method Details
#activate_theme ⇒ Object
208
209
210
211
212
213
214
215
|
# File 'lib/shuttle/deployment/wordpress.rb', line 208
def activate_theme
name = config.wordpress.theme
result = ssh.run("cd #{release_path} && wp theme activate #{name}")
if result.failure?
error "Unable to activate theme. Error: #{result.output}"
end
end
|
#check_config ⇒ Object
113
114
115
116
117
118
|
# File 'lib/shuttle/deployment/wordpress.rb', line 113
def check_config
if !ssh.file_exists?(shared_path('wordpress/core/wp-config.php'))
log "Creating wordpress config"
generate_config
end
end
|
#check_dependencies ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/shuttle/deployment/wordpress.rb', line 68
def check_dependencies
if !svn_installed?
log "Installing Subversion"
if ssh.run("sudo apt-get install -y subversion").success?
log "Subversion installed"
end
end
end
|
#check_plugins ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/shuttle/deployment/wordpress.rb', line 177
def check_plugins
plugins = config.wordpress.plugins
if plugins
if plugins.kind_of?(Array)
plugins.each do |p|
if p.kind_of?(String)
plugin_install(p)
elsif p.kind_of?(Hash)
name, url = p.to_a.flatten.map(&:to_s)
plugin_custom_install(name, url)
end
end
else
error "Config file has invalid plugins section"
end
end
end
|
#checkout_theme ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/shuttle/deployment/wordpress.rb', line 196
def checkout_theme
if config.wordpress
if config.wordpress.theme
checkout_code("wp-content/themes/#{config.wordpress.theme}")
else
error "Theme name is not defined."
end
else
error "Config does not contain 'wordpress' section"
end
end
|
#deploy ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/shuttle/deployment/wordpress.rb', line 46
def deploy
setup
update_code
link_shared_data
checkout_theme
if vip_required?
vip_install if !vip_installed?
vip_link
end
if !site_installed?
site_install
network_install
end
check_plugins
activate_theme
link_release
end
|
#generate_config ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/shuttle/deployment/wordpress.rb', line 90
def generate_config
mysql = config.wordpress.mysql
if mysql.nil?
error "Missing :mysql section of the config."
end
cmd = [
"wp core config",
"--dbname=#{mysql.database}",
"--dbhost=#{mysql.host || 'localhost'}",
"--dbuser=#{mysql.user}"
]
cmd << "--dbpass=#{mysql.password}" if mysql.password
res = ssh.run("cd #{core_path} && #{cmd.join(' ')}")
if res.success?
log "A new wordpress config has been generated"
else
error "Unable to generate config. Error: #{res.output}"
end
end
|
#link_shared_data ⇒ Object
169
170
171
172
173
174
175
|
# File 'lib/shuttle/deployment/wordpress.rb', line 169
def link_shared_data
log "Linking shared data"
ssh.run("cp -a #{core_path} #{release_path}")
ssh.run("cp #{shared_path('wp-config.php')} #{release_path('wp-config.php')}")
ssh.run("ln -s #{shared_path('wordpress/uploads')} #{release_path('wp-content/uploads')}")
end
|
#network_install ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/shuttle/deployment/wordpress.rb', line 153
def network_install
if config.wordpress.network
network = config.wordpress.network
cmd = [
"wp core install-network",
"--title=#{network.title}",
].join(' ')
result = ssh.run("cd #{release_path} && #{cmd}")
if result.failure?
error "Failed to setup WP network. #{result.output}"
end
end
end
|
#setup ⇒ Object
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
|
# File 'lib/shuttle/deployment/wordpress.rb', line 13
def setup
if config.wordpress.nil?
error "Please add :wordpress section to your config"
end
super
setup_shared_dirs
check_dependencies
if !cli_installed?
cli_install
else
version = ssh.capture("cd #{core_path} && wp --version")
version.gsub!('wp-cli', '').to_s.strip!
log "WordPress CLI version: #{version}"
end
if !core_installed?
core_install
else
res = ssh.run("cd #{core_path} && wp core version")
if res.success?
log "WordPress core version: #{res.output}"
else
warn "Unable to detect WordPress core version: #{res.output}"
end
end
check_config
end
|
#setup_shared_dirs ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/shuttle/deployment/wordpress.rb', line 77
def setup_shared_dirs
dirs = [
'wordpress',
'wordpress/uploads',
'wordpress/core',
'wordpress/plugins'
]
dirs.each do |path|
ssh.run("mkdir -p #{shared_path(path)}")
end
end
|
#site_install ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/shuttle/deployment/wordpress.rb', line 131
def site_install
if config.wordpress.site
site = config.wordpress.site
cmd = [
"wp core install",
"--url=#{site.url}",
"--title=#{site.title}",
"--admin_name=#{site.admin_name}",
"--admin_email=#{site.admin_email}",
"--admin_password=#{site.admin_password}"
].join(' ')
result = ssh.run("cd #{release_path} && #{cmd}")
if result.failure?
error "Failed to setup site. #{result.output}"
end
else
error "Please define :site section"
end
end
|
#site_installed? ⇒ Boolean
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/shuttle/deployment/wordpress.rb', line 120
def site_installed?
result = ssh.run("cd #{release_path} && wp core version")
if result.failure? && debug?
log "Wordpress core check failed:"
log result.output
end
result.success?
end
|