111 lines
4.0 KiB
Ruby

set :application, "thirteen_tien_len_#{fetch(:stage)}"
set :repo_url, 'git@pineapple.punked.us:Bort/thirteen-tien-len.git'
# If you want to import assets, you can change default asset dir (default = system)
# This directory must be in your shared directory on the server
set :assets_dir, %w(public/assets public/system)
#set :local_assets_dir, %w(public/assets public/att)
#set :branch, proc { `git rev-parse --abbrev-ref stash`.chomp }
#ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :remote_user, "thirteen"
set :deploy_to, "/home/thirteen/srv/thirteen-tien-len_#{fetch(:stage)}"
# set :scm, :git
# set :format, :pretty
# set :log_level, :debug
# set :pty, true
# set :linked_files, %w{config/database.yml .env}
# append :linked_files, "puma.rb"
# append :linked_files, "config/master.key"
append :linked_files, "config/database.yml"
append :linked_files, ".env"
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/lift-calculator}
set :rbenv_type, :user # or :system, or :fullstaq (for Fullstaq Ruby), depends on your rbenv setup
# set :rbenv_ruby, '2.6.0'
set :rbenv_ruby, File.read('.ruby-version').strip
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
append :rbenv_map_bins, 'puma', 'pumactl'
set :rbenv_roles, :all # default value
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :default_env, {
'PATH' => 'PATH=$HOME/bin:/usr/local/rbenv/bin:./bin:$PATH:./bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:$HOME/.rbenv/bin'
}
# set :keep_releases, 5
# rbenv system global rbenv install config
# set :rbenv_custom_path, "/usr/local/rbenv"
# set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_custom_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_custom_path)}/bin/rbenv exec"
set :rbenv_prefix, "/home/thirteen/.rbenv/bin/rbenv exec"
set :nginx_path, '/etc/nginx' # directory containing sites-available and sites-enabled
set :nginx_template, 'config/deploy/nginx_conf.erb' # configuration template
#set :nginx_server_name, 'example.com' # optional, defaults to :application
#set :nginx_upstream, 'example-app' # optional, defaults to :application
# set :nginx_listen, 80 # optional, default is not set
# set :nginx_roles, :all
## postgresql
set :pg_user, "thirteen_tien_len_#{fetch(:stage)}"
set :pg_database, "thirteen_tien_len_#{fetch(:stage)}"
set :puma_enable_socket_service, true
namespace :db do
desc 'Setup the database'
task :setup do
on roles(:app), in: :sequence, wait: 5 do
within release_path do
with rails_env: (fetch(:rails_env) || fetch(:stage)) do
execute :rake, 'db:setup'
end
end
end
end
end
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
after :finishing, 'deploy:cleanup'
end
namespace :rails do
desc 'Open a rails console `cap [staging] rails:console [server_index default: 0]`'
task :console do
server = roles(:app)[ARGV[2].to_i]
puts "Opening a console on: #{server.hostname}...."
cmd = "ssh #{server.user}@#{server.hostname} -t 'bash -c export PATH=/usr/local/rbenv/bin:./bin:$PATH:./bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:$HOME/.rbenv/bin; cd #{fetch(:deploy_to)}/current && RAILS_ENV=#{fetch(:rails_env)} which ruby'"
# cmd = "ssh #{server.user}@#{server.hostname} -t 'export PATH=/usr/local/rbenv/bin:./bin:$PATH:./bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:$HOME/.rbenv/bin; cd #{fetch(:deploy_to)}/current && RAILS_ENV=#{fetch(:rails_env)} bundle exec rails console'"
puts cmd
exec cmd
end
end