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

65 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
# Genera un ZIP a partir del sitio ya construido
#
# TODO: Firmar con minisign
class DeployZip < Deploy
store :values, accessors: %i[fqdn destination file path], coder: JSON
before_create :fqdn!, :destination!
before_create :file!, :path!
# Una vez que el sitio está generado, tomar todos los archivos y
# y generar un zip accesible públicamente.
#
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def deploy
time_start
Dir.chdir(destination) do
Zip::File.open(path, Zip::File::CREATE) do |z|
Dir.glob('./**/**').each do |f|
File.directory?(f) ? z.mkdir(f) : z.add(f, f)
end
end
end
time_stop
build_stats.create action: 'zip',
seconds: time_spent_in_seconds,
bytes: size
File.exist? path
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
def limit
1
end
def size
File.size path
end
private
# Copiamos de DeployLocal para no cargar todos los métodos de
# compilación...
def fqdn!
self.fqdn ||= "#{site.name}.#{Site.domain}"
end
def destination!
self.destination ||= File.join(Rails.root, '_deploy', fqdn)
end
def file!
self.file ||= "#{fqdn}.zip"
end
def path!
self.path = File.join(destination, file)
end
end