5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-25 00:26:22 +00:00
panel/app/models/deploy_zip.rb

95 lines
2 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2019-09-16 16:15:20 +00:00
require 'zip'
# Genera un ZIP a partir del sitio ya construido
#
# TODO: Firmar con minisign
class DeployZip < Deploy
store :values, accessors: %i[], coder: JSON
2023-03-18 16:42:47 +00:00
DEPENDENCIES = %i[deploy_local]
# Una vez que el sitio está generado, tomar todos los archivos y
# y generar un zip accesible públicamente.
#
# 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
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)
end
end
end
2023-03-18 16:54:19 +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 })
build_stats.create action: 'zip',
2023-03-18 16:54:19 +00:00
seconds: 0,
bytes: 0,
log: @log.join("\n"),
status: false
2023-03-18 16:54:19 +00:00
false
end
# rubocop:enable Metrics/MethodLength
def limit
1
end
def size
File.size path
end
2023-03-18 16:54:19 +00:00
# @return [String]
def destination
2023-03-18 16:54:19 +00:00
Rails.root.join('_deploy', site.hostname).realpath.to_s
rescue Errno::ENOENT
Rails.root.join('_deploy', site.hostname).to_s
end
def file
"#{site.hostname}.zip"
end
2022-04-06 23:07:14 +00:00
def url
"#{site.url}#{file}"
end
def path
File.join(destination, file)
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
end