mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 21:46:22 +00:00
Merge branch 'deadlock' into 'rails'
Deadlock See merge request sutty/sutty!81
This commit is contained in:
commit
4cc93313f4
11 changed files with 42 additions and 34 deletions
|
@ -6,7 +6,9 @@ class DeployJob < ApplicationJob
|
|||
class DeployTimedOutException < DeployException; end
|
||||
|
||||
# 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
|
||||
@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"
|
||||
end
|
||||
|
||||
DeployJob.perform_in(60, site, notify, time)
|
||||
DeployJob.perform_in(60, site, notify: notify, time: time, output: output)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -75,13 +77,13 @@ class DeployJob < ApplicationJob
|
|||
end
|
||||
|
||||
def deploy_locally
|
||||
deploy_local.deploy
|
||||
deploy_local.deploy(output: @output)
|
||||
end
|
||||
|
||||
def deploy_others
|
||||
@site.deploys.where.not(type: 'DeployLocal').find_each do |d|
|
||||
begin
|
||||
status = d.deploy
|
||||
status = d.deploy(output: @output)
|
||||
seconds = d.build_stats.last.try(:seconds)
|
||||
rescue StandardError => e
|
||||
status = false
|
||||
|
|
|
@ -11,7 +11,7 @@ class Deploy < ApplicationRecord
|
|||
belongs_to :site
|
||||
has_many :build_stats, dependent: :destroy
|
||||
|
||||
def deploy
|
||||
def deploy(**)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
|
@ -55,20 +55,26 @@ class Deploy < ApplicationRecord
|
|||
#
|
||||
# @param [String]
|
||||
# @return [Boolean]
|
||||
def run(cmd)
|
||||
def run(cmd, output: false)
|
||||
r = nil
|
||||
lines = []
|
||||
|
||||
time_start
|
||||
Dir.chdir(site.path) do
|
||||
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?
|
||||
o.each do |line|
|
||||
lines << line
|
||||
Thread.new do
|
||||
o.each do |line|
|
||||
lines << line
|
||||
|
||||
puts line if output
|
||||
end
|
||||
rescue IOError => e
|
||||
lines << e.message
|
||||
puts e.message if output
|
||||
end
|
||||
|
||||
r = t.value
|
||||
end
|
||||
end
|
||||
time_stop
|
||||
|
|
|
@ -5,7 +5,7 @@ class DeployAlternativeDomain < Deploy
|
|||
store :values, accessors: %i[hostname], coder: JSON
|
||||
|
||||
# Generar un link simbólico del sitio principal al alternativo
|
||||
def deploy
|
||||
def deploy(**)
|
||||
File.symlink?(destination) ||
|
||||
File.symlink(site.hostname, destination).zero?
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Genera una versión onion
|
||||
class DeployHiddenService < DeployWww
|
||||
def deploy
|
||||
def deploy(**)
|
||||
return true if fqdn.blank?
|
||||
|
||||
super
|
||||
|
|
|
@ -12,12 +12,12 @@ class DeployLocal < Deploy
|
|||
#
|
||||
# Pasamos variables de entorno mínimas para no filtrar secretos de
|
||||
# Sutty
|
||||
def deploy
|
||||
def deploy(output: false)
|
||||
return false unless mkdir
|
||||
return false unless yarn
|
||||
return false unless bundle
|
||||
return false unless yarn(output: output)
|
||||
return false unless bundle(output: output)
|
||||
|
||||
jekyll_build
|
||||
jekyll_build(output: output)
|
||||
end
|
||||
|
||||
# Sólo permitimos un deploy local
|
||||
|
@ -96,23 +96,23 @@ class DeployLocal < Deploy
|
|||
File.exist? yarn_lock
|
||||
end
|
||||
|
||||
def gem
|
||||
run %(gem install bundler --no-document)
|
||||
def gem(output: false)
|
||||
run %(gem install bundler --no-document), output: output
|
||||
end
|
||||
|
||||
# Corre yarn dentro del repositorio
|
||||
def yarn
|
||||
def yarn(output: false)
|
||||
return true unless yarn_lock?
|
||||
|
||||
run 'yarn install --production'
|
||||
run 'yarn install --production', output: output
|
||||
end
|
||||
|
||||
def bundle
|
||||
def bundle(output: false)
|
||||
run %(bundle install --no-cache --path="#{gems_dir}")
|
||||
end
|
||||
|
||||
def jekyll_build
|
||||
run %(bundle exec jekyll build --trace --profile --destination "#{escaped_destination}")
|
||||
def jekyll_build(output: false)
|
||||
run %(bundle exec jekyll build --trace --profile --destination "#{escaped_destination}"), output: output
|
||||
end
|
||||
|
||||
# no debería haber espacios ni caracteres especiales, pero por si
|
||||
|
|
|
@ -5,7 +5,7 @@ class DeployLocalizedDomain < DeployAlternativeDomain
|
|||
store :values, accessors: %i[hostname locale], coder: JSON
|
||||
|
||||
# Generar un link simbólico del sitio principal al alternativo
|
||||
def deploy
|
||||
def deploy(**)
|
||||
File.symlink?(destination) ||
|
||||
File.symlink(File.join(site.hostname, locale), destination).zero?
|
||||
end
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
# jekyll-private-data
|
||||
class DeployPrivate < DeployLocal
|
||||
# No es necesario volver a instalar dependencias
|
||||
def deploy
|
||||
jekyll_build
|
||||
def deploy(output: false)
|
||||
jekyll_build(output: output)
|
||||
end
|
||||
|
||||
# Hacer el deploy a un directorio privado
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Reindexa los artículos al terminar la compilación
|
||||
class DeployReindex < Deploy
|
||||
def deploy
|
||||
def deploy(**)
|
||||
time_start
|
||||
|
||||
site.reset
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
class DeployRsync < Deploy
|
||||
store :values, accessors: %i[destination host_keys], coder: JSON
|
||||
|
||||
def deploy
|
||||
ssh? && rsync
|
||||
def deploy(output: false)
|
||||
ssh? && rsync(output: output)
|
||||
end
|
||||
|
||||
# El espacio remoto es el mismo que el local
|
||||
|
@ -83,8 +83,8 @@ class DeployRsync < Deploy
|
|||
# Sincroniza hacia el directorio remoto
|
||||
#
|
||||
# @return [Boolean]
|
||||
def rsync
|
||||
run %(rsync -aviH --timeout=5 #{Shellwords.escape source}/ #{Shellwords.escape destination}/)
|
||||
def rsync(output: output)
|
||||
run %(rsync -aviH --timeout=5 #{Shellwords.escape source}/ #{Shellwords.escape destination}/), output: output
|
||||
end
|
||||
|
||||
# El origen es el destino de la compilación
|
||||
|
|
|
@ -6,7 +6,7 @@ class DeployWww < Deploy
|
|||
|
||||
before_destroy :remove_destination!
|
||||
|
||||
def deploy
|
||||
def deploy(**)
|
||||
File.symlink?(destination) ||
|
||||
File.symlink(site.hostname, destination).zero?
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ class DeployZip < Deploy
|
|||
# y generar un zip accesible públicamente.
|
||||
#
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def deploy
|
||||
def deploy(**)
|
||||
FileUtils.rm_f path
|
||||
|
||||
time_start
|
||||
|
|
Loading…
Reference in a new issue