From 854d3661eb6e24817b14e11ae4ac2d4e0f52ffdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 18 Oct 2025 19:18:24 +0000 Subject: [PATCH 1/4] Setup capistrano deployment with puma and rvm Puma 5 doesn't support daemonize, so we need to use systemd to manage the puma process. --- .gitignore | 1 + Capfile | 42 +++++++++++++++++++++++++++++++++++++ Gemfile | 5 ++++- Gemfile.lock | 41 ++++++++++++++++++++++++++++++++++-- bin/cap | 27 ++++++++++++++++++++++++ bin/capify | 27 ++++++++++++++++++++++++ config/deploy.rb | 12 +++++++++++ config/deploy/production.rb | 7 +++++++ config/puma.rb | 1 - 9 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 Capfile create mode 100755 bin/cap create mode 100755 bin/capify create mode 100644 config/deploy.rb create mode 100644 config/deploy/production.rb diff --git a/.gitignore b/.gitignore index cbd7075..d6d09a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ run-rails-master-hook +/log diff --git a/Capfile b/Capfile new file mode 100644 index 0000000..22adb18 --- /dev/null +++ b/Capfile @@ -0,0 +1,42 @@ +# Load DSL and set up stages +require "capistrano/setup" + +# Include default deployment tasks +require "capistrano/deploy" + +# Load the SCM plugin appropriate to your project: +# +# require "capistrano/scm/hg" +# install_plugin Capistrano::SCM::Hg +# or +# require "capistrano/scm/svn" +# install_plugin Capistrano::SCM::Svn +# or +require "capistrano/scm/git" +install_plugin Capistrano::SCM::Git + +# Include tasks from other gems included in your Gemfile +# +# For documentation on these, see for example: +# +# https://github.com/capistrano/rvm +# https://github.com/capistrano/rbenv +# https://github.com/capistrano/chruby +# https://github.com/capistrano/bundler +# https://github.com/capistrano/rails +# https://github.com/capistrano/passenger +# +require "capistrano/rvm" +# require "capistrano/rbenv" +# require "capistrano/chruby" +# require "capistrano/bundler" +# require "capistrano/rails/assets" +# require "capistrano/rails/migrations" +# require "capistrano/passenger" + +# Load custom tasks from `lib/capistrano/tasks` if you have any defined +Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } + +require 'capistrano/puma' +install_plugin Capistrano::Puma +install_plugin Capistrano::Puma::Systemd diff --git a/Gemfile b/Gemfile index 8c6ad87..10cc338 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,7 @@ source 'https://rubygems.org' gem "rack", "~> 2.2" -gem "puma", "~> 4.3" +gem "puma", "~> 5.6" + +gem "capistrano3-puma" +gem "capistrano-rvm" diff --git a/Gemfile.lock b/Gemfile.lock index 56451b3..60fee6d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,16 +1,53 @@ GEM remote: https://rubygems.org/ specs: + airbrussh (1.5.3) + sshkit (>= 1.6.1, != 1.7.0) + base64 (0.3.0) + capistrano (3.19.2) + airbrussh (>= 1.0.0) + i18n + rake (>= 10.0.0) + sshkit (>= 1.9.0) + capistrano-bundler (2.1.1) + capistrano (~> 3.1) + capistrano-rvm (0.1.2) + capistrano (~> 3.0) + sshkit (~> 1.2) + capistrano3-puma (6.2.0) + capistrano (~> 3.7) + capistrano-bundler + puma (>= 5.1, < 7.0) + concurrent-ruby (1.3.5) + i18n (1.14.7) + concurrent-ruby (~> 1.0) + logger (1.7.0) + net-scp (4.1.0) + net-ssh (>= 2.6.5, < 8.0.0) + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) + net-ssh (7.3.0) nio4r (2.7.4) - puma (4.3.12) + ostruct (0.6.3) + puma (5.6.9) nio4r (~> 2.0) rack (2.2.20) + rake (13.3.0) + sshkit (1.24.0) + base64 + logger + net-scp (>= 1.1.2) + net-sftp (>= 2.1.2) + net-ssh (>= 2.8.0) + ostruct PLATFORMS ruby DEPENDENCIES - puma (~> 4.3) + capistrano-rvm + capistrano3-puma + puma (~> 5.6) rack (~> 2.2) BUNDLED WITH diff --git a/bin/cap b/bin/cap new file mode 100755 index 0000000..6dfe3fd --- /dev/null +++ b/bin/cap @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'cap' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("capistrano", "cap") diff --git a/bin/capify b/bin/capify new file mode 100755 index 0000000..86d25e1 --- /dev/null +++ b/bin/capify @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'capify' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("capistrano", "capify") diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..a2be650 --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,12 @@ +# config valid for current version and patch releases of Capistrano +lock "~> 3.19.2" + +set :application, "rails-master-hook" +set :repo_url, "https://github.com/rails/rails-master-hook.git" + +set :deploy_to, "/home/rails/rails-master-hook-deploy" + +set :keep_releases, 5 + +set :puma_bind, "tcp://0.0.0.0:9293" +set :puma_systemctl_user, :system diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 0000000..c3983e5 --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,7 @@ +DOCS_SERVER_IP = '138.197.6.175' + +set :ssh_options, port: 987 +server DOCS_SERVER_IP, user: 'rails', roles: %w(web) + +set :rvm_ruby_version, '3.3.4' +set :rvm_custom_path, '/home/rails/.rvm' diff --git a/config/puma.rb b/config/puma.rb index 660ee2d..34df675 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,3 +1,2 @@ -daemonize true pidfile "puma.pid" threads 1, 1 From f35f8fc7f5a760da960390e99acd4ceb1c6d22b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 18 Oct 2025 19:21:31 +0000 Subject: [PATCH 2/4] Bind to a the same port in the capistrano config --- config/deploy.rb | 2 +- config/puma.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index a2be650..e949a81 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -8,5 +8,5 @@ set :keep_releases, 5 -set :puma_bind, "tcp://0.0.0.0:9293" +set :puma_bind, "tcp://0.0.0.0:9292" set :puma_systemctl_user, :system diff --git a/config/puma.rb b/config/puma.rb index 34df675..7dab7ac 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,2 +1,3 @@ pidfile "puma.pid" threads 1, 1 +bind "tcp://0.0.0.0:9292" From aacd6a1e89c9f28647fd6732f4fbc8961d4d4d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 18 Oct 2025 22:38:48 +0000 Subject: [PATCH 3/4] Upgrade to Puma 6 --- Gemfile | 2 +- Gemfile.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 10cc338..ed7deba 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gem "rack", "~> 2.2" -gem "puma", "~> 5.6" +gem "puma", "~> 6.0" gem "capistrano3-puma" gem "capistrano-rvm" diff --git a/Gemfile.lock b/Gemfile.lock index 60fee6d..7f37cf7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,10 +14,10 @@ GEM capistrano-rvm (0.1.2) capistrano (~> 3.0) sshkit (~> 1.2) - capistrano3-puma (6.2.0) + capistrano3-puma (7.0.0) capistrano (~> 3.7) capistrano-bundler - puma (>= 5.1, < 7.0) + puma (>= 6.1, < 8.0) concurrent-ruby (1.3.5) i18n (1.14.7) concurrent-ruby (~> 1.0) @@ -29,7 +29,7 @@ GEM net-ssh (7.3.0) nio4r (2.7.4) ostruct (0.6.3) - puma (5.6.9) + puma (6.6.1) nio4r (~> 2.0) rack (2.2.20) rake (13.3.0) @@ -47,7 +47,7 @@ PLATFORMS DEPENDENCIES capistrano-rvm capistrano3-puma - puma (~> 5.6) + puma (~> 6.0) rack (~> 2.2) BUNDLED WITH From e5e3ce09e28a5678721e744c690b46bcbb26a5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sun, 19 Oct 2025 17:42:20 +0000 Subject: [PATCH 4/4] Set the RUN_FILE environment variable to the right place --- config/deploy/production.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/deploy/production.rb b/config/deploy/production.rb index c3983e5..9dcb52d 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -5,3 +5,7 @@ set :rvm_ruby_version, '3.3.4' set :rvm_custom_path, '/home/rails/.rvm' + +set :puma_service_unit_env_vars, %w[ + RUN_FILE=/home/rails/rails-master-hook/run-rails-master-hook +]