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
|
2022-03-15 19:03:16 +00:00
|
|
|
def deploy(output: false)
|
2020-01-24 15:12:49 +00:00
|
|
|
return false unless mkdir
|
2022-03-15 19:03:16 +00:00
|
|
|
return false unless yarn(output: output)
|
2023-02-06 19:09:51 +00:00
|
|
|
return false unless pnpm(output: output)
|
2022-03-15 19:03:16 +00:00
|
|
|
return false unless bundle(output: output)
|
2020-01-24 15:12:49 +00:00
|
|
|
|
2022-03-15 19:03:16 +00:00
|
|
|
jekyll_build(output: output)
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Sólo permitimos un deploy local
|
|
|
|
def limit
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
2022-04-06 23:07:14 +00:00
|
|
|
def url
|
|
|
|
site.url
|
|
|
|
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
|
2022-04-06 23:54:35 +00:00
|
|
|
@size ||= begin
|
|
|
|
paths = [destination, File.join(destination, '**', '**')]
|
2019-07-26 00:07:53 +00:00
|
|
|
|
2022-04-06 23:54:35 +00:00
|
|
|
Dir.glob(paths).map do |file|
|
|
|
|
if File.symlink? file
|
|
|
|
0
|
|
|
|
else
|
|
|
|
File.size(file)
|
|
|
|
end
|
|
|
|
end.inject(:+)
|
|
|
|
end
|
2019-07-26 00:07:53 +00:00
|
|
|
end
|
|
|
|
|
2019-09-25 16:05:18 +00:00
|
|
|
def destination
|
|
|
|
File.join(Rails.root, '_deploy', site.hostname)
|
|
|
|
end
|
|
|
|
|
2022-04-15 13:39:44 +00:00
|
|
|
# Libera espacio eliminando archivos temporales
|
|
|
|
#
|
|
|
|
# @return [nil]
|
|
|
|
def cleanup!
|
|
|
|
FileUtils.rm_rf(gems_dir)
|
|
|
|
FileUtils.rm_rf(yarn_cache_dir)
|
|
|
|
FileUtils.rm_rf(File.join(site.path, 'node_modules'))
|
|
|
|
FileUtils.rm_rf(File.join(site.path, '.sass-cache'))
|
|
|
|
FileUtils.rm_rf(File.join(site.path, '.jekyll-cache'))
|
|
|
|
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
|
2022-10-05 21:44:23 +00:00
|
|
|
#
|
|
|
|
# @return [Hash]
|
2019-07-24 23:51:29 +00:00
|
|
|
def env
|
2019-07-26 00:07:53 +00:00
|
|
|
# XXX: This doesn't support Windows paths :B
|
2023-02-06 19:16:27 +00:00
|
|
|
paths = [File.dirname(`which bundle`), '/usr/local/bin', '/usr/bin', '/bin']
|
2019-07-24 23:51:29 +00:00
|
|
|
|
2022-10-05 21:44:23 +00:00
|
|
|
# Las variables de entorno extra no pueden superponerse al local.
|
|
|
|
extra_env.merge({
|
|
|
|
'HOME' => home_dir,
|
|
|
|
'PATH' => paths.join(':'),
|
|
|
|
'SPREE_API_KEY' => site.tienda_api_key,
|
|
|
|
'SPREE_URL' => site.tienda_url,
|
|
|
|
'AIRBRAKE_PROJECT_ID' => site.id.to_s,
|
|
|
|
'AIRBRAKE_PROJECT_KEY' => site.airbrake_api_key,
|
|
|
|
'JEKYLL_ENV' => Rails.env,
|
|
|
|
'LANG' => ENV['LANG'],
|
|
|
|
'YARN_CACHE_FOLDER' => yarn_cache_dir
|
|
|
|
})
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
|
2021-12-09 13:42:03 +00:00
|
|
|
def yarn_cache_dir
|
2021-12-24 01:47:15 +00:00
|
|
|
Rails.root.join('_yarn_cache').to_s
|
2021-12-09 13:42:03 +00:00
|
|
|
end
|
|
|
|
|
2023-02-06 19:09:51 +00:00
|
|
|
def pnpm_cache_dir
|
|
|
|
Rails.root.join('_pnpm_cache').to_s
|
|
|
|
end
|
|
|
|
|
2019-07-24 23:51:29 +00:00
|
|
|
def yarn_lock
|
|
|
|
File.join(site.path, 'yarn.lock')
|
|
|
|
end
|
|
|
|
|
|
|
|
def yarn_lock?
|
|
|
|
File.exist? yarn_lock
|
|
|
|
end
|
|
|
|
|
2022-03-15 19:03:16 +00:00
|
|
|
def gem(output: false)
|
|
|
|
run %(gem install bundler --no-document), output: output
|
2020-01-24 15:12:49 +00:00
|
|
|
end
|
|
|
|
|
2023-02-06 19:09:51 +00:00
|
|
|
def pnpm_lock
|
|
|
|
File.join(site.path, 'pnpm-lock.yaml')
|
|
|
|
end
|
|
|
|
|
|
|
|
def pnpm_lock?
|
|
|
|
File.exist? pnpm_lock
|
|
|
|
end
|
|
|
|
|
2019-07-24 23:51:29 +00:00
|
|
|
# Corre yarn dentro del repositorio
|
2022-03-15 19:03:16 +00:00
|
|
|
def yarn(output: false)
|
2021-08-07 18:55:00 +00:00
|
|
|
return true unless yarn_lock?
|
2019-07-24 23:51:29 +00:00
|
|
|
|
2022-03-15 19:03:16 +00:00
|
|
|
run 'yarn install --production', output: output
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|
|
|
|
|
2023-03-27 17:08:19 +00:00
|
|
|
def pnpm(output: false)
|
2023-02-06 19:09:51 +00:00
|
|
|
return true unless pnpm_lock?
|
|
|
|
|
2023-03-27 17:08:19 +00:00
|
|
|
run %(pnpm config set store-dir "#{pnpm_cache_dir}"), output: output
|
|
|
|
run 'pnpm install --production', output: output
|
|
|
|
end
|
|
|
|
|
|
|
|
def bundle(output: false)
|
|
|
|
run %(bundle install --no-cache --path="#{gems_dir}" --clean --without test development), output: output
|
2023-02-06 19:09:51 +00:00
|
|
|
end
|
|
|
|
|
2022-03-15 19:03:16 +00:00
|
|
|
def jekyll_build(output: false)
|
|
|
|
run %(bundle exec jekyll build --trace --profile --destination "#{escaped_destination}"), output: output
|
2019-07-24 23:51:29 +00:00
|
|
|
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
|
2022-10-05 21:44:23 +00:00
|
|
|
|
|
|
|
# Consigue todas las variables de entorno configuradas por otros
|
|
|
|
# deploys.
|
|
|
|
#
|
2023-03-27 17:44:22 +00:00
|
|
|
# @deprecated Solo tenía sentido para Distributed Press v0
|
2022-10-05 21:44:23 +00:00
|
|
|
# @return [Hash]
|
|
|
|
def extra_env
|
|
|
|
@extra_env ||=
|
|
|
|
non_local_deploys.reduce({}) do |extra_env, deploy|
|
|
|
|
extra_env.tap do |e|
|
|
|
|
e.merge! deploy.local_env
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-24 23:51:29 +00:00
|
|
|
end
|