Skip to content

Commit

Permalink
Start solr with docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 25, 2024
1 parent 2f34f9f commit 133830b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SOLR_PORT=8983
SOLR_URL=http://solr:8983/solr/blacklight-core
SOLR_VERSION=latest
45 changes: 34 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,46 @@ Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
require 'engine_cart/rake_task'
require 'solr_wrapper'
require 'open3'

task :default => :ci

desc "Run specs"
RSpec::Core::RakeTask.new

task ci: ['engine_cart:generate'] do
SolrWrapper.wrap do |solr|
solr.with_collection(name: 'blacklight-core', dir: File.join(File.expand_path(File.dirname(__FILE__)), "solr", "conf")) do
Rake::Task["test:seed"].invoke
Rake::Task['spec'].invoke
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

def with_solr
if system('docker compose -v')
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 do
yield
end
end
end
end

task :ci do
with_solr do
Rake::Task["test:seed"].invoke
Rake::Task['spec'].invoke
end
end

namespace :test do
desc "Put sample data into solr"
task seed: ['engine_cart:generate'] do
Expand All @@ -40,13 +65,11 @@ namespace :test do
Rake::Task['engine_cart:generate'].invoke
end

SolrWrapper.wrap(port: '8983') do |solr|
solr.with_collection(name: 'blacklight-core', dir: File.join(File.expand_path(File.dirname(__FILE__)), "solr", "conf")) do
Rake::Task['test:seed'].invoke
with_solr do
Rake::Task['test:seed'].invoke

within_test_app do
system "bundle exec rails s #{args[:rails_server_args]}"
end
within_test_app do
system "bundle exec rails s #{args[:rails_server_args]}"
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
solr:
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
image: "solr:${SOLR_VERSION}"
volumes:
- $PWD/solr/conf:/opt/solr/conf
ports:
- "${SOLR_PORT}:8983"
entrypoint:
- docker-entrypoint.sh
- solr-precreate
- blacklight-core
- /opt/solr/conf
- "-Xms256m"
- "-Xmx512m"

0 comments on commit 133830b

Please sign in to comment.