Configure mina for new infra
This commit is contained in:
parent
3c9182d41d
commit
bffeeaf954
2 changed files with 76 additions and 77 deletions
128
config/deploy.rb
128
config/deploy.rb
|
@ -13,91 +13,54 @@ require 'mina/rbenv'
|
||||||
# forward_agent - SSH forward_agent
|
# forward_agent - SSH forward_agent
|
||||||
# user - Username in the server to SSH to
|
# user - Username in the server to SSH to
|
||||||
|
|
||||||
if !["staging", "production"].include?(ENV['to'])
|
|
||||||
raise "missing or incorrect `to` (should be 'staging' or 'production')"
|
|
||||||
end
|
|
||||||
|
|
||||||
if ENV['domain'].nil?
|
if ENV['domain'].nil?
|
||||||
raise "missing `domain`"
|
raise "missing `domain`"
|
||||||
end
|
end
|
||||||
|
|
||||||
set :domain, ENV['domain']
|
set :domain, ENV['domain']
|
||||||
|
|
||||||
set :repository, 'https://github.com/betagouv/tps.git'
|
set :repository, 'https://github.com/betagouv/tps.git'
|
||||||
set :port, 2200
|
deploy_to = '/var/www/ds'
|
||||||
set :rails_env, 'production'
|
set :deploy_to, deploy_to
|
||||||
set :rbenv_path, "/usr/local/rbenv/bin/rbenv"
|
set :user, 'ds'
|
||||||
set :forward_agent, true
|
branch = 'puma'
|
||||||
|
set :branch, branch
|
||||||
|
|
||||||
|
print "Deploy to #{ENV['domain']}, branch : #{branch}\n"
|
||||||
|
|
||||||
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
|
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
|
||||||
# They will be linked in the 'deploy:link_shared_paths' step.
|
# They will be linked in the 'deploy:link_shared_paths' step.
|
||||||
set :shared_paths, [
|
set :shared_dirs, [
|
||||||
'.env',
|
|
||||||
'log',
|
'log',
|
||||||
'uploads',
|
'sockets',
|
||||||
'tmp/pids',
|
'tmp/pids',
|
||||||
'tmp/cache',
|
'tmp/cache'
|
||||||
'tmp/sockets',
|
|
||||||
'public/system',
|
|
||||||
'public/uploads',
|
|
||||||
'config/unicorn.rb'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
case ENV["to"]
|
set :rbenv_path, "/home/ds/.rbenv/bin/rbenv"
|
||||||
when "staging"
|
|
||||||
set :branch, ENV['branch'] || 'dev'
|
|
||||||
set :deploy_to, '/var/www/tps_dev'
|
|
||||||
set :user, 'tps_dev'
|
|
||||||
appname = 'tps_dev'
|
|
||||||
when "production"
|
|
||||||
set :branch, ENV['branch'] || 'master'
|
|
||||||
set :deploy_to, '/var/www/tps'
|
|
||||||
set :user, 'tps'
|
|
||||||
appname = 'tps'
|
|
||||||
end
|
|
||||||
|
|
||||||
print "Deploy to #{ENV['to']} environment branch #{branch}\n"
|
set :forward_agent, true # SSH forward_agent.
|
||||||
|
#
|
||||||
|
# # This task is the environment that is loaded for most commands, such as
|
||||||
|
# # `mina deploy` or `mina rake`.
|
||||||
|
task :setup do
|
||||||
|
command %[mkdir -p "#{deploy_to}/shared/log"]
|
||||||
|
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
|
||||||
|
|
||||||
# This task is the environment that is loaded for most commands, such as
|
command %[mkdir -p "#{deploy_to}/shared/tmp/pids"]
|
||||||
# `mina deploy` or `mina rake`.
|
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]
|
||||||
task :setup => :environment do
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/log"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
|
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/bin"]
|
command %[mkdir -p "#{deploy_to}/shared/tmp/cache"]
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/bin"]
|
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/cache"]
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/tmp/pids"]
|
command %[mkdir -p "#{deploy_to}/shared/sockets"]
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]
|
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/sockets"]
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/tmp/cache"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/cache"]
|
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/tmp/sockets"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/sockets"]
|
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/public/system"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/public/system"]
|
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/public/uploads"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/public/uploads"]
|
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/config"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
|
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/app"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/app"]
|
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/views/layouts"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/views/layouts"]
|
|
||||||
|
|
||||||
queue! %[mkdir -p "#{deploy_to}/shared/config/locales/dynamics"]
|
|
||||||
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config/locales/dynamics"]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :yarn do
|
namespace :yarn do
|
||||||
desc "Install package dependencies using yarn."
|
desc "Install package dependencies using yarn."
|
||||||
task :install do
|
task :install do
|
||||||
queue %{
|
command %{
|
||||||
echo "-----> Installing package dependencies using yarn"
|
echo "-----> Installing package dependencies using yarn"
|
||||||
#{echo_cmd %[yarn install --non-interactive]}
|
#{echo_cmd %[yarn install --non-interactive]}
|
||||||
}
|
}
|
||||||
|
@ -107,18 +70,36 @@ end
|
||||||
namespace :after_party do
|
namespace :after_party do
|
||||||
desc "Run after_party tasks."
|
desc "Run after_party tasks."
|
||||||
task :run do
|
task :run do
|
||||||
queue %{
|
command %{
|
||||||
echo "-----> Running deploy tasks"
|
echo "-----> Running deploy tasks"
|
||||||
#{echo_cmd %[#{rake} after_party:run]}
|
#{echo_cmd %[bundle exec rake after_party:run]}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :service do
|
||||||
|
desc "Manage services."
|
||||||
|
task :restart_puma do
|
||||||
|
command %{
|
||||||
|
echo "-----> Restarting puma service"
|
||||||
|
#{echo_cmd %[sudo systemctl restart puma]}
|
||||||
|
echo "-----> Reloading nginx service"
|
||||||
|
#{echo_cmd %[sudo systemctl reload nginx]}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
task :restart_delayed_job do
|
||||||
|
command %{
|
||||||
|
echo "-----> Restarting delayed_job service"
|
||||||
|
#{echo_cmd %[sudo systemctl restart delayed_job]}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Deploys the current version to the server."
|
desc "Deploys the current version to the server."
|
||||||
task :deploy => :environment do
|
task :deploy do
|
||||||
queue 'export PATH=$PATH:/usr/local/rbenv/bin:/usr/local/rbenv/shims'
|
command 'export PATH=$PATH:/home/ds/.rbenv/bin:/home/ds/.rbenv/shims'
|
||||||
|
command 'source /home/ds/.profile'
|
||||||
deploy do
|
deploy do
|
||||||
queue %[sudo service delayed_job_#{user!} stop || true]
|
|
||||||
# Put things that will set up an empty directory into a fully set-up
|
# Put things that will set up an empty directory into a fully set-up
|
||||||
# instance of your project.
|
# instance of your project.
|
||||||
invoke :'git:clone'
|
invoke :'git:clone'
|
||||||
|
@ -127,14 +108,11 @@ task :deploy => :environment do
|
||||||
invoke :'yarn:install'
|
invoke :'yarn:install'
|
||||||
invoke :'rails:db_migrate'
|
invoke :'rails:db_migrate'
|
||||||
invoke :'after_party:run'
|
invoke :'after_party:run'
|
||||||
invoke :'rails:assets_precompile:force'
|
invoke :'rails:assets_precompile'
|
||||||
|
|
||||||
to :launch do
|
on :launch do
|
||||||
queue "/etc/init.d/#{user} upgrade "
|
invoke :'service:restart_puma'
|
||||||
queue! %[sudo service delayed_job_#{user!} start]
|
invoke :'service:restart_delayed_job'
|
||||||
|
|
||||||
# If you are deploying a review app on a fresh testing environment,
|
|
||||||
# now can be a good time to seed the database.
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,27 @@
|
||||||
task :deploy do
|
task :deploy do
|
||||||
domains = ['149.202.72.152', '149.202.198.6']
|
domains = ['web1', 'web2']
|
||||||
domains.each do |domain|
|
domains.each do |domain|
|
||||||
sh "mina deploy domain=#{domain}"
|
sh "mina deploy domain=#{domain} force_asset_precompile=true"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :setup do
|
||||||
|
domains = ['web1', 'web2']
|
||||||
|
domains.each do |domain|
|
||||||
|
sh "mina setup domain=#{domain} force_asset_precompile=true"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :deploy_dev do
|
||||||
|
domains = ['web1.dev', 'web2.dev']
|
||||||
|
domains.each do |domain|
|
||||||
|
sh "mina deploy domain=#{domain} force_asset_precompile=true"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :setup_dev do
|
||||||
|
domains = ['web1.dev', 'web2.dev']
|
||||||
|
domains.each do |domain|
|
||||||
|
sh "mina setup domain=#{domain} force_asset_precompile=true"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue