diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ac75a6c..60808116 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,6 +10,11 @@ jobs: RAILS_ENV: test PULMAP_DB_HOST: localhost PULMAP_DB_USERNAME: geoblacklight + - image: postgres:10.6-alpine + environment: + POSTGRES_USER: geoblacklight + POSTGRES_DB: pulmap_test + POSTGRES_HOST_AUTH_METHOD: trust steps: - checkout # Restore Cached Dependencies @@ -65,8 +70,13 @@ jobs: RAILS_ENV: test PULMAP_DB_HOST: localhost PULMAP_DB_USERNAME: geoblacklight + - image: postgres:10.6-alpine + environment: + POSTGRES_USER: geoblacklight + POSTGRES_DB: pulmap_test + POSTGRES_HOST_AUTH_METHOD: trust - image: solr:7.7-alpine - command: bin/solr -cloud -noprompt -f -p 8985 + command: bin/solr -cloud -noprompt -f -p 8984 steps: &test_steps - attach_workspace: at: '~/pulmap' @@ -93,8 +103,8 @@ jobs: command: | cd solr/conf zip -1 -r solr_config.zip ./* - curl -H "Content-type:application/octet-stream" --data-binary @solr_config.zip "http://localhost:8985/solr/admin/configs?action=UPLOAD&name=pulmap" - curl -H 'Content-type: application/json' http://localhost:8985/api/collections/ -d '{create: {name: pulmap-core-test, config: pulmap, numShards: 1}}' + curl -H "Content-type:application/octet-stream" --data-binary @solr_config.zip "http://localhost:8984/solr/admin/configs?action=UPLOAD&name=pulmap" + curl -H 'Content-type: application/json' http://localhost:8984/api/collections/ -d '{create: {name: pulmap-core-test, config: pulmap, numShards: 1}}' - run: bundle exec rake db:migrate - run: bundle exec rake geoblacklight:solr:seed - run: bundle exec rspec spec/ diff --git a/.lando.yml b/.lando.yml new file mode 100644 index 00000000..841c04ba --- /dev/null +++ b/.lando.yml @@ -0,0 +1,22 @@ +name: pulmap +services: + pulmap_test_solr: + type: solr:8.4 + portforward: true + core: pulmap-core-test + config: + dir: "solr/conf" + pulmap_development_solr: + type: solr:8.4 + portforward: true + core: pulmap-core-dev + config: + dir: "solr/conf" + pulmap_database: + type: postgres:10 + portforward: true +proxy: + pulmap_test_solr: + - pulmap.test.solr.lndo.site:8983 + pulmap_development_solr: + - pulmap.dev.solr.lndo.site:8983 diff --git a/Gemfile b/Gemfile index 8a7610fa..c1e0d71e 100644 --- a/Gemfile +++ b/Gemfile @@ -61,7 +61,6 @@ gem 'sidekiq' gem 'simple_form' gem 'sitemap_generator', '~> 6.0' gem 'sneakers' -gem 'solr_wrapper' gem 'twitter-typeahead-rails' gem 'webpacker' gem 'whenever' diff --git a/Gemfile.lock b/Gemfile.lock index 40d568c9..a831b388 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -510,11 +510,6 @@ GEM rake (~> 12.3) serverengine (~> 2.1.0) thor - solr_wrapper (2.2.0) - faraday - retriable - ruby-progressbar - rubyzip spring (2.1.1) sprockets (3.7.2) concurrent-ruby (~> 1.0) @@ -624,7 +619,6 @@ DEPENDENCIES simple_form sitemap_generator (~> 6.0) sneakers - solr_wrapper spring sqlite3 turbolinks diff --git a/README.md b/README.md index 2d3f61b6..02bf0d50 100644 --- a/README.md +++ b/README.md @@ -6,23 +6,24 @@ GeoBlacklight for Princeton University Library [![CircleCI](https://circleci.com/gh/pulibrary/pulmap.svg?style=svg)](https://circleci.com/gh/pulibrary/pulmap) [![Coverage Status](https://coveralls.io/repos/pulibrary/pulmap/badge.svg?branch=master&service=github)](https://coveralls.io/github/pulibrary/pulmap?branch=master) -### Installation -``` -bundle -rake db:migrate -npm install --global yarn -yarn +### Initial Setup +```sh +git clone https://github.com/pulibrary/pulmap.git +cd pulmap +bundle install +yarn install ``` ### Setup server +1. Install Lando DMG from https://github.com/lando/lando/releases +1. To start: `rake pulmap:server:start` 1. For test: - - `rake pulmap:test` - - In a separate terminal: `bundle exec rspec` -2. For development: - - `rake pulmap:development` - - In a separate terminal: `rails s` + - `bundle exec rspec` +1. For development: + - `rails s` - Access Pulmap at http://localhost:3000/ +1. To stop: `rake pulmap:server:stop` or `lando stop` ### Auto-update from external services diff --git a/Rakefile b/Rakefile index 24f5d436..9ae0996b 100644 --- a/Rakefile +++ b/Rakefile @@ -6,8 +6,6 @@ require "rubocop/rake_task" if Rails.env.development? || Rails.env.test? Rails.application.load_tasks -require 'solr_wrapper/rake_task' if Rails.env.development? || Rails.env.test? - if defined? RuboCop desc "Run RuboCop style checker" RuboCop::RakeTask.new(:rubocop) do |task| diff --git a/config/application.rb b/config/application.rb index 0c603865..d9569d3b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -3,6 +3,7 @@ require File.expand_path('../boot', __FILE__) require 'rails/all' +require_relative 'lando_env' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/config/blacklight.yml b/config/blacklight.yml index 926c90a6..21e4b39c 100644 --- a/config/blacklight.yml +++ b/config/blacklight.yml @@ -1,9 +1,9 @@ development: adapter: solr - url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr/pulmap-core-dev" %> + url: <%= ENV['SOLR_URL'] || "http://#{ENV["lando_pulmap_development_solr_conn_host"] || "127.0.0.1"}:#{ENV["lando_pulmap_development_solr_conn_port"] || 8983}/solr/pulmap-core-dev" %> test: &test adapter: solr - url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8985}/solr/pulmap-core-test" %> + url: <%= ENV['SOLR_URL'] || "http://#{ENV["lando_pulmap_test_solr_conn_host"] || "127.0.0.1"}:#{ENV['SOLR_TEST_PORT'] || ENV["lando_pulmap_test_solr_conn_port"] || 8984}/solr/pulmap-core-test" %> production: adapter: solr url: <%= ENV['PULMAP_SOLR_URL'] %> diff --git a/config/database.yml b/config/database.yml index cbca3695..c61919ca 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,25 +1,26 @@ default: &default - adapter: sqlite3 + adapter: postgresql + encoding: unicode + host: <%= ENV["lando_pulmap_database_conn_host"] || ENV["PULMAP_DB_HOST"] || "localhost" %> + port: <%= ENV["lando_pulmap_database_conn_port"] || 5432 %> + username: <%= ENV["lando_pulmap_database_creds_user"] || ENV["PULMAP_DB_USERNAME"] %> + password: <%= ENV["lando_pulmap_database_creds_password"] || ENV["PULMAP_DB_PASSWORD"] %> + database: <%= ENV['PULMAP_DB'] %> pool: 5 - timeout: 5000 development: <<: *default - database: db/development.sqlite3 + database: pulmap_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default - database: db/test.sqlite3 + database: pulmap_test -production: &deploy +production: <<: *default - adapter: postgresql - database: <%= ENV["PULMAP_DB"] %> - host: <%= ENV["PULMAP_DB_HOST"] %> - username: <%= ENV["PULMAP_DB_USERNAME"] %> - password: <%= ENV["PULMAP_DB_PASSWORD"] %> -staging: *deploy +staging: + <<: *default diff --git a/config/lando_env.rb b/config/lando_env.rb new file mode 100644 index 00000000..dd219a09 --- /dev/null +++ b/config/lando_env.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true +if Rails.env.development? || Rails.env.test? + begin + lando_services = JSON.parse(`lando info --format json`, symbolize_names: true) + lando_services.each do |service| + service[:external_connection]&.each do |key, value| + ENV["lando_#{service[:service]}_conn_#{key}"] = value + end + next unless service[:creds] + service[:creds].each do |key, value| + ENV["lando_#{service[:service]}_creds_#{key}"] = value + end + end + rescue StandardError + nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 6f8d83e0..6c21e181 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,11 +12,14 @@ ActiveRecord::Schema.define(version: 2020_03_04_234118) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false - t.integer "record_id", null: false - t.integer "blob_id", null: false + t.bigint "record_id", null: false + t.bigint "blob_id", null: false t.datetime "created_at", null: false t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true @@ -33,7 +36,7 @@ t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end - create_table "bookmarks", force: :cascade do |t| + create_table "bookmarks", id: :serial, force: :cascade do |t| t.integer "user_id", null: false t.string "user_type" t.string "document_id" @@ -44,7 +47,7 @@ t.index ["user_id"], name: "index_bookmarks_on_user_id" end - create_table "searches", force: :cascade do |t| + create_table "searches", id: :serial, force: :cascade do |t| t.text "query_params" t.integer "user_id" t.string "user_type" @@ -69,13 +72,13 @@ t.string "document_id" t.string "document_type" t.string "image" - t.integer "version", limit: 8 + t.bigint "version" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["document_type", "document_id"], name: "sidecars_solr_document" end - create_table "users", force: :cascade do |t| + create_table "users", id: :serial, force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" @@ -97,4 +100,6 @@ t.index ["username"], name: "index_users_on_username" end + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "sidecar_image_transitions", "solr_document_sidecars" end diff --git a/lib/tasks/pulmap.rake b/lib/tasks/pulmap.rake index 1ad03e00..d4a4af5d 100644 --- a/lib/tasks/pulmap.rake +++ b/lib/tasks/pulmap.rake @@ -29,41 +29,23 @@ namespace :pulmap do end end - desc "Start solr server for testing." - task :test do - if Rails.env.test? - shared_solr_opts = { managed: true, verbose: true, persist: false, download_dir: 'tmp' } - shared_solr_opts[:version] = ENV['SOLR_VERSION'] if ENV['SOLR_VERSION'] + namespace :server do + desc "Start solr and postgres servers using lando." + task :start do + system('lando start') + system('rake pulmap:server:seed') + system('rake pulmap:server:seed RAILS_ENV=test') + end - SolrWrapper.wrap(shared_solr_opts.merge(port: 8985, instance_dir: 'tmp/pulmap-core-test')) do |solr| - solr.with_collection(name: "pulmap-core-test", dir: Rails.root.join("solr", "conf").to_s) do - puts "Solr running at http://localhost:8985/solr/pulmap-core-test/, ^C to exit" - begin - Rake::Task['geoblacklight:solr:seed'].invoke - sleep - rescue Interrupt - puts "\nShutting down..." - end - end - end - else - system('rake pulmap:test RAILS_ENV=test') + task :seed do + Rake::Task['db:create'].invoke + Rake::Task['db:migrate'].invoke + Rake::Task['geoblacklight:solr:seed'].invoke end - end - desc "Start solr server for development." - task :development do - SolrWrapper.wrap(managed: true, verbose: true, port: 8983, instance_dir: 'tmp/pulmap-core-dev', persist: false, download_dir: 'tmp') do |solr| - solr.with_collection(name: "pulmap-core-dev", dir: Rails.root.join("solr", "conf").to_s) do - puts "Setup solr" - puts "Solr running at http://localhost:8983/solr/pulmap-core-dev/, ^C to exit" - begin - Rake::Task['geoblacklight:solr:seed'].invoke - sleep - rescue Interrupt - puts "\nShutting down..." - end - end + desc "Stop lando solr and postgres servers." + task :stop do + system('lando stop') end end diff --git a/solr/conf/schema.xml b/solr/conf/schema.xml index f22d10fd..a800534f 100644 --- a/solr/conf/schema.xml +++ b/solr/conf/schema.xml @@ -17,7 +17,7 @@ - + @@ -71,15 +71,15 @@ - - - - + + + + - + @@ -96,15 +96,17 @@ + - + + @@ -124,9 +126,9 @@ - + @@ -134,14 +136,13 @@ - - + @@ -192,6 +193,6 @@ - + !-- for bbox value --> diff --git a/solr/conf/solrconfig.xml b/solr/conf/solrconfig.xml index 9c0786e9..62a46d38 100644 --- a/solr/conf/solrconfig.xml +++ b/solr/conf/solrconfig.xml @@ -27,7 +27,7 @@ that you fully re-index after changing this setting as it can affect both how text is indexed and queried. --> - 7.1 + 7.1.0 @@ -36,9 +36,9 @@ - + ${solr.blacklight-core.data.dir:} - + ${solr.lock.type:native} @@ -69,8 +69,6 @@ - - @@ -207,12 +205,6 @@ all - - server-enabled.txt