|
3 | 3 | require 'mina/git' |
4 | 4 | require 'mina/rbenv' # for rbenv support. (https://rbenv.org) |
5 | 5 | # require 'mina/rvm' # for rvm support. (https://rvm.io) |
6 | | -require 'mina/puma' |
7 | 6 |
|
8 | 7 | # Basic settings: |
9 | 8 | # domain - The hostname to SSH to. |
|
14 | 13 | set :domain, 'xdev-server' |
15 | 14 | set :deploy_to, '/home/tamnguyen/apps/rails_5_api' |
16 | 15 | set :repository, 'git@github.com:ntamvl/rails_5_api_tutorial.git' |
17 | | -set :branch, 'master' |
| 16 | +set :branch, 'deploy' |
| 17 | +set :rails_env, 'production' |
18 | 18 |
|
19 | 19 | # Optional settings: |
20 | 20 | # set :user, 'foobar' # Username in the server to SSH to. |
|
27 | 27 | # They will be linked in the 'deploy:link_shared_paths' step. |
28 | 28 | # set :shared_dirs, fetch(:shared_dirs, []).push('config') |
29 | 29 | # set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml') |
30 | | -set :shared_dirs, fetch(:shared_dirs, []).push('config', 'tmp/sockets', 'tmp/pids') |
31 | | -set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'Gemfile.lock') |
| 30 | +set :shared_dirs, fetch(:shared_dirs, []).push('tmp/sockets', 'tmp/pids') |
| 31 | +set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'Gemfile.lock', 'config/puma.rb') |
32 | 32 |
|
33 | 33 | # This task is the environment that is loaded all remote run commands, such as |
34 | 34 | # `mina deploy` or `mina rake`. |
|
74 | 74 | # Put things that will set up an empty directory into a fully set-up |
75 | 75 | # instance of your project. |
76 | 76 | invoke :'git:clone' |
77 | | - invoke :'deploy:link_shared_paths' |
| 77 | + # invoke :'deploy:link_shared_paths' |
| 78 | + invoke :'my_link_paths' |
78 | 79 | invoke :'bundle:install' |
79 | | - invoke :'rails:db_migrate' |
80 | | - invoke :'rails:assets_precompile' |
| 80 | + # invoke :'rails:db_migrate' |
| 81 | + # invoke :'rails:assets_precompile' |
| 82 | + invoke :'my_db_migrate' |
| 83 | + invoke :'my_assets_clean' |
81 | 84 | invoke :'deploy:cleanup' |
| 85 | + invoke :'my_restart_puma' |
82 | 86 |
|
83 | 87 | on :launch do |
84 | 88 | in_path(fetch(:current_path)) do |
|
92 | 96 | # run :local { say 'done' } |
93 | 97 | end |
94 | 98 |
|
| 99 | +task :my_link_paths do |
| 100 | + comment %{Symlinking my shared paths} |
| 101 | + |
| 102 | + fetch(:shared_dirs, []).each do |linked_dir| |
| 103 | + command %{mkdir -p #{File.dirname("./#{linked_dir}")}} |
| 104 | + command %{rm -rf "./#{linked_dir}"} |
| 105 | + command %{ln -s "#{fetch(:shared_path)}/#{linked_dir}" "./#{linked_dir}"} |
| 106 | + end |
| 107 | + |
| 108 | + fetch(:shared_files, []).each do |linked_path| |
| 109 | + command %{ln -sf "#{fetch(:shared_path)}/#{linked_path}" "./#{linked_path}"} |
| 110 | + end |
| 111 | +end |
| 112 | + |
| 113 | +task :my_db_migrate do |
| 114 | + in_path(fetch(:current_path)) do |
| 115 | + comment %{Running command rails db:migrate for Rails 5+...} |
| 116 | + command %{rails db:migrate RAILS_ENV=production} |
| 117 | + end |
| 118 | +end |
| 119 | + |
| 120 | +task :my_assets_clean do |
| 121 | + in_path(fetch(:current_path)) do |
| 122 | + comment %{Running command rails tmp:clear for Rails 5+...} |
| 123 | + command %{rails tmp:clear RAILS_ENV=production} |
| 124 | + end |
| 125 | +end |
| 126 | + |
| 127 | +task :my_start_puma do |
| 128 | + in_path(fetch(:current_path)) do |
| 129 | + comment %{Puma is starting...} |
| 130 | + command %{bundler exec puma -C config/puma.rb -e production -d} |
| 131 | + comment %{Puma started!} |
| 132 | + end |
| 133 | +end |
| 134 | + |
| 135 | +task :my_stop_puma do |
| 136 | + in_path(fetch(:current_path)) do |
| 137 | + comment %{Puma is stopping...} |
| 138 | + command %{kill -9 `cat tmp/pids/puma.pid`} |
| 139 | + comment %{Puma stopped!} |
| 140 | + end |
| 141 | +end |
| 142 | + |
| 143 | +task :my_restart_puma do |
| 144 | + in_path(fetch(:current_path)) do |
| 145 | + invoke :'my_stop_puma' |
| 146 | + invoke :'my_start_puma' |
| 147 | + end |
| 148 | +end |
| 149 | + |
95 | 150 | # For help in making your deploy script, see the Mina documentation: |
96 | 151 | # |
97 | 152 | # - https://github.com/mina-deploy/mina/docs |
0 commit comments