demarches-normaliennes/config/deploy.rb

125 lines
3.1 KiB
Ruby
Raw Normal View History

2015-09-01 14:42:53 +02:00
require 'mina/bundler'
require 'mina/git'
require 'mina/rails'
2018-09-20 11:33:33 +02:00
require 'mina/rbenv'
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
2018-10-24 14:21:19 +02:00
# shared_dirs - Manually create these paths in shared/ on your server.
# 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
set :repository, 'https://github.com/betagouv/demarches-simplifiees.fr.git'
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
namespace :after_party do
desc "Run after_party tasks."
task :run do
2018-09-03 18:36:09 +02:00
command %{
echo "-----> Running after_party"
2018-09-03 18:36:09 +02:00
#{echo_cmd %[bundle exec rake after_party:run]}
}
end
end
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
command %{
echo "-----> Restarting puma service"
#{echo_cmd %[sudo systemctl restart puma]}
}
end
desc "Reload nginx"
task :reload_nginx do
command %{
2018-09-03 18:36:09 +02:00
echo "-----> Reloading nginx service"
#{echo_cmd %[sudo systemctl reload nginx]}
}
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
command %{
echo "-----> Restarting delayed_job service"
#{echo_cmd %[sudo systemctl restart delayed_job]}
}
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'
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-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'
2018-09-03 18:36:09 +02:00
on :launch do
invoke :'service:restart_puma'
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
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'
end