Skip to content

Instantly share code, notes, and snippets.

@dthtien
Last active November 5, 2023 22:57
Show Gist options
  • Save dthtien/6d3dce146530a7b4d0bc7cc3c6b55cc0 to your computer and use it in GitHub Desktop.
Save dthtien/6d3dce146530a7b4d0bc7cc3c6b55cc0 to your computer and use it in GitHub Desktop.
# config valid for current version and patch releases of Capistrano
lock "~> 3.11.0"
set :message, "Deploy voucher trader api app"
set :application, "voucher_trader_api"
set :repo_url, "[email protected]:dthtien/voucher_trader_api.git "
set :deploy_user, 'deploy'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/home/#{fetch :deploy_user}/#{fetch :application}"
upstream app {
server unix:/home/deploy/voucher_trader_api/shared/sockets/puma.sock fail_timeout=0;
}
server {
listen 80 default;
root /home/deploy/voucher_trader_api/current/public;
try_files $uri/index.html $uri @app;
location @app {
proxy_pass http://app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_set_header Host $http_host;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
workers 1
threads 1, 6
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
app_dir = '/home/deploy/voucher_trader_api'
current_dir = "#{app_dir}/current"
shared_dir = "#{app_dir}/shared"
# Specifies the `environment` that Puma will run in.
rails_env = ENV['RAILS_ENV'] || 'production'
environment rails_env
#Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"
# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true
# setup master PID and state location
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app
on_worker_boot do
require "active_record"
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{current_dir}/config/database.yml")[rails_env])
end
~
#VPS
sudo adduser deploy
sudo vim /etc/sudoers
%deploy ALL=(ALL) NOPASSWD: ALL
sudo su - deploy
mkdir .ssh
sudo chmod 700 .ssh
vim ~/.ssh/authorized_keys
sudo chmod 600 ~/.ssh/authorized_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment