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-09-25 16:05:18 +00:00
|
|
|
store :values, accessors: %i[], coder: JSON
|
2019-07-24 23:51:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
def deploy
|
2020-01-24 15:12:49 +00:00
|
|
|
return false unless mkdir
|
|
|
|
return false unless yarn
|
|
|
|
return false unless bundle
|
|
|
|
|
|
|
|
jekyll_build
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Sólo permitimos un deploy local
|
|
|
|
def limit
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
2019-07-26 00:07:53 +00:00
|
|
|
# Obtener el tamaño de todos los archivos y directorios (los
|
|
|
|
# directorios son archivos :)
|
|
|
|
def size
|
|
|
|
paths = [destination, File.join(destination, '**', '**')]
|
|
|
|
|
|
|
|
Dir.glob(paths).map do |file|
|
|
|
|
File.size file
|
|
|
|
end.inject(:+)
|
|
|
|
end
|
|
|
|
|
2019-09-25 16:05:18 +00:00
|
|
|
def destination
|
|
|
|
File.join(Rails.root, '_deploy', site.hostname)
|
|
|
|
end
|
|
|
|
|
2019-07-24 23:51:29 +00:00
|
|
|
private
|
|
|
|
|
2019-09-16 16:15:20 +00:00
|
|
|
def mkdir
|
|
|
|
FileUtils.mkdir_p destination
|
|
|
|
end
|
|
|
|
|
2019-07-24 23:51:29 +00:00
|
|
|
# Un entorno que solo tiene lo que necesitamos
|
|
|
|
def env
|
2019-07-26 00:07:53 +00:00
|
|
|
# XXX: This doesn't support Windows paths :B
|
2019-09-20 13:31:46 +00:00
|
|
|
paths = [File.dirname(`which bundle`), '/usr/bin', '/bin']
|
2019-07-24 23:51:29 +00:00
|
|
|
|
2019-09-19 13:20:27 +00:00
|
|
|
{
|
|
|
|
'HOME' => home_dir,
|
|
|
|
'PATH' => paths.join(':'),
|
2020-01-24 15:12:49 +00:00
|
|
|
'JEKYLL_ENV' => Rails.env,
|
|
|
|
'LANG' => ENV['LANG']
|
2019-09-19 13:20:27 +00:00
|
|
|
}
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def yarn_lock
|
|
|
|
File.join(site.path, 'yarn.lock')
|
|
|
|
end
|
|
|
|
|
|
|
|
def yarn_lock?
|
|
|
|
File.exist? yarn_lock
|
|
|
|
end
|
|
|
|
|
2020-01-24 15:12:49 +00:00
|
|
|
def gem
|
|
|
|
run %(gem install bundler --no-document)
|
|
|
|
end
|
|
|
|
|
2019-07-24 23:51:29 +00:00
|
|
|
# Corre yarn dentro del repositorio
|
|
|
|
def yarn
|
|
|
|
return unless yarn_lock?
|
|
|
|
|
|
|
|
run 'yarn'
|
|
|
|
end
|
|
|
|
|
|
|
|
def bundle
|
2019-09-19 13:54:21 +00:00
|
|
|
run %(bundle install --no-cache --path="#{gems_dir}")
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
|
2019-09-25 16:05:18 +00:00
|
|
|
# rubocop:disable Metrics/LineLength
|
2019-07-24 23:51:29 +00:00
|
|
|
def jekyll_build
|
2019-09-25 16:05:18 +00:00
|
|
|
run "bundle exec jekyll build --trace --destination \"#{escaped_destination}\""
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
2019-09-25 16:05:18 +00:00
|
|
|
# rubocop:enable Metrics/LineLength
|
2019-07-24 23:51:29 +00:00
|
|
|
|
|
|
|
# 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
|