Skip to content

Commit 49599a2

Browse files
committed
Use docker-compose to run Solr in CI
Fixes #2195 Fixes #2231 Closes #2256 Supersedes #2256 In this way, we are using docker-compose for development and testing of the Blacklight gem itself, not for downstream purposes such as generation of new Blacklight applications, which will continue to use solr_wrapper.
1 parent d4e6247 commit 49599a2

File tree

7 files changed

+87
-65
lines changed

7 files changed

+87
-65
lines changed

.docker/app/Dockerfile

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
FROM ruby:2.6
2-
RUN \
3-
wget -qO- https://deb.nodesource.com/setup_9.x | bash - && \
4-
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
5-
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
6-
apt-get update -qq && \
7-
apt-get install -y --force-yes --no-install-recommends && \
8-
nodejs yarn build-essential libpq-dev \
9-
&& apt-get clean
10-
RUN gem install bundler
1+
ARG ALPINE_RUBY_VERSION
2+
3+
FROM ruby:${ALPINE_RUBY_VERSION}-alpine
4+
5+
RUN apk add --update --no-cache \
6+
bash \
7+
build-base \
8+
git \
9+
libxml2-dev \
10+
libxslt-dev \
11+
nodejs \
12+
sqlite-dev \
13+
tzdata
14+
1115
RUN mkdir /app
1216
WORKDIR /app
17+
18+
RUN gem update --system && \
19+
gem install bundler && \
20+
bundle config build.nokogiri --use-system-libraries
21+
22+
COPY . .
23+
24+
EXPOSE 3000
25+
26+
CMD [".docker/app/entrypoint.sh"]

.docker/app/entrypoint.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
rm -f /app/.internal_test_app/tmp/pids/server.pid
5+
bundle install
6+
exec bundle exec rake blacklight:server["-p 3000 -b 0.0.0.0"]

.env

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALPINE_RUBY_VERSION=2.6.5
2+
RAILS_VERSION=5.2.4.1
3+
SOLR_PORT=8983
4+
SOLR_URL=http://solr:8983/solr/blacklight-core
5+
SOLR_VERSION=latest

.travis.yml

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
dist: bionic
2+
23
addons:
34
chrome: stable
4-
language: ruby
55

6-
notifications:
7-
email: false
6+
language: ruby
87

98
matrix:
109
include:
@@ -25,26 +24,19 @@ matrix:
2524
fast_finish: true
2625

2726
before_install:
28-
- docker pull solr:7
29-
- docker run -d -p 8983:8983 -v $PWD/lib/generators/blacklight/templates/solr/conf:/myconfig solr:7 solr-create -c blacklight-core -d /myconfig
30-
- docker ps -a
3127
- google-chrome-stable --headless --disable-gpu --no-sandbox --remote-debugging-port=9222 http://localhost &
3228

33-
notifications:
34-
irc: "irc.freenode.org#blacklight"
35-
email:
36-
37-
38-
global_env:
39-
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
40-
- ENGINE_CART_RAILS_OPTIONS='--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
41-
- CC_TEST_REPORTER_ID=5042c7358c96b0b926088a4cda3e132fffe7a66ce8047cdb1dc6f0b4b6676b79
42-
43-
jdk: openjdk11
29+
env:
30+
global:
31+
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
32+
- ENGINE_CART_RAILS_OPTIONS='--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
33+
- CC_TEST_REPORTER_ID=5042c7358c96b0b926088a4cda3e132fffe7a66ce8047cdb1dc6f0b4b6676b79
4434

4535
before_script:
4636
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
4737
- chmod +x ./cc-test-reporter
4838
- ./cc-test-reporter before-build
39+
4940
after_script:
5041
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
42+
- docker-compose build app || travis_terminate 1 # validates application Dockerfile

bin/start.sh

-5
This file was deleted.

