2015-09-01 14:42:53 +02:00
|
|
|
require 'mina/bundler'
|
|
|
|
require 'mina/rails'
|
|
|
|
require 'mina/git'
|
2016-02-24 11:12:18 +01:00
|
|
|
require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
|
2015-09-01 14:42:53 +02:00
|
|
|
# require 'mina/rvm' # for rvm support. (http://rvm.io)
|
|
|
|
|
|
|
|
# Basic settings:
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
ENV['to'] ||= "staging"
|
2018-09-20 11:26:25 +02:00
|
|
|
if !["staging", "production"].include?(ENV['to'])
|
|
|
|
raise "Bad to=#{+ENV['to']}"
|
|
|
|
end
|
2015-09-01 14:42:53 +02:00
|
|
|
|
2018-09-20 11:26:25 +02:00
|
|
|
if ENV['domain'].nil?
|
|
|
|
raise "missing domain, run with 'rake deploy domain=37.187.154.237'"
|
|
|
|
end
|
2015-09-01 14:42:53 +02:00
|
|
|
|
|
|
|
set :domain, ENV['domain']
|
2018-01-10 17:26:12 +01:00
|
|
|
set :repository, 'https://github.com/betagouv/tps.git'
|
2015-09-01 14:42:53 +02:00
|
|
|
set :port, 2200
|
|
|
|
|
2017-04-05 10:22:37 +02:00
|
|
|
case ENV["to"]
|
|
|
|
when "staging"
|
2017-07-05 14:41:00 +02:00
|
|
|
set :branch, ENV['branch'] || 'dev'
|
2015-09-01 14:42:53 +02:00
|
|
|
set :deploy_to, '/var/www/tps_dev'
|
2016-02-24 11:12:18 +01:00
|
|
|
set :user, 'tps_dev' # Username in the server to SSH to.
|
2015-09-01 14:42:53 +02:00
|
|
|
appname = 'tps_dev'
|
2017-04-05 10:22:37 +02:00
|
|
|
when "production"
|
2017-05-31 17:22:30 +02:00
|
|
|
set :branch, ENV['branch'] || 'master'
|
2015-09-01 14:42:53 +02:00
|
|
|
set :deploy_to, '/var/www/tps'
|
2016-02-24 11:12:18 +01:00
|
|
|
set :user, 'tps' # Username in the server to SSH to.
|
2015-09-01 14:42:53 +02:00
|
|
|
appname = 'tps'
|
|
|
|
end
|
|
|
|
|
2017-05-31 17:24:16 +02:00
|
|
|
print "Deploy to #{ENV['to']} environment branch #{branch}\n"
|
|
|
|
|
2018-08-23 15:00:21 +02:00
|
|
|
set :rails_env, 'production'
|
2016-10-10 18:21:46 +02:00
|
|
|
|
2015-09-01 14:42:53 +02:00
|
|
|
# For system-wide RVM install.
|
|
|
|
# set :rvm_path, '/usr/local/rvm/bin/rvm'
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
set :shared_paths, [
|
2018-08-16 11:34:17 +02:00
|
|
|
'.env',
|
2018-01-15 18:54:57 +01:00
|
|
|
'log',
|
|
|
|
'uploads',
|
|
|
|
'tmp/pids',
|
|
|
|
'tmp/cache',
|
|
|
|
'tmp/sockets',
|
|
|
|
'public/system',
|
|
|
|
'public/uploads',
|
2018-08-22 18:15:00 +02:00
|
|
|
'config/unicorn.rb'
|
2018-01-15 18:54:57 +01:00
|
|
|
]
|
2015-09-01 14:42:53 +02:00
|
|
|
|
|
|
|
set :rbenv_path, "/usr/local/rbenv/bin/rbenv"
|
|
|
|
|
|
|
|
# Optional settings:
|
|
|
|
# set :user, 'foobar' # Username in the server to SSH to.
|
|
|
|
# set :port, '30000' # SSH port number.
|
2016-02-24 11:12:18 +01:00
|
|
|
set :forward_agent, true # SSH forward_agent.
|
2015-09-01 14:42:53 +02:00
|
|
|
|
|
|
|
# This task is the environment that is loaded for most commands, such as
|
|
|
|
# `mina deploy` or `mina rake`.
|
|
|
|
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"]
|
|
|
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/bin"]
|
|
|
|
|
|
|
|
queue! %[mkdir -p "#{deploy_to}/shared/tmp/pids"]
|
|
|
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]
|
|
|
|
|
|
|
|
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"]
|
|
|
|
|
2016-10-10 18:21:46 +02:00
|
|
|
queue! %[mkdir -p "#{deploy_to}/shared/app"]
|
|
|
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/app"]
|
|
|
|
|
2016-11-17 12:35:05 +01:00
|
|
|
queue! %[mkdir -p "#{deploy_to}/shared/views/layouts"]
|
|
|
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/views/layouts"]
|
|
|
|
|
2016-11-03 16:46:26 +01:00
|
|
|
queue! %[mkdir -p "#{deploy_to}/shared/config/locales/dynamics"]
|
|
|
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config/locales/dynamics"]
|
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
|
|
|
|
queue %{
|
|
|
|
echo "-----> Installing package dependencies using yarn"
|
|
|
|
#{echo_cmd %[yarn install --non-interactive]}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-18 15:45:23 +02:00
|
|
|
namespace :rails do
|
|
|
|
desc "Run deploy tasks."
|
|
|
|
task :after_party do
|
|
|
|
queue %{
|
|
|
|
echo "-----> Running deploy tasks"
|
2018-08-30 13:51:28 +02:00
|
|
|
#{echo_cmd %[bundle exec rake after_party:run]}
|
2018-07-18 15:45:23 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-01 14:42:53 +02:00
|
|
|
desc "Deploys the current version to the server."
|
|
|
|
task :deploy => :environment do
|
|
|
|
queue 'export PATH=$PATH:/usr/local/rbenv/bin:/usr/local/rbenv/shims'
|
|
|
|
deploy do
|
2017-09-28 10:48:48 +02:00
|
|
|
queue %[sudo service delayed_job_#{user!} stop || true]
|
2015-09-01 14:42:53 +02:00
|
|
|
# Put things that will set up an empty directory into a fully set-up
|
|
|
|
# instance of your project.
|
|
|
|
invoke :'git:clone'
|
|
|
|
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-07-18 15:45:23 +02:00
|
|
|
invoke :'rails:after_party'
|
2018-01-31 16:23:40 +01:00
|
|
|
invoke :'rails:assets_precompile:force'
|
2015-09-01 14:42:53 +02:00
|
|
|
|
|
|
|
to :launch do
|
|
|
|
queue "/etc/init.d/#{user} upgrade "
|
2017-09-28 10:48:48 +02:00
|
|
|
queue! %[sudo service delayed_job_#{user!} start]
|
2016-06-07 10:31:54 +02:00
|
|
|
|
2018-06-15 12:28:18 +02:00
|
|
|
# If you are deploying a review app on a fresh testing environment,
|
|
|
|
# now can be a good time to seed the database.
|
2015-09-01 14:42:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# For help in making your deploy script, see the Mina documentation:
|
|
|
|
#
|
|
|
|
# - http://nadarei.co/mina
|
|
|
|
# - http://nadarei.co/mina/tasks
|
|
|
|
# - http://nadarei.co/mina/settings
|
|
|
|
# - http://nadarei.co/mina/helpers
|