5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 23:36:21 +00:00

Merge branch 'deadlock' into 'rails'

Deadlock

See merge request sutty/sutty!81
This commit is contained in:
fauno 2023-03-23 22:12:18 +00:00
commit 4cc93313f4
11 changed files with 42 additions and 34 deletions

View file

@ -6,7 +6,9 @@ class DeployJob < ApplicationJob
class DeployTimedOutException < DeployException; end class DeployTimedOutException < DeployException; end
# rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
def perform(site, notify = true, time = Time.now) def perform(site, notify: true, time: Time.now, output: false)
@output = output
ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.connection_pool.with_connection do
@site = Site.find(site) @site = Site.find(site)
@ -22,7 +24,7 @@ class DeployJob < ApplicationJob
"#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" "#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original"
end end
DeployJob.perform_in(60, site, notify, time) DeployJob.perform_in(60, site, notify: notify, time: time, output: output)
return return
end end
@ -75,13 +77,13 @@ class DeployJob < ApplicationJob
end end
def deploy_locally def deploy_locally
deploy_local.deploy deploy_local.deploy(output: @output)
end end
def deploy_others def deploy_others
@site.deploys.where.not(type: 'DeployLocal').find_each do |d| @site.deploys.where.not(type: 'DeployLocal').find_each do |d|
begin begin
status = d.deploy status = d.deploy(output: @output)
seconds = d.build_stats.last.try(:seconds) seconds = d.build_stats.last.try(:seconds)
rescue StandardError => e rescue StandardError => e
status = false status = false

View file

@ -11,7 +11,7 @@ class Deploy < ApplicationRecord
belongs_to :site belongs_to :site
has_many :build_stats, dependent: :destroy has_many :build_stats, dependent: :destroy
def deploy def deploy(**)
raise NotImplementedError raise NotImplementedError
end end
@ -55,20 +55,26 @@ class Deploy < ApplicationRecord
# #
# @param [String] # @param [String]
# @return [Boolean] # @return [Boolean]
def run(cmd) def run(cmd, output: false)
r = nil r = nil
lines = [] lines = []
time_start time_start
Dir.chdir(site.path) do Dir.chdir(site.path) do
Open3.popen2e(env, cmd, unsetenv_others: true) do |_, o, t| Open3.popen2e(env, cmd, unsetenv_others: true) do |_, o, t|
r = t.value
# XXX: Tenemos que leer línea por línea porque en salidas largas
# se cuelga la IO
# TODO: Enviar a un websocket para ver el proceso en vivo? # TODO: Enviar a un websocket para ver el proceso en vivo?
o.each do |line| Thread.new do
lines << line o.each do |line|
lines << line
puts line if output
end
rescue IOError => e
lines << e.message
puts e.message if output
end end
r = t.value
end end
end end
time_stop time_stop

View file

@ -5,7 +5,7 @@ class DeployAlternativeDomain < Deploy
store :values, accessors: %i[hostname], coder: JSON store :values, accessors: %i[hostname], coder: JSON
# Generar un link simbólico del sitio principal al alternativo # Generar un link simbólico del sitio principal al alternativo
def deploy def deploy(**)
File.symlink?(destination) || File.symlink?(destination) ||
File.symlink(site.hostname, destination).zero? File.symlink(site.hostname, destination).zero?
end end

View file

@ -2,7 +2,7 @@
# Genera una versión onion # Genera una versión onion
class DeployHiddenService < DeployWww class DeployHiddenService < DeployWww
def deploy def deploy(**)
return true if fqdn.blank? return true if fqdn.blank?
super super

View file

