2015-09-01 14:42:53 +02:00
|
|
|
require 'mina/bundler'
|
|
|
|
require 'mina/git'
|
2018-10-24 14:25:31 +02:00
|
|
|
require 'mina/rails'
|
2018-09-20 11:33:33 +02:00
|
|
|
require 'mina/rbenv'
|
2015-09-01 14:42:53 +02:00
|
|
|
|
2020-11-13 16:06:51 +01:00
|
|
|
SHARED_WORKER_FILE_NAME = 'i_am_a_worker'
|
2021-03-29 18:25:46 +02:00
|
|
|
SHARED_WEBSERVER_FILE_NAME = 'i_am_a_webserver'
|
2015-09-01 14:42:53 +02:00
|
|
|
# Basic settings:
|
2018-09-20 13:40:06 +02:00
|
|
|
# domain - The hostname to SSH to.
|
|
|
|
# deploy_to - Path to deploy into.
|
|
|
|
# repository - Git repo to clone from. (needed by mina/git)
|
|
|
|
# branch - Branch name to deploy. (needed by mina/git)
|
|
|
|
#
|
|
|
|
# Advanced settings:
|
|
|
|
# forward_agent - SSH forward_agent
|
|
|
|
# user - Username in the server to SSH to
|
2020-12-11 09:49:29 +01:00
|
|
|
# shared_dirs - Manually create these paths in shared/ on your server.
|
2018-10-24 14:21:19 +02:00
|
|
|
# They will be linked in the 'deploy:link_shared_paths' step.
|
2015-09-01 14:42:53 +02:00
|
|
|
|
2018-09-03 18:36:09 +02:00
|
|
|
deploy_to = '/var/www/ds'
|
2018-10-24 14:06:18 +02:00
|
|
|
shared_dirs = [
|
2018-01-15 18:54:57 +01:00
|
|
|
'log',
|
2018-09-03 18:36:09 +02:00
|
|
|
'sockets',
|
2018-10-24 14:26:25 +02:00
|
|
|
'tmp/cache',
|
2019-02-06 14:41:45 +01:00
|
|
|
'tmp/pids',
|
|
|
|
'vendor/bundle'
|
2018-01-15 18:54:57 +01:00
|
|
|
]
|
2018-10-24 14:21:45 +02:00
|
|
|
|
|
|
|
set :domain, ENV.fetch('domain')
|
|
|
|
set :deploy_to, deploy_to
|
2020-07-23 16:01:15 +02:00
|
|
|
# rubocop:disable DS/ApplicationName
|
2019-03-26 11:10:30 +01:00
|
|
|
set :repository, 'https://github.com/betagouv/demarches-simplifiees.fr.git'
|
2020-07-23 16:01:15 +02:00
|
|
|
# rubocop:enable DS/ApplicationName
|
2018-10-24 14:21:45 +02:00
|
|
|
set :branch, ENV.fetch('branch')
|
|
|
|
set :forward_agent, true
|
|
|
|
set :user, 'ds'
|
2018-10-24 14:06:18 +02:00
|
|
|
set :shared_dirs, shared_dirs
|
2018-10-24 14:21:45 +02:00
|
|
|
set :rbenv_path, "/home/ds/.rbenv/bin/rbenv"
|
2015-09-01 14:42:53 +02:00
|
|
|
|
2018-10-24 11:56:48 +02:00
|
|
|
puts "Deploy to #{ENV.fetch('domain')}, branch: #{ENV.fetch('branch')}"
|
|
|
|
|
2018-10-24 11:59:44 +02:00
|
|
|
# This task is the environment that is loaded for most commands, such as
|
|
|
|
# `mina deploy` or `mina rake`.
|
2018-09-03 18:36:09 +02:00
|
|
|
task :setup do
|
2018-10-24 14:06:18 +02:00
|
|
|
shared_dirs.each do |dir|
|
|
|
|
command %[mkdir -p "#{deploy_to}/shared/#{dir}"]
|
|
|
|
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/#{dir}"]
|
|
|
|
end
|
2015-09-01 14:42:53 +02:00
|
|
|
end
|
|
|
|
|
2018-07-26 10:51:37 +02:00
|
|
|
namespace :yarn do
|
|
|
|
desc "Install package dependencies using yarn."
|
|
|
|
task :install do
|
2018-09-03 18:36:09 +02:00
|
|
|
command %{
|
2018-07-26 10:51:37 +02:00
|
|
|
echo "-----> Installing package dependencies using yarn"
|
|
|
|
#{echo_cmd %[yarn install --non-interactive]}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-16 14:49:34 +02:00
|
|
|
namespace :after_party do
|
|
|
|
desc "Run after_party tasks."
|
|
|
|
task :run do
|
2018-09-03 18:36:09 +02:00
|
|
|
command %{
|
2018-12-04 14:42:52 +01:00
|
|
|
echo "-----> Running after_party"
|
2018-09-03 18:36:09 +02:00
|
|
|
#{echo_cmd %[bundle exec rake after_party:run]}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-28 16:45:16 +01:00
|
|
|
namespace :jobs_schedule do
|
|
|
|
desc "Run jobs_schedule tasks."
|
|
|
|
task :run do
|
|
|
|
command %{
|
|
|
|
echo "-----> Running jobs_schedule"
|
|
|
|
#{echo_cmd %[bundle exec rake jobs:schedule]}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-03 18:36:09 +02:00
|
|
|
namespace :service do
|
2018-10-24 12:02:04 +02:00
|
|
|
desc "Restart puma"
|
2018-09-03 18:36:09 +02:00
|
|
|
task :restart_puma do
|
2021-03-29 18:25:46 +02:00
|
|
|
webserver_file_path = File.join(deploy_to, 'shared', SHARED_WEBSERVER_FILE_NAME)
|
|
|
|
|
2018-09-03 18:36:09 +02:00
|
|
|
command %{
|
|
|
|
echo "-----> Restarting puma service"
|
2021-03-29 18:25:46 +02:00
|
|
|
#{echo_cmd %[test -f #{webserver_file_path} && sudo systemctl restart puma]}
|
2018-10-24 14:23:41 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Reload nginx"
|
|
|
|
task :reload_nginx do
|
2021-03-29 18:25:46 +02:00
|
|
|
webserver_file_path = File.join(deploy_to, 'shared', SHARED_WEBSERVER_FILE_NAME)
|
|
|
|
|
2018-10-24 14:23:41 +02:00
|
|
|
command %{
|
2018-09-03 18:36:09 +02:00
|
|
|
echo "-----> Reloading nginx service"
|
2021-03-29 18:25:46 +02:00
|
|
|
#{echo_cmd %[test -f #{webserver_file_path} && sudo systemctl reload nginx]}
|
2018-09-03 18:36:09 +02:00
|
|
|
}
|
|
|
|
end
|
2018-10-24 11:59:44 +02:00
|
|
|
|
2018-10-24 12:02:04 +02:00
|
|
|
desc "Restart delayed_job"
|
2018-09-03 18:36:09 +02:00
|
|
|
task :restart_delayed_job do
|
2020-12-11 09:49:29 +01:00
|
|
|
worker_file_path = File.join(deploy_to, 'shared', SHARED_WORKER_FILE_NAME)
|
|
|
|
|
|
|
|
command %{
|
2020-11-13 16:06:51 +01:00
|
|
|
echo "-----> Restarting delayed_job service"
|
2020-12-11 09:49:29 +01:00
|
|
|
#{echo_cmd %[test -f #{worker_file_path} && echo 'it is a worker marchine, restarting delayed_job']}
|
|
|
|
#{echo_cmd %[test -f #{worker_file_path} && sudo systemctl restart delayed_job]}
|
|
|
|
#{echo_cmd %[test -f #{worker_file_path} || echo "it is not a worker marchine, #{worker_file_path} is absent"]}
|
|
|
|
}
|
2018-10-16 14:49:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-01 14:42:53 +02:00
|
|
|
desc "Deploys the current version to the server."
|
2018-09-03 18:36:09 +02:00
|
|
|
task :deploy do
|
|
|
|
command 'export PATH=$PATH:/home/ds/.rbenv/bin:/home/ds/.rbenv/shims'
|
|
|
|
command 'source /home/ds/.profile'
|
2019-10-24 14:37:52 +02:00
|
|
|
# increase db timeout to 5 minutes to allow long migration
|
|
|
|
command 'export PG_STATEMENT_TIMEOUT=300000'
|
2018-10-24 14:24:27 +02:00
|
|
|
|
2015-09-01 14:42:53 +02:00
|
|
|
deploy do
|
|
|
|
# Put things that will set up an empty directory into a fully set-up
|
|
|
|
# instance of your project.
|
2018-10-19 11:09:57 +02:00
|
|
|
|
2018-10-24 14:24:27 +02:00
|
|
|
invoke :'git:clone'
|
2015-09-01 14:42:53 +02:00
|
|
|
invoke :'deploy:link_shared_paths'
|
|
|
|
invoke :'bundle:install'
|
2018-07-26 10:51:37 +02:00
|
|
|
invoke :'yarn:install'
|
2015-09-01 14:42:53 +02:00
|
|
|
invoke :'rails:db_migrate'
|
2018-09-03 18:36:09 +02:00
|
|
|
invoke :'rails:assets_precompile'
|
2016-06-07 10:31:54 +02:00
|
|
|
|
2018-09-03 18:36:09 +02:00
|
|
|
on :launch do
|
|
|
|
invoke :'service:restart_puma'
|
2018-10-24 14:23:41 +02:00
|
|
|
invoke :'service:reload_nginx'
|
2018-09-03 18:36:09 +02:00
|
|
|
invoke :'service:restart_delayed_job'
|
2018-11-22 18:26:18 +01:00
|
|
|
invoke :'deploy:cleanup'
|
2015-09-01 14:42:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-04 14:42:52 +01:00
|
|
|
|
|
|
|
task :post_deploy do
|
|
|
|
command 'export PATH=$PATH:/home/ds/.rbenv/bin:/home/ds/.rbenv/shims'
|
|
|
|
command 'source /home/ds/.profile'
|
|
|
|
command 'cd /home/ds/current'
|
|
|
|
|
|
|
|
invoke :'after_party:run'
|
2020-03-28 16:45:16 +01:00
|
|
|
invoke :'jobs_schedule:run'
|
2018-12-04 14:42:52 +01:00
|
|
|
end
|