Redo deploy to work multistage on same host. Add ui and pingwinsoft stages, Refactor deploy. Refactor XML RPC stub. Apply nginx config generation script. Fix scripts. Cleanup code and config. Refs #2261
This commit is contained in:
parent
bcb9333b97
commit
04a17cb691
|
@ -4,12 +4,6 @@ class Download < ActiveRecord::Base
|
||||||
default_scope order(:name)
|
default_scope order(:name)
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
#def rotate_nginx_log
|
|
||||||
# system("sudo mv #{ APP_CONFIG['nginx_log'] } #{ PREV_LOG_FILE }")
|
|
||||||
# #system("sudo kill -USR1 `cat #{ APP_CONFIG['nginx_pid'] }`")
|
|
||||||
# system("sudo /opt/nginx/sbin/nginx -s reload")
|
|
||||||
#end
|
|
||||||
|
|
||||||
def parse_nginx_log
|
def parse_nginx_log
|
||||||
File.open(PREV_LOG_FILE) do |log|
|
File.open(PREV_LOG_FILE) do |log|
|
||||||
while (line = log.gets)
|
while (line = log.gets)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
mv /opt/nginx/logs/access.log /opt/nginx/logs/access.log.0
|
mv /srv/rosa_build/shared/log/nginx.access.log /srv/rosa_build/shared/log/nginx.access.log.0
|
||||||
/opt/nginx/sbin/nginx -s reload
|
/etc/init.d/nginx reload
|
||||||
chown rosa /opt/nginx/logs/access.log.0
|
chown rosa /srv/rosa_build/shared/log/nginx.access.log.0
|
||||||
touch /home/rosa/i_was_launched.txt
|
# touch /home/rosa/i_was_launched.txt
|
||||||
|
|
|
@ -1,66 +1,40 @@
|
||||||
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
|
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
|
||||||
|
set :rvm_type, :user
|
||||||
require 'rvm/capistrano'
|
require 'rvm/capistrano'
|
||||||
require 'bundler/capistrano'
|
require 'bundler/capistrano'
|
||||||
|
require 'delayed/recipes'
|
||||||
require 'airbrake/capistrano'
|
require 'airbrake/capistrano'
|
||||||
|
|
||||||
set :whenever_command, "bundle exec whenever"
|
set :whenever_command, "bundle exec whenever"
|
||||||
require "whenever/capistrano"
|
require "whenever/capistrano"
|
||||||
|
|
||||||
set :rvm_type, :user
|
|
||||||
|
|
||||||
set :default_stage, "staging"
|
set :default_stage, "staging"
|
||||||
set :stages, %w(production staging)
|
# set :stages, %w(production staging pingwinsoft ui) # auto readed
|
||||||
require 'capistrano/ext/multistage'
|
require 'capistrano/ext/multistage'
|
||||||
|
|
||||||
# bundler bootstrap
|
|
||||||
|
|
||||||
# main details
|
# main details
|
||||||
ssh_options[:forward_agent] = true
|
ssh_options[:forward_agent] = true
|
||||||
|
|
||||||
set :application, "rosa_build"
|
set :application, "rosa_build"
|
||||||
|
set :deploy_to, "/srv/#{application}"
|
||||||
|
set :user, "rosa"
|
||||||
|
set :use_sudo, false
|
||||||
|
set :keep_releases, 3
|
||||||
|
|
||||||
set :repository, "git@github.com:warpc/rosa-build.git"
|
set :repository, "git@github.com:warpc/rosa-build.git"
|
||||||
# set :git_shallow_clone, 1
|
# set :git_shallow_clone, 1
|
||||||
set :scm, "git"
|
set :scm, "git"
|
||||||
|
|
||||||
set :user, "rosa"
|
|
||||||
# set :sudo, "rvmsudo"
|
|
||||||
set :use_sudo, false
|
|
||||||
set :deploy_to, "/srv/#{application}"
|
|
||||||
# set :deploy_via, :copy
|
# set :deploy_via, :copy
|
||||||
# set :copy_cache, true
|
# set :copy_cache, true
|
||||||
|
|
||||||
set :keep_releases, 3
|
|
||||||
|
|
||||||
set :rails_env, :production
|
|
||||||
set :unicorn_binary, "bundle exec unicorn"
|
set :unicorn_binary, "bundle exec unicorn"
|
||||||
set :unicorn_config, "#{current_path}/config/unicorn.rb"
|
set :unicorn_config, "#{current_path}/config/unicorn.rb"
|
||||||
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
|
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
|
||||||
|
set :unicorn_port, 8080
|
||||||
|
|
||||||
task :symlink_config_files do
|
require 'lib/recipes/nginx'
|
||||||
run "mkdir -p #{deploy_to}/#{shared_dir}/config"
|
|
||||||
|
|
||||||
run "yes y | cp -i #{release_path}/config/database.yml.sample #{deploy_to}/#{shared_dir}/config/database.yml"
|
|
||||||
run "yes y | cp -i #{release_path}/config/application.yml.sample #{deploy_to}/#{shared_dir}/config/application.yml"
|
|
||||||
|
|
||||||
|
|
||||||
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
|
||||||
run "ln -nfs #{shared_path}/config/application.yml #{release_path}/config/application.yml"
|
|
||||||
end
|
|
||||||
|
|
||||||
task :symlink_downloads_dir do
|
|
||||||
run "ln -nfs #{shared_path}/downloads/ #{release_path}/public/downloads"
|
|
||||||
end
|
|
||||||
|
|
||||||
task :symlink_tmp_dir do
|
|
||||||
run "ln -nfs #{shared_path}/tmp/ #{release_path}/tmp"
|
|
||||||
run "mkdir -p #{release_path}/tmp/mount"
|
|
||||||
run "mkdir -p #{release_path}/tmp/umount"
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :deploy do
|
namespace :deploy do
|
||||||
task :start, :roles => :app, :except => { :no_release => true } do
|
task :start, :roles => :app, :except => { :no_release => true } do
|
||||||
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
|
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -p #{unicorn_port} -E #{rails_env} -D"
|
||||||
end
|
end
|
||||||
task :stop, :roles => :app, :except => { :no_release => true } do
|
task :stop, :roles => :app, :except => { :no_release => true } do
|
||||||
run "#{try_sudo} kill `cat #{unicorn_pid}`"
|
run "#{try_sudo} kill `cat #{unicorn_pid}`"
|
||||||
|
@ -74,22 +48,38 @@ namespace :deploy do
|
||||||
task :restart, :roles => :app, :except => { :no_release => true } do
|
task :restart, :roles => :app, :except => { :no_release => true } do
|
||||||
stop
|
stop
|
||||||
start
|
start
|
||||||
|
end
|
||||||
|
# task :restart, :roles => :app, :except => { :no_release => true } do
|
||||||
# run "touch #{current_release}/tmp/restart.txt"
|
# run "touch #{current_release}/tmp/restart.txt"
|
||||||
restart_dj
|
# end
|
||||||
|
|
||||||
|
task :stub_xml_rpc do
|
||||||
|
path = File.join(current_path, 'config', 'environment.rb')
|
||||||
|
code = %Q{\nrequire 'stub_xml_rpc'\n}
|
||||||
|
puts "Stub XML RPC"
|
||||||
|
run %Q{echo "#{code}" >> #{path}}
|
||||||
end
|
end
|
||||||
|
|
||||||
# %w(start).each { |name| task name, :roles => :app do deploy.restart end }
|
task :symlink_config_files, :roles => :web do
|
||||||
|
run "mkdir -p #{deploy_to}/#{shared_dir}/config"
|
||||||
|
|
||||||
desc "Restart delayed job"
|
run "yes y | cp -i #{release_path}/config/database.yml.sample #{deploy_to}/#{shared_dir}/config/database.yml"
|
||||||
task :restart_dj, :roles => :web do
|
run "yes y | cp -i #{release_path}/config/application.yml.sample #{deploy_to}/#{shared_dir}/config/application.yml"
|
||||||
run "cd #{deploy_to}/current ; RAILS_ENV=production ./script/delayed_job stop; RAILS_ENV=production ./script/delayed_job start; true"
|
|
||||||
|
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
||||||
|
run "ln -nfs #{shared_path}/config/application.yml #{release_path}/config/application.yml"
|
||||||
end
|
end
|
||||||
|
|
||||||
after "deploy:update_code", :roles => :web do
|
task :symlink_downloads_dir, :roles => :web do
|
||||||
symlink_config_files
|
run "ln -nfs #{shared_path}/downloads/ #{release_path}/public/downloads"
|
||||||
symlink_downloads_dir
|
end
|
||||||
symlink_tmp_dir
|
|
||||||
|
task :symlink_tmp_dir, :roles => :web do
|
||||||
|
run "ln -nfs #{shared_path}/tmp/ #{release_path}/tmp"
|
||||||
|
run "mkdir -p #{release_path}/tmp/mount"
|
||||||
|
run "mkdir -p #{release_path}/tmp/umount"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
after "deploy:update_code", "deploy:migrate"
|
after "deploy:update_code", "deploy:symlink_config_files", "deploy:symlink_downloads_dir", "deploy:symlink_tmp_dir", "deploy:migrate"
|
||||||
|
after "deploy:restart", "delayed_job:restart", "deploy:cleanup"
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
set :branch, "pingwinsoft"
|
||||||
|
|
||||||
|
set :domain, "b.pingwinsoft.ru" # "195.19.76.12"
|
||||||
|
set :port, 1822
|
||||||
|
|
||||||
|
role :app, domain
|
||||||
|
role :web, domain
|
||||||
|
role :db, domain, :primary => true
|
||||||
|
|
||||||
|
set :application, "rosa_build_#{stage}"
|
||||||
|
set :deploy_to, "/srv/#{application}"
|
||||||
|
|
||||||
|
set :unicorn_port, 8081
|
||||||
|
|
||||||
|
before "deploy:restart", "deploy:stub_xml_rpc"
|
|
@ -0,0 +1,15 @@
|
||||||
|
set :branch, "ui"
|
||||||
|
|
||||||
|
set :domain, "abf.warpc.ru" # "195.19.76.12"
|
||||||
|
set :port, 1822
|
||||||
|
|
||||||
|
role :app, domain
|
||||||
|
role :web, domain
|
||||||
|
role :db, domain, :primary => true
|
||||||
|
|
||||||
|
set :application, "rosa_build_#{stage}"
|
||||||
|
set :deploy_to, "/srv/#{application}"
|
||||||
|
|
||||||
|
set :unicorn_port, 8082
|
||||||
|
|
||||||
|
before "deploy:restart", "deploy:stub_xml_rpc"
|
|
@ -24,17 +24,4 @@ Rosa::Application.configure do
|
||||||
config.action_dispatch.best_standards_support = :builtin
|
config.action_dispatch.best_standards_support = :builtin
|
||||||
end
|
end
|
||||||
|
|
||||||
# Uncomment this to stub XML RPC calls
|
require 'stub_xml_rpc'
|
||||||
require 'xmlrpc/client'
|
|
||||||
module XMLRPC
|
|
||||||
class Client
|
|
||||||
def call(*args)
|
|
||||||
# raise args.inspect
|
|
||||||
case
|
|
||||||
when args.first == 'get_status'
|
|
||||||
{'client_count' => 1, 'count_new_task' => 2, 'count_build_task' => 3}
|
|
||||||
else; 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
|
@ -49,17 +49,4 @@ Rosa::Application.configure do
|
||||||
config.active_support.deprecation = :notify
|
config.active_support.deprecation = :notify
|
||||||
end
|
end
|
||||||
|
|
||||||
# Uncomment this to stub XML RPC calls
|
# require 'stub_xml_rpc'
|
||||||
# require 'xmlrpc/client'
|
|
||||||
# module XMLRPC
|
|
||||||
# class Client
|
|
||||||
# def call(*args)
|
|
||||||
# # raise args.inspect
|
|
||||||
# case
|
|
||||||
# when args.first == 'get_status'
|
|
||||||
# {'client_count' => 1, 'count_new_task' => 2, 'count_build_task' => 3}
|
|
||||||
# else; 0
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
|
@ -35,18 +35,4 @@ Rosa::Application.configure do
|
||||||
config.active_support.deprecation = :stderr
|
config.active_support.deprecation = :stderr
|
||||||
end
|
end
|
||||||
|
|
||||||
# Uncomment this to stub XML RPC calls
|
require 'stub_xml_rpc'
|
||||||
require 'xmlrpc/client'
|
|
||||||
module XMLRPC
|
|
||||||
class Client
|
|
||||||
def call(*args)
|
|
||||||
# raise args.inspect
|
|
||||||
case
|
|
||||||
when args.first == 'get_status'
|
|
||||||
raise Timeout::Error
|
|
||||||
else; 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
# Patch to use paperclip with nginx upload module
|
# Patch to use paperclip with nginx upload module
|
||||||
# module Paperclip
|
module Paperclip
|
||||||
# class Attachment
|
class Attachment
|
||||||
# class UploadedPath
|
class UploadedPath
|
||||||
# attr_reader :original_filename, :content_type, :size, :path
|
attr_reader :original_filename, :content_type, :size, :path
|
||||||
# def initialize(uploaded_file)
|
def initialize(uploaded_file)
|
||||||
# @original_filename = uploaded_file["name"].downcase
|
@original_filename = uploaded_file["name"].downcase
|
||||||
# @content_type = uploaded_file["content_type"].to_s.strip
|
@content_type = uploaded_file["content_type"].to_s.strip
|
||||||
# @file_size = uploaded_file["size"].to_i
|
@file_size = uploaded_file["size"].to_i
|
||||||
# @path = uploaded_file["path"]
|
@path = uploaded_file["path"]
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# # TODO remove failed files
|
# TODO remove failed files
|
||||||
#
|
|
||||||
# def to_tempfile; self; end
|
def to_tempfile; self; end
|
||||||
#
|
|
||||||
# def size; @file_size; end
|
def size; @file_size; end
|
||||||
#
|
|
||||||
# def close; end
|
def close; end
|
||||||
# def closed?; true; end
|
def closed?; true; end
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# def assign_with_upload(uploaded_file)
|
def assign_with_upload(uploaded_file)
|
||||||
# uploaded_file = UploadedPath.new(uploaded_file) if uploaded_file.is_a?(Hash)
|
uploaded_file = UploadedPath.new(uploaded_file) if uploaded_file.is_a?(Hash)
|
||||||
# assign_without_upload(uploaded_file)
|
assign_without_upload(uploaded_file)
|
||||||
# end
|
end
|
||||||
# alias_method_chain :assign, :upload
|
alias_method_chain :assign, :upload
|
||||||
# end
|
end
|
||||||
# end
|
end
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
Capistrano::Configuration.instance(:must_exist).load do
|
||||||
|
namespace :deploy do
|
||||||
|
namespace :nginx do
|
||||||
|
set :nginx_init_path, "/etc/init.d/nginx"
|
||||||
|
|
||||||
|
desc "Generate Nginx configuration"
|
||||||
|
task :generate_configuration, :roles => :web, :except => { :no_release => true } do
|
||||||
|
cur_path = File.join(deploy_to, current_dir)
|
||||||
|
nginx_config_path = "/etc/nginx/conf.d/#{application}.conf"
|
||||||
|
config = %Q{
|
||||||
|
upstream #{application}_backend {
|
||||||
|
server 127.0.0.1:#{unicorn_port};
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name #{domain};
|
||||||
|
root #{cur_path}/public;
|
||||||
|
|
||||||
|
location /downloads {
|
||||||
|
autoindex on;
|
||||||
|
}
|
||||||
|
|
||||||
|
try_files $uri/index.html $uri.html $uri @myapp;
|
||||||
|
|
||||||
|
location @myapp {
|
||||||
|
proxy_pass http://#{application}_backend;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $remote_addr;
|
||||||
|
proxy_read_timeout 300;
|
||||||
|
proxy_send_timeout 180;
|
||||||
|
proxy_redirect off;
|
||||||
|
}
|
||||||
|
|
||||||
|
access_log #{shared_path}/log/nginx.access.log;
|
||||||
|
error_log #{shared_path}/log/nginx.error.log;
|
||||||
|
|
||||||
|
error_page 500 502 503 504 /500.html;
|
||||||
|
location = /500.html {
|
||||||
|
root #{cur_path}/public;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# puts config
|
||||||
|
puts "Write nginx config to #{nginx_config_path}"
|
||||||
|
put config, '/tmp/nginx.conf'
|
||||||
|
sudo "mv /tmp/nginx.conf #{nginx_config_path}", :pty => true
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Start nginx web server"
|
||||||
|
task :start, :roles => :web, :except => { :no_release => true } do
|
||||||
|
sudo "#{fetch :nginx_init_path} start"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Stop nginx web server"
|
||||||
|
task :stop, :roles => :web, :except => { :no_release => true } do
|
||||||
|
sudo "#{fetch :nginx_init_path} stop"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Restart nginx web server"
|
||||||
|
task :restart, :roles => :web, :except => { :no_release => true } do
|
||||||
|
sudo "#{fetch :nginx_init_path} restart"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Resload nginx web server"
|
||||||
|
task :reload, :roles => :web, :except => { :no_release => true } do
|
||||||
|
sudo "#{fetch :nginx_init_path} reload"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,14 @@
|
||||||
|
require 'xmlrpc/client'
|
||||||
|
module XMLRPC
|
||||||
|
class Client
|
||||||
|
def call(*args)
|
||||||
|
# raise args.inspect
|
||||||
|
case
|
||||||
|
when args.first == 'get_status'
|
||||||
|
{'client_count' => 1, 'count_new_task' => 2, 'count_build_task' => 3}
|
||||||
|
# raise Timeout::Error
|
||||||
|
else; 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -25,7 +25,7 @@ describe BuildListsController do
|
||||||
|
|
||||||
it "should be able to perform all action without exception" do
|
it "should be able to perform all action without exception" do
|
||||||
get :all
|
get :all
|
||||||
assigns[:build_server_status].should == {}
|
assigns[:build_server_status].should == {} # TODO stub to isolate
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue