Skip to content

Commit

Permalink
Merge pull request #258 from samvera/docker-tests
Browse files Browse the repository at this point in the history
Add Dockerfile and docker-compose for running tests, issues #256 #195
  • Loading branch information
stkenny authored Oct 12, 2023
2 parents d573fb4 + 0a7ae67 commit 7a01086
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ARG RUBY_VERSION=3.2.2

FROM rubylang/ruby:$RUBY_VERSION-dev-jammy

RUN apt update && apt -y install \
imagemagick \
zip \
ghostscript \
libpng-dev \
graphicsmagick \
ffmpeg \
libreoffice \
git \
dcraw \
libyaml-dev

RUN mkdir -p /opt/kakadu/downloads
RUN wget http://kakadusoftware.com/wp-content/uploads/KDU805_Demo_Apps_for_Linux-x86-64_200602.zip -O /opt/kakadu/downloads/kakadu.zip \
&& unzip /opt/kakadu/downloads/kakadu.zip \
&& mv KDU805_Demo_Apps_for_Linux-x86-64_200602 kakadu \
&& cp kakadu/*.so /usr/lib \
&& cp kakadu/* /usr/bin

RUN sed -i 's/policy domain="coder" rights="none" pattern="PDF"/policy domain="coder" rights="read|write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml
RUN sed -i 's/decode="dng:decode" command=".*"\/>$/decode="dng:decode" command="\&quot\;dcraw\&quot\; -c -q 3 -H 5 -w \&quot\;\%i\&quot\; \| \&quot\;convert\&quot\; - \&quot\;\%u\.png\&quot\;"\/>/' /etc/ImageMagick-6/delegates.xml

RUN addgroup --system --gid 1001 app && \
adduser --system --ingroup app --uid 1001 --shell /bin/sh --home /app app

RUN mkdir -p /app/samvera/hydra-derviatives
WORKDIR /app/samvera/hydra-derivatives
COPY ./ /app/samvera/hydra-derivatives
RUN gem install bundler && bundle install --jobs=3 --retry=3
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,32 @@ If you don't want to run the whole suite all at once like CI, do the following:
1. Run the test servers with `rake derivatives:test_server`
2. Run the tests.

## Running tests with Docker

First, make sure you have installed [Docker](https://www.docker.com/).

Within your cloned repository, tell Docker to get started installing your development environment:

```sh
docker compose build
docker compose up
```

This starts containers for:

- Fedora
- Solr

It also builds an image containing all dependencies needed for the tests.

To stop the containers, type <kbd>Ctrl</kbd>+<kbd>c</kbd>. To restart the containers you need only run `docker compose up`.

You can run the full test suite using the following command:

```sh
docker compose run -w /app/samvera/hydra-derivatives test sh -c "bundle exec rspec"
```

# Acknowledgments

This software has been developed by and is brought to you by the Samvera community. Learn more at the
Expand Down
46 changes: 46 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: '2.2'

volumes:
solr:
fcrepo:

networks:
internal:

services:

solr:
image: solr:8
ports:
- 8985:8983
command:
- bash
- "-c"
- "precreate-core hydra-test /opt/solr/server/configsets/hydra-test; exec solr -f"
volumes:
- .:/app
- ./solr/config:/opt/solr/server/configsets/hydra-test
- solr:/opt/solr/server/solr
networks:
internal:

fcrepo:
image: ghcr.io/samvera/fcrepo4:4.7.5
volumes:
- fcrepo:/data:cached
ports:
- 8986:8080
networks:
internal:

test:
build: .
env_file:
- test.env
volumes:
- .:/app/samvera/hydra-derivatives # Volume mounted
networks:
internal:
depends_on:
- fcrepo
- solr
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ActiveFedora::Cleaner.clean!
end
end
ActiveFedora.init(fedora_config_path: ENV['FCREPO_CONFIG_PATH']) if ENV['FCREPO_CONFIG_PATH']

# Workaround for RAW image support until these are pushed upstream to
# the MIME Types gem
Expand Down
15 changes: 15 additions & 0 deletions spec/support/config/fedora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
development:
user: fedoraAdmin
password: fedoraAdmin
url: http://<%= ENV['FCREPO_HOST'] || 'localhost' %>:<%= ENV['FCREPO_DEVELOPMENT_PORT'] || ENV['FCREPO_PORT'] || 8984 %>/<%= ENV['FCREPO_REST_PATH'] || 'rest' %>
base_path: <%= ENV['FCREPO_DEV_BASE_PATH'] || ENV['FCREPO_BASE_PATH'] || '/dev' %>
test:
user: fedoraAdmin
password: fedoraAdmin
url: http://<%= ENV['FCREPO_HOST'] || 'localhost' %>:<%= ENV['FCREPO_DEVELOPMENT_PORT'] || ENV['FCREPO_PORT'] || 8986 %>/<%= ENV['FCREPO_REST_PATH'] || 'rest' %>
base_path: <%= ENV['FCREPO_TEST_BASE_PATH'] || ENV['FCREPO_BASE_PATH'] || '/test' %>
production:
user: fedoraAdmin
password: fedoraAdmin
url: http://<%= ENV['FCREPO_HOST'] || 'localhost' %>:<%= ENV['FCREPO_DEVELOPMENT_PORT'] || ENV['FCREPO_PORT'] || 8983 %>/<%= ENV['FCREPO_REST_PATH'] || 'rest' %>
base_path: <%= ENV['FCREPO_BASE_PATH'] || '/prod' %>
7 changes: 7 additions & 0 deletions spec/support/config/solr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This is a sample config file that points to a solr server for each environment
development:
url: <%= ENV['SOLR_DEVELOPMENT_URL'] || ENV['SOLR_URL'] || "http://127.0.0.1:#{ENV.fetch('SOLR_DEVELOPMENT_PORT', 8983)}/solr/hydra-development" %>
test:
url: <%= ENV['SOLR_TEST_URL'] || ENV['SOLR_URL'] || "http://127.0.0.1:#{ENV.fetch('SOLR_TEST_PORT', 8985)}/solr/hydra-test" %>
production:
url: <%= ENV['SOLR_URL'] || "http://your.production.server:8080/bl_solr/core0" %>
9 changes: 9 additions & 0 deletions test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FCREPO_HOST=fcrepo
FCREPO_PORT=8080
FCREPO_REST_PATH=rest
FCREPO_TEST_BASE_PATH=/test
SOLR_HOST=solr
SOLR_PORT=8983
SOLR_TEST_URL=http://solr:8983/solr/hydra-test
SOLR_URL=http://solr:8983/solr/
FCREPO_CONFIG_PATH=spec/support/config/fedora.yml

0 comments on commit 7a01086

Please sign in to comment.