This commit is contained in:
BoHung Chiu 2021-02-23 14:18:25 +08:00
parent f40b9bd3f3
commit a543d6be8f
3 changed files with 35 additions and 4 deletions

View File

@ -110,9 +110,15 @@ class Admin::SitePanelController < OrbitAdminController
db_name = site_construct.db_name db_name = site_construct.db_name
path = site_construct.path path = site_construct.path
site_construct_id = params[:id] site_construct_id = params[:id]
if site_construct.copy_id
Thread.new do
system("bundle exec rake create_site:copy_site['#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}','#{site_construct.copy_id}']")
end
else
Thread.new do Thread.new do
system("bundle exec rake create_site:create_site['#{git_template_url}','#{git_extension_url}','#{git_url}','#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}']") system("bundle exec rake create_site:create_site['#{git_template_url}','#{git_extension_url}','#{git_url}','#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}']")
end end
end
render :json =>{"success"=>true} render :json =>{"success"=>true}
end end
def edit_site def edit_site
@ -173,8 +179,6 @@ class Admin::SitePanelController < OrbitAdminController
def site_construct_params def site_construct_params
site_construct_params = params.require(:site_construct).permit! site_construct_params = params.require(:site_construct).permit!
site_construct_params = site_construct_params.except(:copy_id)
return site_construct_params
end end
def site_server_params def site_server_params
params.require(:site_server).permit! params.require(:site_server).permit!

View File

@ -20,6 +20,7 @@ class SiteConstruct
field :status, type: String, :default => "" field :status, type: String, :default => ""
field :infos, type: Array, :default => [] field :infos, type: Array, :default => []
field :hidden, type: Boolean, :default => false field :hidden, type: Boolean, :default => false
field :copy_id
after_initialize do |record| after_initialize do |record|
if record.status.nil? if record.status.nil?
record.status = "" record.status = ""

View File

@ -94,6 +94,32 @@ namespace :create_site do
end end
update_infos("Finish copying database!") update_infos("Finish copying database!")
update_infos("Checking extensions!")
extensions = ["downloaded_extensions.rb","built_in_extensions.rb"]
extensions.each do |extension_file|
outputs = exec_ssh_command_by_sudo_for_create(ssh,"cat #{args.path}/#{@site_construct.get_site_name}/#{extension_file}")
if !outputs.include?("No such file or directory")
read_lines = outputs.split("\n").map{|l| l.split('#').first}
include_path_lines = read_lines.select{|l| l.include?("path")}
include_path_lines.each do |line|
path = line.split(/[:>]/).last.gsub(/[\'\"]/,"").strip
absolute_path = (path[0] == "/") ? path : ("#{template_site.path}/#{template_site.get_site_name}/#{path}")
absolute_path = (absolute_path[-1] == "/") ? absolute_path : (absolute_path + "/")
if @site_construct.server_type == template_site.server_type
exec_ssh_command_for_create(ssh,"rsync -arv --delete #{absolute_path} #{args.path}/#{args.site_name}/#{Pathname.new(absolute_path).basename}/")
else
server = SiteServer.where(:server_name => template_site.server_type).first
exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete #{server.account}@#{server.ip}:#{absolute_path} #{args.path}/#{args.site_name}/#{Pathname.new(absolute_path).basename}/")
end
outputs = outputs.gsub(path,"#{args.path}/#{args.site_name}/#{Pathname.new(absolute_path).basename}/")
end
if include_path_lines.count != 0
exec_ssh_command_by_sudo_for_create(ssh,"sh -c \"echo '#{outputs.gsub("'","\\\"")}' > #{args.path}/#{@site_construct.get_site_name}/#{extension_file}\"")
end
end
end
update_infos("Finish checking extensions!")
update_infos("execing bundle install...") update_infos("execing bundle install...")
exec_ssh_command_by_sudo_for_create(ssh,"bash -l -c 'cd #{args.path}/#{@site_construct.get_site_name}\nbundle install'",true) exec_ssh_command_by_sudo_for_create(ssh,"bash -l -c 'cd #{args.path}/#{@site_construct.get_site_name}\nbundle install'",true)
exec_ssh_command_by_sudo_for_create(ssh,"bash -l -c 'cd #{args.path}/#{@site_construct.get_site_name}\nbundle install'") exec_ssh_command_by_sudo_for_create(ssh,"bash -l -c 'cd #{args.path}/#{@site_construct.get_site_name}\nbundle install'")