From 4fe34902a584ac395075323bdb10190ee0f87c94 Mon Sep 17 00:00:00 2001 From: David Chandek-Stark Date: Fri, 4 Feb 2022 16:32:45 -0500 Subject: [PATCH] WIP --- .dockerignore | 7 ++ .gitignore | 1 + Dockerfile | 16 ++++ db/config.yml | 4 +- dev.sh | 7 ++ docker-compose.yml | 83 +++++++++++++++++++ spec/spec_helper.rb | 6 +- spec/support/fedora_helper.rb | 17 ++-- .../persistence/solr/persister_spec.rb | 4 +- 9 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 dev.sh create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..7e2bed8ab --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +Dockerfile +docker-compose.yml +.bundle +.circleci +.ctags +.dockerignore +.lando.yml diff --git a/.gitignore b/.gitignore index 3bd902c5c..4f05b7782 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.bash_history /.bundle/ /.yardoc /Gemfile.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..24cb7f68b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +ARG ruby_version=2.6 +FROM ruby:${ruby_version} + +SHELL ["/bin/bash", "-c"] + +WORKDIR /opt/valkyrie + +COPY . . + +RUN chmod -R 0777 . + +USER 1001:0 + +ENV HOME=/opt/valkyrie + +RUN gem install bundler && bundle install diff --git a/db/config.yml b/db/config.yml index 0d4222633..03f31014d 100644 --- a/db/config.yml +++ b/db/config.yml @@ -7,12 +7,12 @@ default: &default timeout: 5000 host: localhost username: postgres - password: + password: development: <<: *default database: Valkyrie_gem_development - port: 5433 + url: <%= ENV['DATABASE_URL'] %> test: <<: *default diff --git a/dev.sh b/dev.sh new file mode 100755 index 000000000..53ee56756 --- /dev/null +++ b/dev.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker-compose up -d + +docker-compose exec valkyrie /bin/bash + +docker-compose down diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..ac41aca42 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,83 @@ +version: '3.8' + +services: + valkyrie: + image: valkyrie + build: + context: . + volumes: + - .:/opt/valkyrie + environment: + - SOLR_URL=http://solr:8983/solr/valkyrie-core-test + - DATABASE_URL=postgresql://postgres:valkyrie@db:5432/Valkyrie_gem_development + - DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true + - RAILS_ENV=development + - RACK_ENV=development + - FEDORA_4_PORT=8080 + - FEDORA_4_HOST=fcrepo4 + - FEDORA_5_PORT=8080 + - FEDORA_5_HOST=fcrepo5 + - FEDORA_6_PORT=8080 + - FEDORA_6_HOST=fcrepo6 + command: + - sleep + - infinity + + solr: + image: solr:7 + ports: + - "8994:8983" + volumes: + - ./solr/config:/solr_config + - solr:/opt/solr/server/solr/mycores + entrypoint: + - docker-entrypoint.sh + - solr-precreate + - valkyrie-core-test + - /solr_config + + db: + image: postgres:10 + volumes: + - pgdata:/var/lib/postgresql/data + environment: + - POSTGRES_DB=Valkyrie_gem_development + - POSTGRES_PASSWORD=valkyrie + + fcrepo4: + image: samvera/fcrepo4:4.7.5 + command: + - /fedora-entrypoint.sh + volumes: + - fcrepo4:/data + ports: + - "8988:8080" + + fcrepo5: + image: samvera/fcrepo4:5.1.0 + command: + - /fedora-entrypoint.sh + volumes: + - fcrepo5:/data + ports: + - "8998:8080" + + fcrepo6: + image: fcrepo/fcrepo:6.0.0 + command: + - "catalina.sh" + - "run" + volumes: + - fcrepo6:/data + ports: + - "8978:8080" + environment: + CATALINA_OPTS: "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true" + JAVA_OPTS: "-Dfcrepo.dynamic.jms.port=61619 -Dfcrepo.dynamic.stomp.port=61615 -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true" + +volumes: + fcrepo4: + fcrepo5: + fcrepo6: + solr: + pgdata: diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aa1f13696..4f8f6af3e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,12 +16,14 @@ require 'webmock/rspec' require 'timecop' -SOLR_TEST_URL = "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8994}/solr/valkyrie-core-test" +SOLR_TEST_URL = ENV['SOLR_URL'] || "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8994}/solr/valkyrie-core-test" ROOT_PATH = Pathname.new(Dir.pwd) Dir[Pathname.new("./").join("spec", "support", "**", "*.rb")].sort.each { |file| require_relative file.gsub(/^spec\//, "") } -WebMock.disable_net_connect!(allow_localhost: true) +# TODO - replace solr and fcrepo hosts with vars +# WebMock.disable_net_connect!(allow: ['localhost', 'solr:8983', 'fcrepo4:8080', 'fcrepo5:8080', 'fcrepo6:8080']) +WebMock.allow_net_connect! RSpec.configure do |config| config.order = :random diff --git a/spec/support/fedora_helper.rb b/spec/support/fedora_helper.rb index e6c1abd66..1beaec1c3 100644 --- a/spec/support/fedora_helper.rb +++ b/spec/support/fedora_helper.rb @@ -1,16 +1,23 @@ # frozen_string_literal: true module FedoraHelper def fedora_adapter_config(base_path:, schema: nil, fedora_version: 4) - port = 8988 - if fedora_version == 5 - port = 8998 - elsif fedora_version == 6 + host = 'localhost' + + case fedora_version + when 4 + port = ENV["FEDORA_4_PORT"] || 8988 + host = ENV["FEDORA_4_HOST"] if ENV["FEDORA_4_HOST"].present? + when 5 + port = ENV["FEDORA_5_PORT"] || 8998 + host = ENV["FEDORA_5_HOST"] if ENV["FEDORA_5_HOST"].present? + when 6 port = ENV["FEDORA_6_PORT"] || 8978 + host = ENV["FEDORA_6_HOST"] if ENV["FEDORA_6_HOST"].present? end connection_url = fedora_version == 6 ? "/fcrepo/rest" : "/rest" opts = { base_path: base_path, - connection: ::Ldp::Client.new(faraday_client("http://#{fedora_auth}localhost:#{port}#{connection_url}")), + connection: ::Ldp::Client.new(faraday_client("http://#{fedora_auth}#{host}:#{port}#{connection_url}")), fedora_version: fedora_version } opts[:schema] = schema if schema diff --git a/spec/valkyrie/persistence/solr/persister_spec.rb b/spec/valkyrie/persistence/solr/persister_spec.rb index 461367c1c..a9372c067 100644 --- a/spec/valkyrie/persistence/solr/persister_spec.rb +++ b/spec/valkyrie/persistence/solr/persister_spec.rb @@ -101,11 +101,11 @@ class MyLockingResource < Valkyrie::Resource context "when solr does not return a response" do before do - WebMock.disable_net_connect! + # WebMock.disable_net_connect! stub_request(:post, "#{SOLR_TEST_URL}/update?softCommit=true&versions=true&wt=json").to_raise(RSolr::Error::Http.new(nil, nil)) end after do - WebMock.disable_net_connect!(allow_localhost: true) + # WebMock.disable_net_connect!(allow_localhost: true) end it "passes the exception through" do resource = MyLockingResource.new(title: ["My Locked Resource"])