class Wordmove::Deployer::Base
Attributes
environment[R]
logger[R]
options[R]
Public Class Methods
current_dir()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 29 def current_dir '.' end
deployer_for(cli_options)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 9 def deployer_for(cli_options) movefile = Wordmove::Movefile.new(cli_options[:config]) movefile.load_dotenv(cli_options) options = movefile.fetch.merge! cli_options environment = movefile.environment(cli_options) return FTP.new(environment, options) if options[environment][:ftp] if options[environment][:ssh] && options[:global][:sql_adapter] == 'wpcli' return Ssh::WpcliSqlAdapter.new(environment, options) end if options[environment][:ssh] && options[:global][:sql_adapter] == 'default' return Ssh::DefaultSqlAdapter.new(environment, options) end raise NoAdapterFound, "No valid adapter found." end
logger(secrets)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 33 def logger(secrets) Logger.new(STDOUT, secrets).tap { |l| l.level = Logger::DEBUG } end
new(environment, options = {})
click to toggle source
# File lib/wordmove/deployer/base.rb, line 38 def initialize(environment, options = {}) @environment = environment.to_sym @options = options movefile_secrets = Wordmove::Movefile.new(options[:config]).secrets @logger = self.class.logger(movefile_secrets) end
Public Instance Methods
exclude_dir_contents(path)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 58 def exclude_dir_contents(path) "#{path}/*" end
pull_db()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 50 def pull_db logger.task "Pulling Database" end
pull_wordpress()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 73 def pull_wordpress logger.task "Pulling wordpress core" local_path = local_options[:wordpress_path] remote_path = remote_options[:wordpress_path] exclude_wp_content = exclude_dir_contents(remote_wp_content_dir.relative_path) exclude_paths = paths_to_exclude.push(exclude_wp_content) remote_get_directory(remote_path, local_path, exclude_paths) end
push_db()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 46 def push_db logger.task "Pushing Database" end
push_wordpress()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 62 def push_wordpress logger.task "Pushing wordpress core" local_path = local_options[:wordpress_path] remote_path = remote_options[:wordpress_path] exclude_wp_content = exclude_dir_contents(local_wp_content_dir.relative_path) exclude_paths = paths_to_exclude.push(exclude_wp_content) remote_put_directory(local_path, remote_path, exclude_paths) end
remote_get_directory()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 54 def remote_get_directory; end
remote_put_directory()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 56 def remote_put_directory; end
Protected Instance Methods
compress_command(path)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 158 def compress_command(path) command = ["gzip"] command << "-9" command << "-f" command << "\"#{path}\"" command.join(" ") end
download(url, local_path)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 98 def download(url, local_path) logger.task_step true, "download #{url} > #{local_path}" return true if simulate? File.open(local_path, 'w') do |file| file << URI.open(url).read end end
local_delete(path)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 174 def local_delete(path) logger.task_step true, "delete: '#{path}'" File.delete(path) unless simulate? end
local_options()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 188 def local_options options[:local].clone end
mysql_dump_command(options, save_to_path)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 128 def mysql_dump_command(options, save_to_path) command = ["mysqldump"] command << "--host=#{Shellwords.escape(options[:host])}" if options[:host].present? command << "--port=#{Shellwords.escape(options[:port])}" if options[:port].present? command << "--user=#{Shellwords.escape(options[:user])}" if options[:user].present? if options[:password].present? command << "--password=#{Shellwords.escape(options[:password])}" end command << "--result-file=\"#{save_to_path}\"" if options[:mysqldump_options].present? command << Shellwords.split(options[:mysqldump_options]) end command << Shellwords.escape(options[:name]) command.join(" ") end
mysql_import_command(dump_path, options)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 144 def mysql_import_command(dump_path, options) command = ["mysql"] command << "--host=#{Shellwords.escape(options[:host])}" if options[:host].present? command << "--port=#{Shellwords.escape(options[:port])}" if options[:port].present? command << "--user=#{Shellwords.escape(options[:user])}" if options[:user].present? if options[:password].present? command << "--password=#{Shellwords.escape(options[:password])}" end command << "--database=#{Shellwords.escape(options[:name])}" command << Shellwords.split(options[:mysql_options]) if options[:mysql_options].present? command << "--execute=\"SET autocommit=0;SOURCE #{dump_path};COMMIT\"" command.join(" ") end
paths_to_exclude()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 86 def paths_to_exclude remote_options[:exclude] || [] end
remote_options()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 184 def remote_options options[environment].clone end
run(command)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 90 def run(command) logger.task_step true, command return true if simulate? system(command) raise ShellCommandError, "Return code reports an error" unless $CHILD_STATUS.success? end
save_local_db(local_dump_path)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 179 def save_local_db(local_dump_path) # dump local mysql into file run mysql_dump_command(local_options[:database], local_dump_path) end
simulate?()
click to toggle source
# File lib/wordmove/deployer/base.rb, line 108 def simulate? options[:simulate] end
uncompress_command(path)
click to toggle source
# File lib/wordmove/deployer/base.rb, line 166 def uncompress_command(path) command = ["gzip"] command << "-d" command << "-f" command << "\"#{path}\"" command.join(" ") end