docker-compose.yml

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@ services:
55
build:
66
context: .
77
dockerfile: .docker/app/Dockerfile
8-
stdin_open: true
9-
tty: true
8+
args:
9+
- ALPINE_RUBY_VERSION
1010
volumes:
1111
- .:/app
1212
depends_on:
1313
- solr
1414
ports:
1515
- "3000:3000"
1616
environment:
17-
SOLR_URL: "http://solr:8983/solr/blacklight-core"
18-
DEVELOPMENT_ENVIRONMENT: "docker"
19-
entrypoint:
20-
- /app/bin/start.sh
17+
- SOLR_URL # Set via environment variable or use default defined in .env file
18+
- RAILS_VERSION # Set via environment variable or use default defined in .env file
2119

2220
solr:
23-
image: solr:7
21+
environment:
22+
- SOLR_PORT # Set via environment variable or use default defined in .env file
23+
- SOLR_VERSION # Set via environment variable or use default defined in .env file
24+
image: "solr:${SOLR_VERSION}"
2425
volumes:
2526
- $PWD/lib/generators/blacklight/templates/solr/conf:/opt/solr/conf
2627
ports:
27-
- "8983:8983"
28+
- "${SOLR_PORT}:8983"
2829
entrypoint:
2930
- docker-entrypoint.sh
3031
- solr-precreate

tasks/blacklight.rake

+34-25
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,26 @@ end
1010
require 'rubocop/rake_task'
1111
RuboCop::RakeTask.new(:rubocop)
1212

13+
def with_solr
14+
puts "Starting Solr"
15+
system "docker-compose up -d solr"
16+
yield
17+
ensure
18+
puts "Stopping Solr"
19+
system "docker-compose stop solr"
20+
end
21+
1322
desc "Run test suite"
14-
task ci: ['blacklight:generate'] do
15-
within_test_app do
16-
system "RAILS_ENV=test rake blacklight:index:seed"
23+
task :ci do
24+
with_solr do
25+
Rake::Task['engine_cart:generate'].invoke
26+
27+
within_test_app do
28+
system "RAILS_ENV=test bin/rake blacklight:index:seed"
29+
end
30+
31+
Rake::Task['blacklight:coverage'].invoke
1732
end
18-
Rake::Task['blacklight:coverage'].invoke
1933
end
2034

2135
namespace :blacklight do
@@ -25,40 +39,35 @@ namespace :blacklight do
2539
Rake::Task["spec"].invoke
2640
end
2741

28-
desc "Create the test rails app"
29-
task generate: ['engine_cart:generate'] do
30-
end
31-
3242
namespace :internal do
43+
desc 'Index seed data in test ap'
3344
task seed: ['engine_cart:generate'] do
3445
within_test_app do
35-
system "bundle exec rake blacklight:index:seed"
46+
system "bin/rake blacklight:index:seed"
3647
end
3748
end
3849
end
3950

4051
desc 'Run Solr and Blacklight for interactive development'
4152
task :server, [:rails_server_args] do |_t, args|
42-
if File.exist? EngineCart.destination
43-
within_test_app do
44-
system "bundle update"
45-
46-
if ENV["DEVELOPMENT_ENVIRONMENT"] == "docker"
47-
system "bundle exec rake blacklight:index:seed"
48-
system "bundle exec rails s #{args[:rails_server_args]}"
49-
next
53+
with_solr do
54+
if File.exist? EngineCart.destination
55+
within_test_app do
56+
system "bundle update"
5057
end
58+
else
59+
Rake::Task['engine_cart:generate'].invoke
5160
end
52-
else
53-
Rake::Task['engine_cart:generate'].invoke
54-
end
5561

56-
SolrWrapper.wrap do |solr|
57-
solr.with_collection do
58-
Rake::Task['blacklight:internal:seed'].invoke
62+
Rake::Task['blacklight:internal:seed'].invoke
5963

60-
within_test_app do
61-
system "bundle exec rails s #{args[:rails_server_args]}"
64+
within_test_app do
65+
begin
66+
puts "Starting Blacklight (Rails server)"
67+
system "bin/rails s #{args[:rails_server_args]}"
68+
rescue Interrupt
69+
# We expect folks to Ctrl-c to stop the server so don't barf at them
70+
puts "\nStopping Blacklight (Rails server)"
6271
end
6372
end
6473
end

0 commit comments

Comments
 (0)