Commit 730be631 by ifool

Setup project

parents
{
"deploy_to": "/dyne/apps/vcooline_ikcrm_production",
"log_path": "/dyne/apps/vcooline_ikcrm_production/shared/log",
"http_port": 8080,
"servers": [
{ "server": "101.37.17.163", "user": "ikcrm_dev", "roles": ["web", "app"] },
{ "server": "101.37.84.86", "user": "ikcrm_dev", "roles": ["web", "app"] },
{ "server": "101.37.91.52", "user": "ikcrm_dev", "roles": ["web", "app"] },
{ "server": "101.37.91.83", "user": "ikcrm_dev", "roles": ["web", "app"] },
{ "server": "116.62.7.124", "user": "ikcrm_dev", "roles": ["db", "whenever", "sidekiq_god"] },
{ "server": "114.55.238.119", "user": "ikcrm_dev", "roles": ["web", "app", "slave_app"] }
]
}
<%
app_server = server_conf['servers'].find { |h| h['roles'].include?('app') }
server_host, server_port = app_server['server'].split(':')
server_port ||= server_conf['port'] || server_conf['ssh_port'] || 22
%>
shell_file_path=$(cd `dirname $0`; pwd)
echo "config file root: $shell_file_path"
rsync -avz -e 'ssh -p <%= server_port %>' --exclude=public <%= app_server['user'] %>@<%= server_host %>:<%= server_conf['deploy_to'] %>/shared/config/ $shell_file_path/app
<%
ROLE_ALIASES = {
'sidekiq_god' => 'sidekiq'
}
config_dir = "#{server_conf['deploy_to']}/shared/config"
def split_server(server_json)
server_host, server_port = server_json['server'].split(':')
server_port ||= server_json['port'] || server_json['ssh_port'] || 22
[server_host, server_port, server_json['user']]
end
%>
shell_file_path=$(cd `dirname $0`; pwd)
echo "config file root: $shell_file_path"
<% server_conf['servers'].each do |server_json| %>
<% server_host, server_port, ssh_user = split_server(server_json) %>
<%= "rsync -avz -e 'ssh -p #{server_port}' $shell_file_path/app/ #{ssh_user}@#{server_host}:#{config_dir}" %>
<% server_json['roles'].map { |role| ROLE_ALIASES[role] || role }.
select { |role| role != "app" && Dir.exists?("#{config_root}/#{role}") }.
each do |role| %>
<%= "rsync -avz -e 'ssh -p #{server_port}' $shell_file_path/#{role}/ #{ssh_user}@#{server_host}:#{config_dir}" %>
<% end %>
<% end %>
\ No newline at end of file
require 'erb'
require 'json'
def download_server_json
product_name = ARGV[0]
config_root = File.expand_path('..', __FILE__)
git_branch = `git rev-parse --abbrev-ref HEAD`.chop
dir_basename = File.basename config_root
server_conf_url = "http://gitlab.ikcrm.com/ikcrm_common/servers_config/raw/master/#{product_name}/#{git_branch}_#{dir_basename}/server.json"
puts "Use server config url: #{server_conf_url}"
system "curl #{server_conf_url} > #{config_root}/server.json"
end
def deploy_binding
config_root = File.expand_path('..', __FILE__)
server_conf = JSON(File.read("#{__dir__}/server.json"))
binding
end
def generate_push_config
template = ERB.new File.read("#{__dir__}/push_config.sh.erb"), nil, '>'
script_content = template.result(deploy_binding)
puts "\n\n\n******************* push_config content *******************\n\n\n"
puts script_content
File.open("#{__dir__}/push_config.sh", "w") { |f| f.write(script_content) }
end
def generate_pull_config
template = ERB.new File.read("#{__dir__}/pull_config.sh.erb"), nil, '>'
script_content = template.result(deploy_binding)
puts "\n\n\n******************* pull_config content *******************\n\n\n"
puts script_content
File.open("#{__dir__}/pull_config.sh", "w") { |f| f.write(script_content) }
end
download_server_json
generate_push_config
generate_pull_config
#!/usr/bin/env ruby
product_name = ARGV[0] # crm, jxc, bms
dir_name = ARGV[1] # dev, test, staging, prod
if dir_name.nil?
raise "Dir name is required!"
elsif !Dir.exists?(dir_name)
raise "Dir: #{dir_name} not exists!"
end
git_config_url = "http://gitlab.ikcrm.com/ikcrm_common/servers_config/raw/master"
config_root = File.expand_path("../#{dir_name}", __FILE__)
setup_url = "#{git_config_url}/setup.rb"
puts "Use setup url: #{setup_url}"
system "curl #{setup_url} > #{config_root}/setup.rb"
push_script_url = "#{git_config_url}/push_config.sh.erb"
puts "Use push script url: #{push_script_url}"
system "curl #{push_script_url} > #{config_root}/push_config.sh.erb"
pull_script_url = "#{git_config_url}/pull_config.sh.erb"
puts "Use pull script url: #{pull_script_url}"
system "curl #{pull_script_url} > #{config_root}/pull_config.sh.erb"
require "#{config_root}/setup.rb"
# Usage example:
# `ruby setup_script.rb crm prod` OR ./setup_script.rb crm prod
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment