Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to staging with capistrano #61

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'

require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

require 'capistrano/bundler'
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 }
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ gem 'railties'
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

group :development do
gem 'bcrypt_pbkdf'
gem 'capistrano', require: false
gem 'capistrano-bundler'
gem 'capistrano-passenger'
gem 'ed25519'
end

group :development, :test do
gem 'pry-byebug'
gem 'reek'
Expand Down
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
airbrussh (1.4.2)
sshkit (>= 1.6.1, != 1.7.0)
ast (2.4.2)
base64 (0.1.1)
bcrypt_pbkdf (1.1.0)
bootsnap (1.16.0)
msgpack (~> 1.2)
builder (3.2.4)
byebug (11.1.3)
capistrano (3.17.3)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (>= 1.9.0)
capistrano-bundler (2.1.0)
capistrano (~> 3.1)
capistrano-passenger (0.2.1)
capistrano (~> 3.0)
coderay (1.1.3)
concurrent-ruby (1.2.2)
crack (0.4.5)
Expand All @@ -45,6 +57,7 @@ GEM
debase-ruby_core_source (3.2.1)
diff-lcs (1.5.0)
dogstatsd-ruby (5.6.1)
ed25519 (1.3.0)
erubi (1.12.0)
ffi (1.15.5)
hashdiff (1.0.1)
Expand All @@ -67,6 +80,9 @@ GEM
method_source (1.0.0)
minitest (5.19.0)
msgpack (1.7.2)
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-ssh (7.2.0)
nio4r (2.5.9)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
Expand Down Expand Up @@ -160,6 +176,9 @@ GEM
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
sshkit (1.21.5)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
thor (1.2.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand All @@ -181,9 +200,14 @@ DEPENDENCIES
activemodel
activerecord
activesupport
bcrypt_pbkdf
bootsnap
capistrano
capistrano-bundler
capistrano-passenger
ddtrace
dogstatsd-ruby
ed25519
pg
pry-byebug
puma (~> 5.0)
Expand Down
12 changes: 4 additions & 8 deletions app/models/concerns/solr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module Solr
def solr_service_response(query_terms:)
query = "q=#{query_terms}&rows=3&facet=false&fl=#{solr_fields.join(',')}&sort=#{solr_sort}"
query = "#{query}&#{extra_solr_params}" if respond_to? :extra_solr_params
uri = url_builder.build(host: solr_config[:host],
port: solr_config[:port],
path: "/solr/#{solr_collection}/select",
query:)
uri = URI::HTTP.build(host: solr_config[:host],
port: solr_config[:port],
path: "/solr/#{solr_collection}/select",
query:)
response = Net::HTTP.get(uri)
JSON.parse(response, symbolize_names: true)
end
Expand All @@ -33,10 +33,6 @@ def url(document:)

private

def url_builder
solr_config[:ssl] ? URI::HTTPS : URI::HTTP
end

def solr_collection
Rails.application.config_for(:allsearch)[service][:solr][:collection]
end
Expand Down
23 changes: 15 additions & 8 deletions config/allsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ default: &default
host: "lib-solr8-prod.princeton.edu"
port: 8983
collection: "catalog-alma-production"
ssl: true
dpul:
solr:
host: "lib-solr8-prod.princeton.edu"
port: 8983
collection: "dpul-production"
ssl: true
findingaids:
solr:
host: "lib-solr8-prod.princeton.edu"
port: 8983
collection: "pulfalight-production"
ssl: true
pulmap:
solr:
host: "lib-solr8-prod.princeton.edu"
port: 8983
collection: "pulmap"
ssl: true

development:
<<: *default
Expand All @@ -31,31 +27,42 @@ development:
host: <%= ENV["lando_catalog_solr_conn_host"] %>
port: <%= ENV["lando_catalog_solr_conn_port"] %>
collection: "catalog"
ssl: false

dpul:
solr:
host: <%= ENV["lando_dpul_solr_conn_host"] %>
port: <%= ENV["lando_dpul_solr_conn_port"] %>
collection: "dpul"
ssl: false

findingaids:
solr:
host: <%= ENV["lando_findingaids_solr_conn_host"] %>
port: <%= ENV["lando_findingaids_solr_conn_port"] %>
collection: "findingaids"
ssl: false

pulmap:
solr:
host: <%= ENV["lando_pulmap_solr_conn_host"] %>
port: <%= ENV["lando_pulmap_solr_conn_port"] %>
collection: "pulmap"
ssl: false

staging:
<<: *default
catalog:
solr:
host: "lib-solr8-staging.princeton.edu"
port: 8983
collection: "catalog-alma-staging"
dpul:
solr:
host: "lib-solr8-staging.princeton.edu"
port: 8983
collection: "dpul-staging"
findingaids:
solr:
host: "lib-solr8-staging.princeton.edu"
port: 8983
collection: "pulfalight-staging"

test:
<<: *default
Expand Down
15 changes: 15 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

set :repo_url, 'https://github.com/pulibrary/allsearch_rails_api.git'
set :application, 'allsearch_rails_api'

set :branch, ENV['BRANCH'] || 'main'

set :deploy_to, -> { "/opt/#{fetch(:application)}" }
set :repo_path, -> { "/opt/#{fetch(:application)}/repo" }

set :log_level, :debug

set :ssh_options, { forward_agent: true }

set :passenger_restart_with_touch, true
5 changes: 5 additions & 0 deletions config/deploy/production.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

set :stage, :production
set :rails_env, 'production'
server 'allsearch-api-prod1', user: 'deploy'
5 changes: 5 additions & 0 deletions config/deploy/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

set :stage, :staging
set :rails_env, 'staging'
server 'allsearch-api-staging1', user: 'deploy'
46 changes: 46 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

require 'active_support/core_ext/integer/time'

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

# Include generic and useful information about system operation, but avoid logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII).
config.log_level = :info

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true

# Don't log any deprecations.
config.active_support.report_deprecations = false

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = Logger::Formatter.new

if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
end
10 changes: 5 additions & 5 deletions spec/requests/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe 'GET /search/catalog' do
it 'returns json' do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=rubix&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=rubix&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
.to_return(status: 200, body: file_fixture('solr/catalog/rubix.json'))
get '/search/catalog?query=rubix'

Expand All @@ -14,7 +14,7 @@

context 'with a search term' do
before do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=rubix&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=rubix&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
.to_return(status: 200, body: file_fixture('solr/catalog/rubix.json'))
end

Expand Down Expand Up @@ -67,7 +67,7 @@

context 'without a publisher in records' do
before do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=pangulubalang&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=pangulubalang&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
.to_return(status: 200, body: file_fixture('solr/catalog/pangulubalang.json'))
end

Expand All @@ -87,7 +87,7 @@

context 'with weird search strings' do
before do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=What%20if%20%22I%20quote%22%20my%20search?&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=What%20if%20%22I%20quote%22%20my%20search?&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
.to_return(status: 200, body: file_fixture('solr/catalog/what_if.json'))
end

Expand All @@ -103,7 +103,7 @@

context 'with CJK characters' do
before do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=%E8%A7%A6%E7%89%A9%E7%94%9F%E6%83%85%E8%AF%9D%E9%81%93%E5%8D%97&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/catalog-alma-production/select?facet=false&fl=id,title_display,author_display,pub_created_display,format,holdings_1display&q=%E8%A7%A6%E7%89%A9%E7%94%9F%E6%83%85%E8%AF%9D%E9%81%93%E5%8D%97&rows=3&sort=score%20desc,%20pub_date_start_sort%20desc,%20title_sort%20asc')
.to_return(status: 200, body: file_fixture('solr/catalog/触物生情话道南.json'))
end

Expand Down
4 changes: 2 additions & 2 deletions spec/requests/dpul_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe 'GET /search/dpul' do
it 'returns json' do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/dpul-production/select?facet=false&fl=id,readonly_title_ssim,readonly_creator_ssim,readonly_publisher_ssim,readonly_format_ssim,readonly_collections_tesim&q=cats&rows=3&sort=score%20desc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/dpul-production/select?facet=false&fl=id,readonly_title_ssim,readonly_creator_ssim,readonly_publisher_ssim,readonly_format_ssim,readonly_collections_tesim&q=cats&rows=3&sort=score%20desc')
.to_return(status: 200, body: file_fixture('solr/dpul/cats.json'))
get '/search/dpul?query=cats'

Expand All @@ -14,7 +14,7 @@

context 'with a search term' do
before do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/dpul-production/select?facet=false&fl=id,readonly_title_ssim,readonly_creator_ssim,readonly_publisher_ssim,readonly_format_ssim,readonly_collections_tesim&q=cats&rows=3&sort=score%20desc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/dpul-production/select?facet=false&fl=id,readonly_title_ssim,readonly_creator_ssim,readonly_publisher_ssim,readonly_format_ssim,readonly_collections_tesim&q=cats&rows=3&sort=score%20desc')
.to_return(status: 200, body: file_fixture('solr/dpul/cats.json'))
end

Expand Down
4 changes: 2 additions & 2 deletions spec/requests/findingaids_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe 'GET /search/findingaids' do
it 'returns json' do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/pulfalight-production/select?facet=false&fl=id,collection_ssm,creator_ssm,level_sim,scopecontent_ssm,repository_ssm,extent_ssm,accessrestrict_ssm&q=cats&rows=3&sort=score%20desc,%20title_sort%20asc&fq=level_sim:Collection')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/pulfalight-production/select?facet=false&fl=id,collection_ssm,creator_ssm,level_sim,scopecontent_ssm,repository_ssm,extent_ssm,accessrestrict_ssm&q=cats&rows=3&sort=score%20desc,%20title_sort%20asc&fq=level_sim:Collection')
.to_return(status: 200, body: file_fixture('solr/findingaids/cats.json'))
get '/search/findingaids?query=cats'

Expand All @@ -14,7 +14,7 @@

context 'with a search term' do
before do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/pulfalight-production/select?facet=false&fl=id,collection_ssm,creator_ssm,level_sim,scopecontent_ssm,repository_ssm,extent_ssm,accessrestrict_ssm&q=cats&rows=3&sort=score%20desc,%20title_sort%20asc&fq=level_sim:Collection')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/pulfalight-production/select?facet=false&fl=id,collection_ssm,creator_ssm,level_sim,scopecontent_ssm,repository_ssm,extent_ssm,accessrestrict_ssm&q=cats&rows=3&sort=score%20desc,%20title_sort%20asc&fq=level_sim:Collection')
.to_return(status: 200, body: file_fixture('solr/findingaids/cats.json'))
end

Expand Down
4 changes: 2 additions & 2 deletions spec/requests/pulmap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe 'GET /search/pulmap' do
it 'returns json' do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/pulmap/select?facet=false&fl=uuid,dc_title_s,dc_creator_sm,dc_publisher_s,dc_format_s,dc_description_s,dc_rights_s,layer_geom_type_s&q=scribner&rows=3&sort=score%20desc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/pulmap/select?facet=false&fl=uuid,dc_title_s,dc_creator_sm,dc_publisher_s,dc_format_s,dc_description_s,dc_rights_s,layer_geom_type_s&q=scribner&rows=3&sort=score%20desc')
.to_return(status: 200, body: file_fixture('solr/pulmap/scribner.json'))
get '/search/pulmap?query=scribner'

Expand All @@ -14,7 +14,7 @@

context 'with a search term' do
before do
stub_request(:get, 'https://lib-solr8-prod.princeton.edu:8983/solr/pulmap/select?facet=false&fl=uuid,dc_title_s,dc_creator_sm,dc_publisher_s,dc_format_s,dc_description_s,dc_rights_s,layer_geom_type_s&q=scribner&rows=3&sort=score%20desc')
stub_request(:get, 'http://lib-solr8-prod.princeton.edu:8983/solr/pulmap/select?facet=false&fl=uuid,dc_title_s,dc_creator_sm,dc_publisher_s,dc_format_s,dc_description_s,dc_rights_s,layer_geom_type_s&q=scribner&rows=3&sort=score%20desc')
.to_return(status: 200, body: file_fixture('solr/pulmap/scribner.json'))
end

Expand Down