2019-07-24 23:51:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-16 16:15:20 +00:00
|
|
|
require 'zip'
|
|
|
|
|
2019-07-24 23:51:29 +00:00
|
|
|
# Genera un ZIP a partir del sitio ya construido
|
|
|
|
#
|
|
|
|
# TODO: Firmar con minisign
|
|
|
|
class DeployZip < Deploy
|
2019-09-25 16:05:18 +00:00
|
|
|
store :values, accessors: %i[], coder: JSON
|
2019-07-24 23:51:29 +00:00
|
|
|
|
2023-03-18 16:42:47 +00:00
|
|
|
DEPENDENCIES = %i[deploy_local]
|
2023-03-17 21:38:47 +00:00
|
|
|
|
2019-07-24 23:51:29 +00:00
|
|
|
# Una vez que el sitio está generado, tomar todos los archivos y
|
|
|
|
# y generar un zip accesible públicamente.
|
|
|
|
#
|
2019-07-26 00:07:53 +00:00
|
|
|
# rubocop:disable Metrics/MethodLength
|
2023-03-18 16:54:19 +00:00
|
|
|
def deploy(output: false)
|
2019-09-24 22:24:45 +00:00
|
|
|
FileUtils.rm_f path
|
2019-07-26 00:07:53 +00:00
|
|
|
time_start
|
2023-03-18 16:54:19 +00:00
|
|
|
Zip::File.open(path, Zip::File::CREATE) do |zip|
|
|
|
|
Dir.glob(File.join(destination, '**', '**')).each do |file|
|
|
|
|
entry = Pathname.new(file).relative_path_from(destination).to_s
|
|
|
|
|
|
|
|
if File.directory? file
|
|
|
|
log "Creando directorio #{entry}", output
|
|
|
|
|
|
|
|
zip.mkdir(entry)
|
|
|
|
else
|
|
|
|
log "Comprimiendo #{entry}", output
|
|
|
|
zip.add(entry, file)
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-03-18 16:54:19 +00:00
|
|
|
|
2019-07-26 00:07:53 +00:00
|
|
|
time_stop
|
|
|
|
|
2023-03-18 16:54:19 +00:00
|
|
|
File.exist?(path).tap do |status|
|
|
|
|
build_stats.create action: 'zip',
|
|
|
|
seconds: time_spent_in_seconds,
|
|
|
|
bytes: size,
|
|
|
|
log: @log.join("\n"),
|
|
|
|
status: status
|
|
|
|
end
|
|
|
|
rescue Zip::Error => e
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { site: site.name })
|
|
|
|
|
2019-07-26 00:07:53 +00:00
|
|
|
build_stats.create action: 'zip',
|
2023-03-18 16:54:19 +00:00
|
|
|
seconds: 0,
|
|
|
|
bytes: 0,
|
|
|
|
log: @log.join("\n"),
|
|
|
|
status: false
|
2019-07-24 23:51:29 +00:00
|
|
|
|
2023-03-18 16:54:19 +00:00
|
|
|
false
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
2019-07-26 00:07:53 +00:00
|
|
|
# rubocop:enable Metrics/MethodLength
|
|
|
|
|
|
|
|
def limit
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
|
|
|
def size
|
|
|
|
File.size path
|
|
|
|
end
|
2019-07-24 23:51:29 +00:00
|
|
|
|
2023-03-18 16:54:19 +00:00
|
|
|
# @return [String]
|
2019-09-25 16:05:18 +00:00
|
|
|
def destination
|
2023-03-18 16:54:19 +00:00
|
|
|
Rails.root.join('_deploy', site.hostname).realpath.to_s
|
2023-03-20 15:20:50 +00:00
|
|
|
rescue Errno::ENOENT
|
|
|
|
Rails.root.join('_deploy', site.hostname).to_s
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
|
2019-09-25 16:05:18 +00:00
|
|
|
def file
|
|
|
|
"#{site.hostname}.zip"
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
|
2022-04-06 23:07:14 +00:00
|
|
|
def url
|
|
|
|
"#{site.url}#{file}"
|
|
|
|
end
|
|
|
|
|
2019-09-25 16:05:18 +00:00
|
|
|
def path
|
|
|
|
File.join(destination, file)
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
2023-03-18 16:54:19 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# @param :line [String]
|
|
|
|
# @param :output [Boolean]
|
|
|
|
def log(line, output)
|
|
|
|
@log ||= []
|
|
|
|
@log << line
|
|
|
|
|
|
|
|
puts line if output
|
|
|
|
end
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|