diff --git a/.docker/app/Dockerfile b/.docker/app/Dockerfile new file mode 100644 index 000000000..fcca7d63c --- /dev/null +++ b/.docker/app/Dockerfile @@ -0,0 +1,31 @@ +ARG ALPINE_RUBY_VERSION + +FROM --platform=linux/amd64 ruby:${ALPINE_RUBY_VERSION}-bookworm + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update -qq && \ + apt-get install -y \ + bash \ + build-essential \ + git \ + libxml2-dev \ + libxslt-dev \ + nodejs \ + shared-mime-info \ + sqlite3 \ + tzdata \ + yarn + +RUN mkdir /app +WORKDIR /app + +RUN gem update --system && \ + gem install bundler && \ + bundle config build.nokogiri --use-system-libraries + +COPY . . + +EXPOSE 3000 + +CMD [".docker/app/entrypoint.sh"] diff --git a/.docker/app/entrypoint.sh b/.docker/app/entrypoint.sh new file mode 100755 index 000000000..a0095f95b --- /dev/null +++ b/.docker/app/entrypoint.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +rm -f /app/.internal_test_app/tmp/pids/server.pid +bundle install +bundle exec rails engine_cart:generate +bundle exec rails arclight:seed +bundle exec rake arclight:server["-p 3000 -b 0.0.0.0"] \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 000000000..2a64fc5fb --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +ALPINE_RUBY_VERSION=3.2.2 +RAILS_VERSION=7.1.2 +VIEW_COMPONENT_VERSION=3.8.0 +SOLR_PORT=8983 +SOLR_URL=http://solr:8983/solr/blacklight-core +SOLR_VERSION=latest diff --git a/README.md b/README.md index 83a8bc510..e74e6ef71 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ See the [CONTRIBUTORS](CONTRIBUTORS.md) file. ## Development -ArcLight requires Solr to be running. For development you can start this using `solr_wrapper` or you may choose to use Docker. Start Solr using Docker by doing `docker compose up`. +ArcLight requires Solr to be running. For development you can start this using `solr_wrapper` or you may choose to use Docker. Start Solr using Docker by doing `docker compose up solr`. ### Run the test suite @@ -105,7 +105,30 @@ Then visit http://localhost:3000. It will also start a Solr instance on port 898 You can also run `bin/console` for an interactive prompt that will allow you to experiment. -### Releasing +### Docker Development Environment + +**NOTE:** If you are on an M1/M2 mac, you will have to do the following first: + +```sh +$ export DOCKER_DEFAULT_PLATFORM=linux/amd64 +``` + +Another option for a local development environment is to use the included docker materials to spin up a local dockerized development instance. After cloning this repository, run the following command inside the project directory: + +```sh +$ docker compose up +``` + +or for a full rebuild and with containers running in the background: + +```sh +$ docker-compose -f docker-compose.yml up --build -d --force-recreate +``` + +Either should bring up a dockerized solr and arclight running at ports 8983 and 3000, with the seed data indexed. This uses a mount which allows you to make changes in your IDE/text editor of choice and see them reflected in the running app without a restart. + + +## Releasing #### To release a new gem: diff --git a/docker-compose.yml b/docker-compose.yml index 3d6d221cf..81d335aa3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,39 @@ version: "3.7" services: + app: + build: + context: . + dockerfile: .docker/app/Dockerfile + args: + - ALPINE_RUBY_VERSION + # mounting . is causing seg-fault on macosx + volumes: + - .:/app + depends_on: + - solr + env_file: + - .env + ports: + - "3000:3000" + environment: + - SOLR_URL # Set via environment variable or use default defined in .env file + - RAILS_VERSION # Set via environment variable or use default defined in .env file + - VIEW_COMPONENT_VERSION # Set via environment variable or use default defined in .env file + - SOLR_ENV=docker-compose + - ENGINE_CART_RAILS_OPTIONS=--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test --skip-solr + solr: - image: solr:latest + 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 + - ./solr/conf:/opt/solr/conf + env_file: + - .env ports: - - 8983:8983 + - "${SOLR_PORT}:8983" entrypoint: - docker-entrypoint.sh - solr-precreate diff --git a/tasks/arclight.rake b/tasks/arclight.rake index 7cc11d7a4..9652bf7ca 100644 --- a/tasks/arclight.rake +++ b/tasks/arclight.rake @@ -41,14 +41,33 @@ namespace :arclight do Rake::Task['engine_cart:generate'].invoke end - print 'Starting Solr...' - SolrWrapper.wrap do |solr| - puts 'done.' - solr.with_collection do - Rake::Task['arclight:seed'].invoke + if ENV['SOLR_ENV'] == 'docker-compose' + puts 'Using docker solr' + within_test_app do + system "bundle exec rails s #{args[:rails_server_args]}" + end + elsif system('docker-compose -v') + # We're not running docker-compose up but still want to use a docker instance of solr. + begin + puts 'Starting Solr' + system_with_error_handling 'docker-compose up -d solr' within_test_app do system "bundle exec rails s #{args[:rails_server_args]}" end + ensure + puts 'Stopping Solr' + system_with_error_handling 'docker-compose stop solr' + end + else + print 'Starting Solr...' + SolrWrapper.wrap do |solr| + puts 'done.' + solr.with_collection do + Rake::Task['arclight:seed'].invoke + within_test_app do + system "bundle exec rails s #{args[:rails_server_args]}" + end + end end end end @@ -59,13 +78,24 @@ namespace :arclight do Dir.glob('spec/fixtures/ead/*').each do |dir| next unless File.directory?(dir) - within_test_app do - # Sets the REPOSITORY_ID to the name of the file's containing directory - system("REPOSITORY_ID=#{File.basename(dir)} " \ - "REPOSITORY_FILE=#{Arclight::Engine.root}/spec/fixtures/config/repositories.yml " \ - "DIR=#{Arclight::Engine.root}/#{dir} " \ - 'SOLR_URL=http://127.0.0.1:8983/solr/blacklight-core ' \ - 'rake arclight:index_dir') + if (ENV['SOLR_ENV'] == 'docker-compose') || system('docker-compose -v') + within_test_app do + # Sets the REPOSITORY_ID to the name of the file's containing directory + system("REPOSITORY_ID=#{File.basename(dir)} " \ + "REPOSITORY_FILE=#{Arclight::Engine.root}/spec/fixtures/config/repositories.yml " \ + "DIR=#{Arclight::Engine.root}/#{dir} " \ + "SOLR_URL=#{ENV.fetch('SOLR_URL', nil)} " \ + 'rake arclight:index_dir') + end + else + within_test_app do + # Sets the REPOSITORY_ID to the name of the file's containing directory + system("REPOSITORY_ID=#{File.basename(dir)} " \ + "REPOSITORY_FILE=#{Arclight::Engine.root}/spec/fixtures/config/repositories.yml " \ + "DIR=#{Arclight::Engine.root}/#{dir} " \ + 'SOLR_URL=http://127.0.0.1:8983/solr/blacklight-core ' \ + 'rake arclight:index_dir') + end end end end