2019-07-24 23:51:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Alojamiento local, solo genera el sitio, con lo que no necesita hacer
|
|
|
|
# nada más
|
|
|
|
class DeployLocal < Deploy
|
2019-07-25 17:25:00 +00:00
|
|
|
store :values, accessors: %i[fqdn destination], coder: JSON
|
2019-07-24 23:51:29 +00:00
|
|
|
|
|
|
|
before_create :fqdn!, :destination!
|
|
|
|
before_destroy :remove_destination!
|
|
|
|
|
|
|
|
# Realizamos la construcción del sitio usando Jekyll y un entorno
|
|
|
|
# limpio para no pasarle secretos
|
|
|
|
#
|
|
|
|
# Pasamos variables de entorno mínimas para no filtrar secretos de
|
|
|
|
# Sutty
|
|
|
|
#
|
|
|
|
# TODO: Recolectar estadísticas y enviarlas a la base de datos
|
|
|
|
def deploy
|
|
|
|
yarn && bundle && jekyll_build
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sólo permitimos un deploy local
|
|
|
|
def limit
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Un entorno que solo tiene lo que necesitamos
|
|
|
|
def env
|
|
|
|
paths = [File.dirname(`which bundle`), '/usr/bin']
|
|
|
|
|
|
|
|
{ 'PATH' => paths.join(':'), 'JEKYLL_ENV' => 'production' }
|
|
|
|
end
|
|
|
|
|
|
|
|
def yarn_lock
|
|
|
|
File.join(site.path, 'yarn.lock')
|
|
|
|
end
|
|
|
|
|
|
|
|
def yarn_lock?
|
|
|
|
File.exist? yarn_lock
|
|
|
|
end
|
|
|
|
|
|
|
|
# Corre yarn dentro del repositorio
|
|
|
|
def yarn
|
|
|
|
return unless yarn_lock?
|
|
|
|
|
|
|
|
run 'yarn'
|
|
|
|
end
|
|
|
|
|
|
|
|
def bundle
|
|
|
|
run 'bundle'
|
|
|
|
end
|
|
|
|
|
|
|
|
def jekyll_build
|
|
|
|
run "bundle exec jekyll build --destination \"#{escaped_destination}\""
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# no debería haber espacios ni caracteres especiales, pero por si
|
|
|
|
# acaso...
|
|
|
|
def escaped_destination
|
|
|
|
Shellwords.escape destination
|
|
|
|
end
|
|
|
|
|
|
|
|
# Eliminar el destino si se elimina el deploy
|
|
|
|
def remove_destination!
|
|
|
|
FileUtils.rm_rf destination
|
|
|
|
end
|
|
|
|
end
|