wblog/config/deploy.rb

95 lines
2.9 KiB
Ruby
Raw Permalink Normal View History

set :stages, %w(en zh)
set :default_stage, 'zh'
2014-04-01 22:54:58 +08:00
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
2018-01-21 02:01:09 +08:00
require 'mina/rbenv'
2016-04-24 15:22:24 +08:00
require 'mina/puma'
2017-05-01 13:37:07 +08:00
require "mina_sidekiq/tasks"
2016-05-15 18:12:20 +08:00
require 'mina/logs'
2017-05-13 09:59:29 +08:00
require 'mina/multistage'
2014-04-01 22:54:58 +08:00
2019-04-22 18:06:29 +08:00
set :shared_dirs, fetch(:shared_dirs, []).push('log', 'public/uploads', 'node_modules', 'storage', 'public/personal')
2017-05-01 13:37:07 +08:00
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/application.yml')
2019-04-22 18:06:29 +08:00
set :puma_config, ->{ "#{fetch(:current_path)}/config/puma.rb" }
2017-05-01 13:37:07 +08:00
set :sidekiq_pid, ->{ "#{fetch(:shared_path)}/tmp/pids/sidekiq.pid" }
2016-04-24 15:22:24 +08:00
2018-01-21 02:01:09 +08:00
task :remote_environment do
invoke :'rbenv:load'
2014-04-01 22:54:58 +08:00
end
2018-01-21 02:01:09 +08:00
task :setup do
2017-05-01 13:37:07 +08:00
command %[mkdir -p "#{fetch(:shared_path)}/tmp/sockets"]
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/tmp/sockets"]
2014-04-01 22:54:58 +08:00
2017-05-01 13:37:07 +08:00
command %[mkdir -p "#{fetch(:shared_path)}/tmp/pids"]
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/tmp/pids"]
command %[mkdir -p "#{fetch(:shared_path)}/log"]
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/log"]
command %[mkdir -p "#{fetch(:shared_path)}/public/uploads"]
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/public/uploads"]
2014-04-03 10:34:25 +08:00
2018-01-21 02:01:09 +08:00
command %[mkdir -p "#{fetch(:shared_path)}/node_modules"]
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/node_modules"]
2019-04-22 18:06:29 +08:00
command %[mkdir -p "#{fetch(:shared_path)}/storage"]
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/storage"]
2017-05-01 13:37:07 +08:00
command %[mkdir -p "#{fetch(:shared_path)}/config"]
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/config"]
command %[touch "#{fetch(:shared_path)}/config/application.yml"]
command %[echo "-----> Be sure to edit '#{fetch(:shared_path)}/config/application.yml'"]
command %[touch "#{fetch(:shared_path)}/config/database.yml"]
command %[echo "-----> Be sure to edit '#{fetch(:shared_path)}/config/database.yml'"]
2014-04-01 22:54:58 +08:00
end
desc "Deploys the current version to the server."
2018-01-21 02:01:09 +08:00
task :deploy do
2017-05-01 13:37:07 +08:00
command %[echo "-----> Server: #{fetch(:domain)}"]
command %[echo "-----> Path: #{fetch(:deploy_to)}"]
command %[echo "-----> Branch: #{fetch(:branch)}"]
2014-04-01 22:54:58 +08:00
deploy do
2017-05-01 13:37:07 +08:00
invoke :'sidekiq:quiet'
2014-04-01 22:54:58 +08:00
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
2017-05-01 13:37:07 +08:00
invoke :'deploy:cleanup'
2014-04-01 22:54:58 +08:00
2017-05-01 13:37:07 +08:00
on :launch do
2018-01-21 02:01:09 +08:00
invoke :'rbenv:load'
2019-04-22 18:06:29 +08:00
invoke :'puma:phased_restart'
2015-04-12 00:59:38 +08:00
invoke :'sidekiq:restart'
2014-04-01 22:54:58 +08:00
end
2017-05-01 13:37:07 +08:00
end
end
2018-01-21 02:01:09 +08:00
desc "Prepare the first deploy on server."
task :first_deploy do
2017-05-01 13:37:07 +08:00
command %[echo "-----> Server: #{fetch(:domain)}"]
command %[echo "-----> Path: #{fetch(:deploy_to)}"]
command %[echo "-----> Branch: #{fetch(:branch)}"]
2016-04-24 15:58:24 +08:00
2017-05-01 13:37:07 +08:00
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
2018-01-21 02:01:09 +08:00
invoke :'rails:assets_precompile'
2016-04-24 15:58:24 +08:00
invoke :'deploy:cleanup'
2017-05-01 13:37:07 +08:00
on :launch do
2018-01-21 02:01:09 +08:00
invoke :'rbenv:load'
2017-05-01 13:37:07 +08:00
invoke :'rails:db_create'
2018-01-21 02:01:09 +08:00
invoke :'rails:db_migrate'
2017-05-01 13:37:07 +08:00
end
2014-04-01 22:54:58 +08:00
end
end