@ -12,12 +12,12 @@ class DeployLocal < Deploy
# #
# Pasamos variables de entorno mínimas para no filtrar secretos de # Pasamos variables de entorno mínimas para no filtrar secretos de
# Sutty # Sutty
def deploy def deploy(output: false)
return false unless mkdir return false unless mkdir
return false unless yarn return false unless yarn(output: output)
return false unless bundle return false unless bundle(output: output)
jekyll_build jekyll_build(output: output)
end end
# Sólo permitimos un deploy local # Sólo permitimos un deploy local
@ -96,23 +96,23 @@ class DeployLocal < Deploy
File.exist? yarn_lock File.exist? yarn_lock
end end
def gem def gem(output: false)
run %(gem install bundler --no-document) run %(gem install bundler --no-document), output: output
end end
# Corre yarn dentro del repositorio # Corre yarn dentro del repositorio
def yarn def yarn(output: false)
return true unless yarn_lock? return true unless yarn_lock?
run 'yarn install --production' run 'yarn install --production', output: output
end end
def bundle def bundle(output: false)
run %(bundle install --no-cache --path="#{gems_dir}") run %(bundle install --no-cache --path="#{gems_dir}")
end end
def jekyll_build def jekyll_build(output: false)
run %(bundle exec jekyll build --trace --profile --destination "#{escaped_destination}") run %(bundle exec jekyll build --trace --profile --destination "#{escaped_destination}"), output: output
end end
# no debería haber espacios ni caracteres especiales, pero por si # no debería haber espacios ni caracteres especiales, pero por si

View file

@ -5,7 +5,7 @@ class DeployLocalizedDomain < DeployAlternativeDomain
store :values, accessors: %i[hostname locale], coder: JSON store :values, accessors: %i[hostname locale], coder: JSON
# Generar un link simbólico del sitio principal al alternativo # Generar un link simbólico del sitio principal al alternativo
def deploy def deploy(**)
File.symlink?(destination) || File.symlink?(destination) ||
File.symlink(File.join(site.hostname, locale), destination).zero? File.symlink(File.join(site.hostname, locale), destination).zero?
end end

View file

@ -7,8 +7,8 @@
# jekyll-private-data # jekyll-private-data
class DeployPrivate < DeployLocal class DeployPrivate < DeployLocal
# No es necesario volver a instalar dependencias # No es necesario volver a instalar dependencias
def deploy def deploy(output: false)
jekyll_build jekyll_build(output: output)
end end
# Hacer el deploy a un directorio privado # Hacer el deploy a un directorio privado

View file

@ -2,7 +2,7 @@
# Reindexa los artículos al terminar la compilación # Reindexa los artículos al terminar la compilación
class DeployReindex < Deploy class DeployReindex < Deploy
def deploy def deploy(**)
time_start time_start
site.reset site.reset

View file

@ -5,8 +5,8 @@
class DeployRsync < Deploy class DeployRsync < Deploy
store :values, accessors: %i[destination host_keys], coder: JSON store :values, accessors: %i[destination host_keys], coder: JSON
def deploy def deploy(output: false)
ssh? && rsync ssh? && rsync(output: output)
end end
# El espacio remoto es el mismo que el local # El espacio remoto es el mismo que el local
@ -83,8 +83,8 @@ class DeployRsync < Deploy
# Sincroniza hacia el directorio remoto # Sincroniza hacia el directorio remoto
# #
# @return [Boolean] # @return [Boolean]
def rsync def rsync(output: output)
run %(rsync -aviH --timeout=5 #{Shellwords.escape source}/ #{Shellwords.escape destination}/) run %(rsync -aviH --timeout=5 #{Shellwords.escape source}/ #{Shellwords.escape destination}/), output: output
end end
# El origen es el destino de la compilación # El origen es el destino de la compilación

View file

@ -6,7 +6,7 @@ class DeployWww < Deploy
before_destroy :remove_destination! before_destroy :remove_destination!
def deploy def deploy(**)
File.symlink?(destination) || File.symlink?(destination) ||
File.symlink(site.hostname, destination).zero? File.symlink(site.hostname, destination).zero?
end end

View file

@ -12,7 +12,7 @@ class DeployZip < Deploy
# y generar un zip accesible públicamente. # y generar un zip accesible públicamente.
# #
# rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
def deploy def deploy(**)
FileUtils.rm_f path FileUtils.rm_f path
time_start time_start