Skip to content

Commit

Permalink
Add stage env
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
  • Loading branch information
kostyanf14 committed Sep 10, 2023
1 parent 00f95e8 commit 13975bc
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 40 deletions.
10 changes: 1 addition & 9 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@

set :rails_env, :production

set :default_env, { path: '$HOME/.rbenv/shims:$PATH' }
set :default_env, { path: '$HOME/.rbenv/versions/3.1.2/bin:$PATH' }

append :linked_files, '.env', 'config/master.key'

append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system', 'storage'

set :deploy_to, '/opt/ai/application'

namespace :deploy do
after :finishing, 'application:restart'
after :finishing, 'nginx:reload'
after :finishing, 'bundler:clean'
end
10 changes: 9 additions & 1 deletion config/deploy/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
set :branch, :main

server 'ikt.edu.vn.ua:10017', user: 'arch-user', roles: %i[app web db]
set :deploy_to, '/opt/ai/ikt.codelabs.site'

server 'ikt.codelabs.site:10017', user: 'arch-user', roles: %i[app web db]

namespace :deploy do
after :finishing, 'ikt_application:restart'
after :finishing, 'nginx:reload'
after :finishing, 'bundler:clean'
end
11 changes: 11 additions & 0 deletions config/deploy/stage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set :branch, :main

set :deploy_to, '/opt/ai/stage-ikt.codelabs.site'

server 'stage-ikt.codelabs.site:10016', user: 'arch-user', roles: %i[app web db]

namespace :deploy do
after :finishing, 'stage_application:restart'
after :finishing, 'nginx:reload'
after :finishing, 'bundler:clean'
end
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
upstream backend {
server unix:///opt/ai/application/current/tmp/sockets/server.sock fail_timeout=0;
upstream ikt_backend {
server unix:///opt/ai/ikt.codelabs.site/current/tmp/sockets/server.sock fail_timeout=0;
}

server {
listen *:80;
server_name ikt.edu.vn.ua ikt.codelabs.site;
return 301 https://$host$request_uri;
}

server {
listen *:443;
server_name ikt.edu.vn.ua ikt.codelabs.site;
client_max_body_size 1024M;
root /opt/ai/application/current/public/;
error_log /opt/ai/application/current/log/nginx_errors.log;
root /opt/ai/ikt.codelabs.site/current/public/;
error_log /opt/ai/ikt.codelabs.site/current/log/nginx_errors.log;

gzip on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/javascript application/octet-stream;

location @backend {
proxy_pass http://backend;
location @ikt_backend {
proxy_pass http://ikt_backend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /cable {
proxy_pass http://backend;
proxy_pass http://ikt_backend;
proxy_set_header Connection Upgrade;
proxy_set_header Upgrade websocket;
proxy_set_header Host $host;
Expand All @@ -38,10 +39,10 @@ server {

location /assets {
expires max;
try_files $uri @backend;
try_files $uri @ikt_backend;
}

location / {
try_files $uri @backend;
try_files $uri @ikt_backend;
}
}
48 changes: 48 additions & 0 deletions config/nginx/stage-ikt.codelabs.site.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
upstream stage_backend {
server unix:///opt/ai/stage-ikt.codelabs.site/current/tmp/sockets/server.sock fail_timeout=0;
}

server {
listen *:80;
server_name stage-ikt.codelabs.site;
return 301 https://$host$request_uri;
}

server {
listen *:443;
server_name stage-ikt.codelabs.site;
client_max_body_size 1024M;
root /opt/ai/stage-ikt.codelabs.site/current/public/;
error_log /opt/ai/stage-ikt.codelabs.site/current/log/nginx_errors.log;

gzip on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/javascript application/octet-stream;

location @stage_backend {
proxy_pass http://stage_backend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /cable {
proxy_pass http://stage_backend;
proxy_set_header Connection Upgrade;
proxy_set_header Upgrade websocket;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /assets {
expires max;
try_files $uri @stage_backend;
}

location / {
try_files $uri @stage_backend;
}
}
17 changes: 0 additions & 17 deletions config/systemd/application.service

This file was deleted.

17 changes: 17 additions & 0 deletions config/systemd/ikt.codelabs.site.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description = IKT Application
After = network.service

[Service]
User = arch-user
Group = arch-user
WorkingDirectory = /opt/ai/ikt.codelabs.site/current
Environment = 'RAILS_ENV=production'
Environment = 'SOCKET=unix:///opt/ai/ikt.codelabs.site/current/tmp/sockets/server.sock'
Environment = 'PIDFILE=/opt/ai/ikt.codelabs.site/current/tmp/pids/server.pid'
Environment = 'PATH=/home/arch-user/.rbenv/versions/3.1.2/bin:/usr/local/sbin:/usr/local/bin:/usr/bin'
ExecStart = /usr/bin/env bundle exec puma --config /opt/ai/ikt.codelabs.site/current/config/puma.rb
Restart = always

[Install]
WantedBy = multi-user.target
17 changes: 17 additions & 0 deletions config/systemd/stage-ikt.codelabs.site.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description = Stage IKT Application
After = network.service

[Service]
User = arch-user
Group = arch-user
WorkingDirectory = /opt/ai/stage-ikt.codelabs.site/current
Environment = 'RAILS_ENV=production'
Environment = 'SOCKET=unix:///opt/ai/stage-ikt.codelabs.site/current/tmp/sockets/server.sock'
Environment = 'PIDFILE=/opt/ai/stage-ikt.codelabs.site/current/tmp/pids/server.pid'
Environment = 'PATH=/home/arch-user/.rbenv/versions/3.1.2/bin:/usr/local/sbin:/usr/local/bin:/usr/bin'
ExecStart = /usr/bin/env bundle exec puma --config /opt/ai/stage-ikt.codelabs.site/current/config/puma.rb
Restart = always

[Install]
WantedBy = multi-user.target
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace :application do
namespace :ikt_application do
desc 'Start application'
task :start do
on roles(:app), in: :sequence, wait: 5 do
within current_path do
execute 'sudo systemctl start application'
execute 'sudo systemctl start ikt.codelabs.site'
end
end
end
Expand All @@ -12,7 +12,7 @@ namespace :application do
task :stop do
on roles(:app), in: :sequence, wait: 5 do
within current_path do
execute 'sudo systemctl stop application'
execute 'sudo systemctl stop ikt.codelabs.site'
end
end
end
Expand All @@ -21,7 +21,7 @@ namespace :application do
task :restart do
on roles(:app), in: :sequence, wait: 5 do
within current_path do
execute 'sudo systemctl restart application'
execute 'sudo systemctl restart ikt.codelabs.site'
end
end
end
Expand Down
28 changes: 28 additions & 0 deletions lib/capistrano/tasks/stage_application.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace :stage_application do
desc 'Start application'
task :start do
on roles(:app), in: :sequence, wait: 5 do
within current_path do
execute 'sudo systemctl start stage-ikt.codelabs.site'
end
end
end

desc 'Stop application'
task :stop do
on roles(:app), in: :sequence, wait: 5 do
within current_path do
execute 'sudo systemctl stop stage-ikt.codelabs.site'
end
end
end

desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
within current_path do
execute 'sudo systemctl restart stage-ikt.codelabs.site'
end
end
end
end

0 comments on commit 13975bc

Please sign in to comment.