2019-07-24 23:51:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Genera un ZIP a partir del sitio ya construido
|
|
|
|
#
|
|
|
|
# TODO: Firmar con minisign
|
|
|
|
class DeployZip < Deploy
|
2019-07-25 17:25:00 +00:00
|
|
|
store :values, accessors: %i[fqdn destination file path], coder: JSON
|
2019-07-24 23:51:29 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
#
|
2019-07-26 00:07:53 +00:00
|
|
|
# rubocop:disable Metrics/MethodLength
|
|
|
|
# rubocop:disable Metrics/AbcSize
|
2019-07-24 23:51:29 +00:00
|
|
|
def deploy
|
2019-07-26 00:07:53 +00:00
|
|
|
time_start
|
2019-07-24 23:51:29 +00:00
|
|
|
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
|
2019-07-26 00:07:53 +00:00
|
|
|
time_stop
|
|
|
|
|
|
|
|
build_stats.create action: 'zip',
|
|
|
|
seconds: time_spent_in_seconds,
|
|
|
|
bytes: size
|
2019-07-24 23:51:29 +00:00
|
|
|
|
|
|
|
File.exist? path
|
|
|
|
end
|
2019-07-26 00:07:53 +00:00
|
|
|
# rubocop:enable Metrics/MethodLength
|
|
|
|
# rubocop:enable Metrics/AbcSize
|
|
|
|
|
|
|
|
def limit
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
|
|
|
def size
|
|
|
|
File.size path
|
|
|
|
end
|
2019-07-24 23:51:29 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Copiamos de DeployLocal para no cargar todos los métodos de
|
|
|
|
# compilación...
|
|
|
|
def fqdn!
|
2019-07-25 18:51:32 +00:00
|
|
|
self.fqdn ||= "#{site.name}.#{Site.domain}"
|
2019-07-24 23:51:29 +00:00
|
|
|
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
|