5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 13:51:41 +00:00

feat: separar rsync de full rsync

los segundos se usan para sincronizar todas las versiones de un sitio
con otro servidor de sutty.  los primeros solo sincronizan los archivos
a otro servidor, no necesariamente bajo el mismo nombre.
This commit is contained in:
f 2023-03-18 15:50:05 -03:00
parent 5974a40d02
commit ba91ed56aa
5 changed files with 67 additions and 9 deletions

View file

@ -20,7 +20,11 @@ class DeployAlternativeDomain < Deploy
end
def destination
@destination ||= File.join(Rails.root, '_deploy', hostname.gsub(/\.\z/, ''))
@destination ||= File.join(Rails.root, '_deploy', fqdn)
end
def fqdn
hostname.gsub(/\.\z/, '')
end
def url

View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
class DeployFullRsync < DeployRsync
DEPENDENCIES = %i[
deploy_alternative_domain
deploy_hidden_service
deploy_local
deploy_www
]
# Sincroniza las ubicaciones alternativas también
#
# @param :output [Boolean]
# @return [Boolean]
def rsync(output: false)
DEPENDENCIES.map(&:to_s).map(&:classify).map do |dependency|
site.deploys.where(type: dependency).find_each.map do |deploy|
run %(rsync -aviH --delete-after --timeout=5 #{Shellwords.escape deploy.destination} #{Shellwords.escape destination}), output: output
end
end.flatten.all?
end
end

View file

@ -5,12 +5,7 @@
class DeployRsync < Deploy
store :values, accessors: %i[destination host_keys], coder: JSON
DEPENDENCIES = %i[
deploy_alternative_domain
deploy_hidden_service
deploy_local
deploy_www
]
DEPENDENCIES = %i[deploy_local]
def deploy(output: false)
ssh? && rsync(output: output)
@ -90,7 +85,7 @@ class DeployRsync < Deploy
# Sincroniza hacia el directorio remoto
#
# @return [Boolean]
def rsync(output: output)
def rsync(output: false)
run %(rsync -aviH --delete-after --timeout=5 #{Shellwords.escape source}/ #{Shellwords.escape destination}/), output: output
end

View file

@ -163,7 +163,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
# Crea los deploys necesarios para sincronizar a otros nodos de Sutty
def sync_nodes
Rails.application.nodes.each do |node|
site.deploys.build(type: 'DeployRsync', destination: "sutty@#{node}:#{site.hostname}")
site.deploys.build(type: 'DeployFullRsync', destination: "sutty@#{node}:")
end
end
end

View file

@ -0,0 +1,37 @@
# frozen_string_literal: true
# Cambia todos los DeployRsync propios de Sutty a DeployFullRsync que se
# encarga de sincronizar todo.
class RenameDeployRsyncToDeployFullRsync < ActiveRecord::Migration[6.1]
def up
DeployRsync.all.find_each do |deploy|
dest = deploy.destination.split(':', 2).first
next unless nodes.include? dest
deploy.destination = "#{dest}:"
deploy.type = 'DeployFullRsync'
deploy.save
end
end
def down
DeployFullRsync.all.find_each do |deploy|
next unless nodes.include? deploy.destination.split(':', 2).first
deploy.destination = "#{deploy.destination}#{deploy.site.hostname}"
deploy.type = 'DeployRsync'
deploy.save
end
end
private
def nodes
@nodes ||= Rails.application.nodes.map do |node|
"sutty@#{node}"
end
end
end