diff --git a/Capfile b/Capfile index 860c088..0710381 100644 --- a/Capfile +++ b/Capfile @@ -1,41 +1,19 @@ +# frozen_string_literal: true + # Load DSL and set up stages -require "capistrano/setup" +require 'capistrano/setup' # Include default deployment tasks -require "capistrano/deploy" +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" +# Git SCM plugin +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" +# additional modules require 'capistrano/rails' -require 'capistrano/rvm' require 'capistrano/passenger' +require 'capistrano/cul' # Load custom tasks from `lib/capistrano/tasks` if you have any defined -Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } +Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } diff --git a/Gemfile b/Gemfile index ae91378..810ce1e 100644 --- a/Gemfile +++ b/Gemfile @@ -58,11 +58,11 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' - gem 'capistrano', '~> 3.17.3', require: false + # Use Capistrano for deployment + gem 'capistrano', '~> 3.18.0', require: false + gem 'capistrano-cul', require: false + gem 'capistrano-passenger', '~> 0.1', require: false gem 'capistrano-rails', '~> 1.4', require: false - gem 'capistrano-bundler', '~> 1.1', require: false - gem 'capistrano-rvm', '~> 0.1', require: false - gem 'capistrano-passenger', '~> 0.2', require: false end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index 0a7c75c..9e64fd6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,9 +75,11 @@ GEM tzinfo (~> 2.0) addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) - airbrussh (1.5.0) + airbrussh (1.5.3) sshkit (>= 1.6.1, != 1.7.0) + base64 (0.2.0) bcrypt (3.1.18) + bcrypt_pbkdf (1.1.1) bigdecimal (3.1.4) bindex (0.5.0) bootsnap (1.10.3) @@ -85,21 +87,26 @@ GEM builder (3.2.4) byebug (11.1.3) cancancan (3.5.0) - capistrano (3.17.3) + capistrano (3.18.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) sshkit (>= 1.9.0) capistrano-bundler (1.5.0) capistrano (~> 3.1) + capistrano-cul (0.3.4) + bcrypt_pbkdf (>= 1.0.1) + capistrano (~> 3.1) + capistrano-git-with-submodules (~> 2.0) + ed25519 (>= 1.2.4) + net-ssh (>= 5) + capistrano-git-with-submodules (2.0.6) + capistrano (~> 3.7) capistrano-passenger (0.2.0) capistrano (~> 3.0) capistrano-rails (1.4.0) capistrano (~> 3.1) capistrano-bundler (~> 1.1) - capistrano-rvm (0.1.2) - capistrano (~> 3.0) - sshkit (~> 1.2) capybara (3.39.2) addressable matrix @@ -130,6 +137,7 @@ GEM devise diff-lcs (1.5.0) docile (1.4.0) + ed25519 (1.3.0) erubi (1.12.0) execjs (2.7.0) factory_bot (4.11.1) @@ -178,9 +186,11 @@ GEM timeout net-scp (4.0.0) net-ssh (>= 2.6.5, < 8.0.0) + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) net-smtp (0.3.3) net-protocol - net-ssh (7.2.0) + net-ssh (7.3.0) nio4r (2.5.9) nokogiri (1.15.5) mini_portile2 (~> 2.8.2) @@ -193,6 +203,7 @@ GEM nokogiri (~> 1.5) omniauth (~> 1.2) orm_adapter (0.5.0) + ostruct (0.6.1) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -291,9 +302,12 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.5.4) mini_portile2 (~> 2.8.0) - sshkit (1.21.6) + sshkit (1.23.2) + base64 net-scp (>= 1.1.2) + net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) + ostruct thor (1.2.1) tilt (2.0.10) timeout (0.3.2) @@ -328,11 +342,10 @@ DEPENDENCIES bootsnap byebug cancancan (~> 3.0) - capistrano (~> 3.17.3) - capistrano-bundler (~> 1.1) - capistrano-passenger (~> 0.2) + capistrano (~> 3.18.0) + capistrano-cul + capistrano-passenger (~> 0.1) capistrano-rails (~> 1.4) - capistrano-rvm (~> 0.1) capybara (~> 3.39) cul-ldap! cul_omniauth (~> 0.8.0) diff --git a/config/deploy.rb b/config/deploy.rb index b42d750..b194534 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,65 +1,87 @@ -# config valid only for current version of Capistrano -lock "~> 3.17.3" +# frozen_string_literal: true -set :department, 'ldpd' -set :instance, fetch(:department) +# config valid for current version and patch releases of Capistrano +lock '~> 3.18.0' + +# Until we retire all old CentOS VMs, we need to set the rvm_custom_path because rvm is installed +# in a non-standard location for our AlmaLinux VMs. This is because our service accounts need to +# maintain two rvm installations for two different Linux OS versions. +set :rvm_custom_path, '~/.rvm-alma8' + +set :remote_user, 'renserv' set :application, 'hours' -set :repo_name, "ldpd-hours" +set :repo_url, "git@github.com:cul/ldpd-hours.git" set :deploy_name, "#{fetch(:application)}_#{fetch(:stage)}" # used to run rake db:migrate, etc -# Default value for :rails_env is fetch(:stage) set :rails_env, fetch(:deploy_name) -# use the rvm wrapper -set :rvm_custom_path, '~/.rvm-alma8' -set :rvm_ruby_version, fetch(:deploy_name) - -set :repo_url, "git@github.com:cul/#{fetch(:repo_name)}.git" - -set :remote_user, "renserv" -# Default deploy_to directory is /var/www/:application -set :deploy_to, "/opt/passenger/#{fetch(:deploy_name)}" +# Default deploy_to directory is /var/www/my_app_name +set :deploy_to, "/opt/passenger/#{fetch(:deploy_name)}" -# Default value for :log_level is :debug -set :log_level, :info +# Default value for :linked_files is [] +append :linked_files, + 'config/database.yml', + 'config/secrets.yml', + 'config/wifi_density.yml' # Default value for linked_dirs is [] -set :linked_dirs, fetch(:linked_dirs, []).push('log') +append :linked_dirs, 'log', 'tmp/pids', 'node_modules' + +set :passenger_restart_with_touch, true # Default value for keep_releases is 5 set :keep_releases, 3 -set :passenger_restart_with_touch, true +# Set default log level (which can be overridden by other environments) +set :log_level, :info -set :linked_files, fetch(:linked_files, []).push( - "config/database.yml", - "config/secrets.yml", - "config/wifi_density.yml" -) - -before "deploy:assets:precompile", "deploy:yarn_install" - -namespace :deploy do - desc "Report the environment" - task :report do - run_locally do - puts "cap called with stage = \"#{fetch(:stage,'none')}\"" - puts "cap would deploy to = \"#{fetch(:deploy_to,'none')}\"" - puts "cap would install from #{fetch(:repo_url)}" - puts "cap would install in Rails env #{fetch(:rails_env)}" - end - end +# NVM Setup, for selecting the correct node version +# NOTE: This NVM configuration MUST be configured before the RVM setup steps because: +# This works: +# nvm exec 16 ~/.rvm-alma8/bin/rvm example_app_dev do node --version +# But this does not work: +# ~/.rvm-alma8/bin/rvm example_app_dev do nvm exec 16 node --version +set :nvm_node_version, fetch(:deploy_name) # This NVM alias must exist on the server +[:rake, :node, :npm, :yarn].each do |command_to_prefix| + SSHKit.config.command_map.prefix[command_to_prefix].push("nvm exec #{fetch(:nvm_node_version)}") +end + +# RVM Setup, for selecting the correct ruby version (instead of capistrano-rvm gem) +set :rvm_ruby_version, fetch(:deploy_name) # This RVM alias must exist on the server +[:rake, :gem, :bundle, :ruby].each do |command_to_prefix| + SSHKit.config.command_map.prefix[command_to_prefix].push( + "#{fetch(:rvm_custom_path, '~/.rvm')}/bin/rvm #{fetch(:rvm_ruby_version)} do" + ) +end - desc "Add tag based on current version from VERSION file" - task :auto_tag do - current_version = "v#{IO.read("VERSION").strip}" +# Default value for default_env is {} +set :default_env, NODE_ENV: 'production' - ask(:tag, current_version) - tag = fetch(:tag) +# Default branch is :master +# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp - system("git tag -a #{tag} -m 'auto-tagged' && git push origin --tags") - end +# Default value for :scm is :git +# set :scm, :git + +# Default value for :format is :airbrussh +# set :format, :airbrussh + +# You can configure the Airbrussh format using :format_options. +# These are the defaults. +# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto + +# Default value for :pty is false +# set :pty, true + +# Default value for local_user is ENV['USER'] +# set :local_user, -> { `git config user.name`.chomp } + +# Uncomment the following to require manually verifying the host key before first deploy. +# set :ssh_options, verify_host_key: :secure + +before 'deploy:assets:precompile', 'hours:yarn_install' +namespace :hours do desc "Run rake yarn install" task :yarn_install do on roles(:web) do