demarches-normaliennes/config/deploy.rb

115 lines
3.1 KiB
Ruby
Raw Normal View History

2015-09-01 14:42:53 +02:00
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
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
2015-09-01 14:42:53 +02:00
2018-10-24 11:40:08 +02:00
set :domain, ENV.fetch('domain')
set :repository, 'https://github.com/betagouv/tps.git'
2018-09-03 18:36:09 +02:00
deploy_to = '/var/www/ds'
set :deploy_to, deploy_to
set :user, 'ds'
2018-10-24 11:40:08 +02:00
set :branch, ENV.fetch('branch')
2015-09-01 14:42:53 +02:00
# 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.
2018-09-03 18:36:09 +02:00
set :shared_dirs, [
2018-01-15 18:54:57 +01:00
'log',
2018-09-03 18:36:09 +02:00
'sockets',
2018-01-15 18:54:57 +01:00
'tmp/pids',
2018-09-03 18:36:09 +02:00
'tmp/cache'
2018-01-15 18:54:57 +01:00
]
2015-09-01 14:42:53 +02:00
2018-09-03 18:36:09 +02:00
set :rbenv_path, "/home/ds/.rbenv/bin/rbenv"
set :forward_agent, true # SSH forward_agent.
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
command %[mkdir -p "#{deploy_to}/shared/log"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
2015-09-01 14:42:53 +02:00
2018-09-03 18:36:09 +02:00
command %[mkdir -p "#{deploy_to}/shared/tmp/pids"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]
2018-09-03 18:36:09 +02:00
command %[mkdir -p "#{deploy_to}/shared/tmp/cache"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/cache"]
2016-11-17 12:35:05 +01:00
2018-09-03 18:36:09 +02:00
command %[mkdir -p "#{deploy_to}/shared/sockets"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/sockets"]
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 deploy tasks"
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]}
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'
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.
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'
invoke :'after_party:run'
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:restart_delayed_job'
2015-09-01 14:42:53 +02:00
end
end
end