diff --git a/app/controllers/api/v1/sites_controller.rb b/app/controllers/api/v1/sites_controller.rb index 32fdae1d..10a92907 100644 --- a/app/controllers/api/v1/sites_controller.rb +++ b/app/controllers/api/v1/sites_controller.rb @@ -69,12 +69,11 @@ module Api end end + # Todos los dominios con WWW habilitado def www_names - Site.where(contact: true) - .or(Site.where(colaboracion_anonima: true)) - .select("'www.' || name as name").map(&:name).map do |name| - canonicalize name - end + Site.where(id: DeployWww.all.pluck(:site_id)).select("'www.' || name as name").map(&:name).map do |name| + canonicalize name + end end end end diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index b4826226..f0eff0dc 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -68,9 +68,7 @@ class SitesController < ApplicationController def enqueue authorize site - # XXX: Convertir en una máquina de estados? - site.enqueue! - DeployJob.perform_async site.id + SiteService.new(site: site).deploy redirect_to site_posts_path(site, locale: site.default_locale) end diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 8b1e1df0..aeb0f4b6 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -5,6 +5,8 @@ class DeployJob < ApplicationJob class DeployException < StandardError; end class DeployTimedOutException < DeployException; end + discard_on ActiveRecord::RecordNotFound + # rubocop:disable Metrics/MethodLength def perform(site, notify: true, time: Time.now, output: false) @output = output @@ -42,7 +44,8 @@ class DeployJob < ApplicationJob status = false seconds ||= 0 size ||= 0 - urls ||= [] + # XXX: Hace que se vea la tabla + urls ||= [nil] notify_exception e, d end diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 502d7116..1c80e51b 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -130,9 +130,17 @@ class DeployLocal < Deploy run 'yarn install --production', output: output end + def pnpm(output: output) + return true unless pnpm_lock? + + run %(pnpm config set store-dir "#{pnpm_cache_dir}"), output: output + run 'pnpm install --production', output: output + end + def bundle(output: false) # XXX: Desde que ya no compartimos el directorio de gemas, tenemos # que hacer limpieza después de instalar. + run %(bundle install --no-cache --path="#{gems_dir}" --clean --without test development), output: output end diff --git a/app/models/metadata_permalink.rb b/app/models/metadata_permalink.rb index 30ad32cc..895b7439 100644 --- a/app/models/metadata_permalink.rb +++ b/app/models/metadata_permalink.rb @@ -2,12 +2,6 @@ # Este metadato permite generar rutas manuales. class MetadataPermalink < MetadataString - # El valor por defecto una vez creado es la URL que le asigne Jekyll, - # de forma que nunca cambia aunque se cambie el título. - def default_value - document.url.sub(%r{\A/}, '') unless post.new? - end - # Los permalinks nunca pueden ser privados def private? false diff --git a/app/services/site_service.rb b/app/services/site_service.rb index c089c816..a93b2ba3 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -3,6 +3,11 @@ # Se encargar de guardar cambios en sitios # TODO: Implementar rollback en la configuración SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do + def deploy + site.enqueue! + DeployJob.perform_async site.id + end + # Crea un sitio, agrega un rol nuevo y guarda los cambios a la # configuración en el repositorio git def create @@ -28,6 +33,8 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do add_privacy_policy end + deploy + site end diff --git a/config/locales/en.yml b/config/locales/en.yml index c5e46313..84251203 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -118,7 +118,7 @@ en: success: Success! error: Error deploy_localized_domain: - title: Localized domain + title: Domain name by language success: Success! error: Error deploy_rsync: diff --git a/config/locales/es.yml b/config/locales/es.yml index 3e9707ad..ec081aa4 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -118,7 +118,7 @@ es: success: ¡Éxito! error: Hubo un error deploy_localized_domain: - title: Dominio por idioma + title: Dominio según idioma success: ¡Éxito! error: Hubo un error deploy_rsync: