Skip to content

Commit

Permalink
Backport: Prefer docker for starting solr; support Solr 9.8
Browse files Browse the repository at this point in the history
  • Loading branch information
corylown committed Jan 24, 2025
1 parent da2ae8c commit b8aad03
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ RAILS_QUEUE=inline
SOLR_VERSION=latest
SOLR_HOST=solr
SOLR_PORT=8983
SOLR_MODULES=analysis-extras
53 changes: 45 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ end
Bundler::GemHelper.install_tasks

require 'solr_wrapper'
require 'open3'

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
Expand All @@ -30,16 +31,52 @@ require 'engine_cart/rake_task'

require 'spotlight/version'

task ci: ['engine_cart:generate'] do
ENV['environment'] = 'test'
# Build with our opinionated defaults if none are provided.
rails_options = ENV.fetch('ENGINE_CART_RAILS_OPTIONS', '')
rails_options = "#{rails_options} -a propshaft" unless rails_options.match?(/-a\s|--asset-pipeline/)
rails_options = "#{rails_options} -j importmap" unless rails_options.match?(/-j\s|--javascript/)
rails_options = "#{rails_options} --css bootstrap" unless rails_options.match?(/--css/)
ENV['ENGINE_CART_RAILS_OPTIONS'] = rails_options

def system_with_error_handling(*args)
Open3.popen3(*args) do |_stdin, stdout, stderr, thread|
puts stdout.read
raise "Unable to run #{args.inspect}: #{stderr.read}" unless thread.value.success?
end
end

SolrWrapper.wrap(port: '8983') do |solr|
solr.with_collection(name: 'blacklight-core', dir: 'lib/generators/spotlight/templates/solr/conf') do
Rake::Task['spotlight:fixtures'].invoke
def with_solr(&block) # rubocop:disable Metrics/MethodLength
# We're being invoked by the app entrypoint script and solr is already up via docker compose
if ENV['SOLR_ENV'] == 'docker-compose'
yield
elsif system('docker compose version')
# We're not running `docker compose up' but still want to use a docker instance of solr.
begin
puts 'Starting Solr'
system_with_error_handling 'docker compose up -d solr'
yield
ensure
puts 'Stopping Solr'
system_with_error_handling 'docker compose stop solr'
end
else
SolrWrapper.wrap do |solr|
solr.with_collection(&block)
end
end
end

task :ci do
ENV['environment'] = 'test'

# run the tests
Rake::Task['spec'].invoke
with_solr do
Rake::Task['spotlight:fixtures'].invoke
within_test_app do
system 'bin/rake spec:prepare'
end

# run the tests
Rake::Task['spec'].invoke
end
end

Expand All @@ -63,7 +100,7 @@ namespace :spotlight do
system 'bin/rails spotlight:initialize spotlight_test:solr:seed'
File.open('.initialized', 'w') {}
end
system 'bin/rails s'
system 'bin/dev'
end
end
end
Expand Down
1 change: 1 addition & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ services:
environment:
- SOLR_PORT # Set via environment variable or use default defined in .env file
- SOLR_VERSION # Set via environment variable or use default defined in .env file
- SOLR_MODULES # Set via environment variable or use default defined in .env file
image: "solr:${SOLR_VERSION}"
volumes:
- $PWD/lib/generators/spotlight/templates/solr/conf:/opt/solr/conf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</updateLog>
</updateHandler>

<!-- solr lib dirs -->
<!-- solr lib dirs: needed for Solr 8 compatibility but ignored in solr 9.8 and above -->
<lib dir="${solr.install.dir:../../../..}/modules/analysis-extras/lib" />
<lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lib" />
<lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lucene-libs" />
Expand Down

0 comments on commit b8aad03

Please sign in to comment.