From 2f5724f8fd90f828d898c81b7dc57ab5c3c4d7b6 Mon Sep 17 00:00:00 2001 From: Kostiantyn Kostiuk Date: Mon, 11 Sep 2023 11:10:17 +0300 Subject: [PATCH] fixup! Add stage env --- config/deploy.rb | 8 +++- config/deploy/production.rb | 6 --- config/deploy/staging.rb | 6 --- config/systemd/ikt.codelabs.site.service | 2 +- .../systemd/stage-ikt.codelabs.site.service | 2 +- lib/capistrano/tasks/application.rake | 40 +++++++++++++++++++ lib/capistrano/tasks/ikt_application.rake | 28 ------------- lib/capistrano/tasks/stage_application.rake | 28 ------------- 8 files changed, 49 insertions(+), 71 deletions(-) create mode 100644 lib/capistrano/tasks/application.rake delete mode 100644 lib/capistrano/tasks/ikt_application.rake delete mode 100644 lib/capistrano/tasks/stage_application.rake diff --git a/config/deploy.rb b/config/deploy.rb index 13bc6c99..a2d7ac00 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -2,8 +2,14 @@ set :repo_url, 'https://github.com/amnis-invictus/ikt.edu.vn.ua.git' -set :default_env, { path: '$HOME/.rbenv/versions/3.1.2/bin:$PATH' } +set :default_env, { path: '$HOME/.rbenv/shims:$PATH' } append :linked_files, '.env', 'config/master.key' append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system', 'storage' + +namespace :deploy do + after :finishing, 'application:restart' + after :finishing, 'nginx:reload' + after :finishing, 'bundler:clean' +end diff --git a/config/deploy/production.rb b/config/deploy/production.rb index e0b5ecd8..37558136 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -5,9 +5,3 @@ set :rails_env, :production 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 diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index f2f4192d..1b408d5e 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -7,9 +7,3 @@ append :linked_files, 'config/credentials/staging.key' 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 diff --git a/config/systemd/ikt.codelabs.site.service b/config/systemd/ikt.codelabs.site.service index 72177cdf..040b449d 100644 --- a/config/systemd/ikt.codelabs.site.service +++ b/config/systemd/ikt.codelabs.site.service @@ -9,7 +9,7 @@ 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' + Environment = 'PATH=/home/arch-user/.rbenv/shims:/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 diff --git a/config/systemd/stage-ikt.codelabs.site.service b/config/systemd/stage-ikt.codelabs.site.service index 3d1bfae2..074d2f53 100644 --- a/config/systemd/stage-ikt.codelabs.site.service +++ b/config/systemd/stage-ikt.codelabs.site.service @@ -9,7 +9,7 @@ Environment = 'RAILS_ENV=staging' 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' + Environment = 'PATH=/home/arch-user/.rbenv/shims:/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 diff --git a/lib/capistrano/tasks/application.rake b/lib/capistrano/tasks/application.rake new file mode 100644 index 00000000..0ec81ed2 --- /dev/null +++ b/lib/capistrano/tasks/application.rake @@ -0,0 +1,40 @@ +namespace :ikt_application do + desc 'Start application' + task :start do + on roles(:app), in: :sequence, wait: 5 do + within current_path do + if fetch(:rails_env) == 'staging' + execute 'sudo systemctl start stage-ikt.codelabs.site' + else + execute 'sudo systemctl start ikt.codelabs.site' + end + end + end + end + + desc 'Stop application' + task :stop do + on roles(:app), in: :sequence, wait: 5 do + within current_path do + if fetch(:rails_env) == 'staging' + execute 'sudo systemctl stop stage-ikt.codelabs.site' + else + execute 'sudo systemctl stop ikt.codelabs.site' + end + end + end + end + + desc 'Restart application' + task :restart do + on roles(:app), in: :sequence, wait: 5 do + within current_path do + if fetch(:rails_env) == 'staging' + execute 'sudo systemctl restart stage-ikt.codelabs.site' + else + execute 'sudo systemctl restart ikt.codelabs.site' + end + end + end + end +end diff --git a/lib/capistrano/tasks/ikt_application.rake b/lib/capistrano/tasks/ikt_application.rake deleted file mode 100644 index f58899c8..00000000 --- a/lib/capistrano/tasks/ikt_application.rake +++ /dev/null @@ -1,28 +0,0 @@ -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 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 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 ikt.codelabs.site' - end - end - end -end diff --git a/lib/capistrano/tasks/stage_application.rake b/lib/capistrano/tasks/stage_application.rake deleted file mode 100644 index 28ac23b1..00000000 --- a/lib/capistrano/tasks/stage_application.rake +++ /dev/null @@ -1,28 +0,0 @@ -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