From 133830b82c1838eaf3b1346e217a2f7b42b5c7b8 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 25 Sep 2024 12:13:28 -0500 Subject: [PATCH] Start solr with docker compose --- .env | 3 +++ Rakefile | 45 ++++++++++++++++++++++++++++++++++----------- compose.yaml | 17 +++++++++++++++++ 3 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 .env create mode 100644 compose.yaml diff --git a/.env b/.env new file mode 100644 index 00000000..994fa1d6 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +SOLR_PORT=8983 +SOLR_URL=http://solr:8983/solr/blacklight-core +SOLR_VERSION=latest diff --git a/Rakefile b/Rakefile index f21b58fe..22fd0c5d 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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 diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..ea302812 --- /dev/null +++ b/compose.yaml @@ -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"