5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 05:21:42 +00:00
panel/app/models/deploy_zip.rb

67 lines
1.3 KiB
Ruby
Raw 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[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
def deploy
2019-09-24 22:24:45 +00:00
FileUtils.rm_f path
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
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