diff --git a/.dockerignore b/.dockerignore index d12e797bc..48b7cbb60 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,3 +9,4 @@ postgres-data redis-data # Required for puma to have a place to put the pid file !tmp/pids/.keep +public/assets diff --git a/Capfile b/Capfile index 7fbea43ca..a8f6aa7bf 100644 --- a/Capfile +++ b/Capfile @@ -9,13 +9,9 @@ require 'capistrano/deploy' require 'capistrano/scm/git' install_plugin Capistrano::SCM::Git -require 'capistrano/bundler' -require 'capistrano/rails' -require 'capistrano/honeybadger' -require 'capistrano/passenger' require 'capistrano/maintenance' -require 'whenever/capistrano' -require 'dlss/capistrano' + +require 'dlss/docker/capistrano' # Load custom tasks from `lib/capistrano/tasks` if you have any defined Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } diff --git a/Gemfile b/Gemfile index b4a1ba281..3fa41fb75 100644 --- a/Gemfile +++ b/Gemfile @@ -23,10 +23,8 @@ group :development, :test do end group :development do - gem 'faker' gem 'listen', '~> 3.2' gem 'multi_json', require: false # needed to update RBIs after adding reform-rails - gem 'puma', '~> 5.6', '>= 5.6.4' gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' gem 'state_machines-graphviz' @@ -41,9 +39,8 @@ end group :deployment do gem 'capistrano-maintenance', '~> 1.2', require: false - gem 'capistrano-passenger', require: false gem 'capistrano-rails', require: false - gem 'dlss-capistrano', require: false + gem 'dlss-capistrano-docker', github: 'sul-dlss/dlss-capistrano-docker', branch: 't2-rollback', require: false end gem 'action_policy', '~> 0.5.3' @@ -57,6 +54,7 @@ gem 'devise-remote-user', '~> 1.0' gem 'druid-tools' gem 'dry-types' gem 'edtf' +gem 'faker' gem 'faraday', '~> 2.0' gem 'honeybadger', '~> 4.0' gem 'jbuilder' @@ -67,6 +65,7 @@ gem 'pg' gem 'preservation-client', '~> 5.0' gem 'propshaft' gem 'pry' +gem 'puma', '~> 5.6', '>= 5.6.4' gem 'redis', '~> 4.0' # TODO: Deal with this # pinned because 2.6.0 broke the build: [Reform] Your :populator did not return a Reform::Form instance for `authors`. diff --git a/Gemfile.lock b/Gemfile.lock index 9240fff65..c5719c530 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,13 @@ +GIT + remote: https://github.com/sul-dlss/dlss-capistrano-docker.git + revision: 6db0ad1335507359f32b6a40ce8cd56e8be42be9 + branch: t2-rollback + specs: + dlss-capistrano-docker (1.0.0) + capistrano (~> 3.0) + capistrano-one_time_key + capistrano-shared_configs + GEM remote: https://rubygems.org/ specs: @@ -80,9 +90,6 @@ GEM bootsnap (1.13.0) msgpack (~> 1.2) builder (3.2.4) - bundler-audit (0.9.1) - bundler (>= 1.2.0, < 3) - thor (~> 1.0) bunny (2.19.0) amq-protocol (~> 2.3, >= 2.3.1) sorted_set (~> 1, >= 1.0.2) @@ -92,18 +99,12 @@ GEM i18n rake (>= 10.0.0) sshkit (>= 1.9.0) - capistrano-bundle_audit (0.4.0) - bundler-audit (~> 0.5) - capistrano (~> 3.0) - capistrano-bundler (>= 1.4) capistrano-bundler (2.1.0) capistrano (~> 3.1) capistrano-maintenance (1.2.1) capistrano (>= 3.0) capistrano-one_time_key (0.1.0) capistrano (~> 3.0) - capistrano-passenger (0.2.1) - capistrano (~> 3.0) capistrano-rails (1.6.2) capistrano (~> 3.1) capistrano-bundler (>= 1.1, < 3) @@ -179,11 +180,6 @@ GEM declarative-option (< 0.2.0) representable (>= 2.4.0, <= 3.1.0) uber (< 0.2.0) - dlss-capistrano (4.3.1) - capistrano (~> 3.0) - capistrano-bundle_audit (>= 0.3.0) - capistrano-one_time_key - capistrano-shared_configs docile (1.4.0) druid-tools (3.0.0) dry-configurable (0.16.1) @@ -548,7 +544,6 @@ DEPENDENCIES bunny (~> 2.17) byebug capistrano-maintenance (~> 1.2) - capistrano-passenger capistrano-rails capybara (~> 3.34) capybara-screenshot @@ -559,7 +554,7 @@ DEPENDENCIES cypress-rails devise (~> 4.7) devise-remote-user (~> 1.0) - dlss-capistrano + dlss-capistrano-docker! druid-tools dry-types edtf diff --git a/README.md b/README.md index 17c02a118..dc08f6f19 100644 --- a/README.md +++ b/README.md @@ -65,13 +65,13 @@ Then run tests with `bundle exec rspec`. If you also want to do style checks & l ### Integration -Spin up all docker compose services for local development and in-browser testing: +Spin up all docker compose services for local testing: ```shell $ docker compose up # use -d to run in background ``` -This will spin up the H2 web application, its background workers, and all service dependencies declared in docker-compose.yml. +This will spin up the H2 web application, its background workers, and all service dependencies declared in docker-compose.yml. H2 will be running in production mode. ### Cypress Cypress is primarily used to test features implemented with JS/Stimulus. Cypress tests are located in `cypress/spec`. diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 98ec65e2f..d571a38c6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -41,14 +41,21 @@ def groups_from_request_env session['groups'] = begin raw_header = request.env[Settings.authorization_group_header] roles = ENV.fetch('ROLES', nil) # rubocop:disable Rails/EnvironmentVariableAccess - raw_header = roles if Rails.env.development? - # This test setting is for cypress. - raw_header = roles if Rails.env.test? && roles + raw_header = roles if use_roles?(roles) logger.debug("Roles are #{raw_header}") raw_header&.split(';') || [] end end + def use_roles?(roles) + return true if Rails.env.development? + # This test setting is for cypress. + return true if Rails.env.test? && roles + return true if ENV.fetch('LOCAL_DOCKER', nil) && roles # rubocop:disable Rails/EnvironmentVariableAccess + + false + end + def deny_access flash[:warning] = 'You are not authorized to perform the requested action' redirect_to :root diff --git a/app/jobs/assign_pid_job.rb b/app/jobs/assign_pid_job.rb index 9593f915f..79b716bea 100644 --- a/app/jobs/assign_pid_job.rb +++ b/app/jobs/assign_pid_job.rb @@ -6,7 +6,7 @@ class AssignPidJob # This worker will connect to "h2.druid_assigned" queue # env is set to nil since by default the actual queue name would be # "h2.druid_assigned_development" - from_queue 'h2.druid_assigned', env: nil + from_queue Settings.rabbitmq.queues.druid_assigned, env: nil def work(msg) model = build_cocina_model_from_json_str(msg) diff --git a/app/jobs/deposit_complete_job.rb b/app/jobs/deposit_complete_job.rb index 0271997ff..0aa4925ff 100644 --- a/app/jobs/deposit_complete_job.rb +++ b/app/jobs/deposit_complete_job.rb @@ -11,7 +11,7 @@ class DepositCompleteJob # example, if the embargo was lifted, DSA would open and close a version. The # workflow message "end-accession" would end up here. We must be able to handle # these messages in addition to those that result from depositing in h2. - from_queue 'h2.deposit_complete', env: nil + from_queue Settings.rabbitmq.queues.deposit_complete, env: nil def work(msg) druid = parse_message(msg) diff --git a/app/jobs/record_embargo_release_job.rb b/app/jobs/record_embargo_release_job.rb index 571796e3b..d5f7feebd 100644 --- a/app/jobs/record_embargo_release_job.rb +++ b/app/jobs/record_embargo_release_job.rb @@ -6,7 +6,7 @@ class RecordEmbargoReleaseJob # This worker will connect to "h2.embargo_lifted" queue # env is set to nil since by default the actual queue name would be # "h2.embargo_lifted_development" - from_queue 'h2.embargo_lifted', env: nil + from_queue Settings.rabbitmq.queues.embargo_lifted, env: nil def work(msg) model = build_cocina_model_from_json_str(msg) diff --git a/config/deploy.rb b/config/deploy.rb index 121a7ffe5..f9e72e592 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -22,14 +22,11 @@ # Default value for :pty is false # set :pty, true -# Default value for :linked_files is [] -append :linked_files, - 'config/database.yml', # in Puppet - 'config/secrets.yml', # in shared_configs - 'config/honeybadger.yml' # in shared_configs +set :linked_files, %w[config/honeybadger.yml] -# Default value for linked_dirs is [] -append :linked_dirs, 'log', 'config/settings', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system' +set :linked_dirs, %w[log config/settings public/system] + +set :dereference_dirs, %w[config/settings] # Default value for default_env is {} # set :default_env, { path: "/opt/ruby/bin:$PATH" } @@ -46,21 +43,9 @@ # honeybadger_env otherwise defaults to rails_env set :honeybadger_env, fetch(:stage) -# Manage sidekiq via systemd (from dlss-capistrano gem) -set :sidekiq_systemd_use_hooks, true - -# Manage sneakers via systemd (from dlss-capistrano gem) -set :sneakers_systemd_use_hooks, true - # Set Rails env to production in all Cap environments set :rails_env, 'production' -# Deploy passenger-standalone via systemd service -set :passenger_restart_command, 'sudo systemctl restart passenger' -set :passenger_restart_options, -> { '' } - -set :whenever_environment, fetch(:rails_env) -set :whenever_roles, [:cron] - -# update shared_configs before restarting app (from dlss-capistrano gem) -before 'deploy:restart', 'shared_configs:update' +set :docker_compose_file, 'docker-compose.prod.yml' +set :docker_compose_seed_use_hooks, true +set :docker_compose_rabbitmq_use_hooks, true diff --git a/config/deploy/qa.rb b/config/deploy/qa.rb index 645246c6d..c0dcf2af4 100644 --- a/config/deploy/qa.rb +++ b/config/deploy/qa.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -server 'sul-h2-qa.stanford.edu', user: 'h2', roles: %w[web app db] +# Roles are passed to docker-compose as profiles. +server 'h2-docker-qa.stanford.edu', user: 'h2', roles: %w[web app db cron worker] Capistrano::OneTimeKey.generate_one_time_key! diff --git a/config/environments/production.rb b/config/environments/production.rb index cb79d2520..3cecf6a1a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -66,6 +66,7 @@ config.action_mailer.perform_caching = false config.action_mailer.asset_host = "https://#{Settings.host}" + config.action_mailer.smtp_settings = { address: ENV.fetch('SMTP_HOST', 'localhost') } # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. diff --git a/config/initializers/devise_remote_user.rb b/config/initializers/devise_remote_user.rb index 8f59d46d4..2e6cdc777 100644 --- a/config/initializers/devise_remote_user.rb +++ b/config/initializers/devise_remote_user.rb @@ -3,7 +3,7 @@ DeviseRemoteUser.configure do |config| config.env_key = lambda do |env| remote_user = ENV.fetch('REMOTE_USER', nil) - if (Rails.env.development? || Rails.env.test?) && remote_user + if (Rails.env.development? || Rails.env.test? || ENV.fetch('LOCAL_DOCKER', false)) && remote_user remote_user else # Return the first non-blank value of a remote user header, or return nil (unauthenticated) diff --git a/config/puma.rb b/config/puma.rb index 69e2645fb..c5a455e58 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,8 +6,8 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) -min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } +max_threads_count = ENV.fetch('PUMA_MAX_THREADS', 5) +min_threads_count = ENV.fetch('PUMA_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. @@ -27,14 +27,14 @@ # Workers do not work on JRuby or Windows (both of which do not support # processes). # -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } +workers ENV.fetch('PUMA_WORKERS', 2) # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. # -# preload_app! +preload_app! # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart diff --git a/config/schedule.rb b/config/schedule.rb index 4b183ab82..bbc4dde1e 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -3,6 +3,9 @@ # Use this file to easily define all of your cron jobs. # Learn more: http://github.com/javan/whenever +# Execute without bash. +set :job_template, nil + every :day, at: '1:00am' do runner 'WorkReminderGenerator.send_draft_reminders' end diff --git a/config/settings.yml b/config/settings.yml index ed045c032..259f70372 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -58,7 +58,7 @@ purl_url: https://purl.stanford.edu terms_url: https://library.stanford.edu/research/stanford-digital-repository/documentation/sdr-terms-deposit sdr_url: https://library.stanford.edu/research/stanford-digital-repository -host: <%= Socket.gethostname %> +host: <%= ENV.fetch('HOST', Socket.gethostname) %> rabbitmq: enabled: false @@ -66,6 +66,10 @@ rabbitmq: vhost: / username: guest password: guest + queues: + deposit_complete: 'h2.deposit_complete' + druid_assigned: 'h2.druid_assigned' + embargo_lifted: 'h2.embargo_lifted' notifications: first_draft_reminder: diff --git a/db/seeds.rb b/db/seeds.rb index 9ae6be35c..8b10156fc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,4 +9,4 @@ # Character.create(name: 'Luke', movie: movies.first) # The SDR user is used in Events performed by SDR. -User.create!(name: 'SDR', email: 'sdr@stanford.edu') +User.find_or_create_by!(name: 'SDR', email: 'sdr@stanford.edu') diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 000000000..8b1ce25e2 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,69 @@ +version: '3.6' + +name: h2 + +services: + app: + build: &build + context: . + dockerfile: docker/Dockerfile + args: + - GID=${H2_GID-1000} + - UID=${H2_UID-1000} + - SECRET_KEY_BASE + environment: &environment + - DATABASE_NAME=h2 + - DATABASE_USERNAME + - DATABASE_PASSWORD + - DATABASE_HOSTNAME + - REDIS_URL + - SMTP_HOST=host.docker.internal + - HOST + - HONEYBADGER_API_KEY + - SETTINGS__RABBITMQ__PASSWORD + - SETTINGS__RABBITMQ__QUEUES__DEPOSIT_COMPLETE + - SETTINGS__RABBITMQ__QUEUES__DRUID_ASSIGNED + - SETTINGS__RABBITMQ__QUEUES__EMBARGO_LIFTED + - SETTINGS__SDR_API__PASSWORD + - SETTINGS__PRESERVATION_CATALOG__TOKEN + - SETTINGS__ACCOUNTWS__PEM_FILE=/etc/pki/tls/certs/h2-docker-qa.stanford.edu.pem + volumes: &volumes + - /opt/app/h2/happy-heron/shared/log:/app/log + - /data/h2-files:/data/h2-files + - /etc/pki/tls/certs:/etc/pki/tls/certs + ports: + - 3000:3000 + extra_hosts: &extra-hosts + - host.docker.internal:host-gateway + profiles: + - web + # restart: on-failure + sneakers: + build: *build + environment: *environment + volumes: *volumes + extra_hosts: *extra-hosts + profiles: + - web + command: bin/bundle exec rake sneakers:run 2>&1 | tee -a log/sneakers.log + # restart: on-failure + sidekiq: + build: *build + environment: *environment + volumes: *volumes + extra_hosts: *extra-hosts + command: bin/bundle exec sidekiq 2>&1 | tee -a log/sidekiq.log + profiles: + - worker + deploy: + replicas: ${SIDEKIQ_COUNT-1} + # restart: on-failure + cron: + build: *build + environment: *environment + volumes: *volumes + extra_hosts: *extra-hosts + profiles: + - cron + command: supercronic /app/config/crontab 2>&1 | tee -a log/cron.log + # restart: on-failure diff --git a/docker-compose.yml b/docker-compose.yml index 050f487ed..f7e6fa039 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,42 +2,35 @@ version: '3.6' services: app: - build: + build: &build context: . - dockerfile: docker/app/Dockerfile - environment: + dockerfile: docker/Dockerfile + args: + SECRET_KEY_BASE: 2e4f669b6529a0bcec468d9b5329e2fe7e7f6a4d7915370862d6d4f2b6907f1fabc505a681aaa13b3858f02588602fd0b721ca783bdac37fe70ea83b8f123456 + environment: &environment DATABASE_NAME: h2 DATABASE_USERNAME: postgres DATABASE_PASSWORD: postgres DATABASE_HOSTNAME: db - RAILS_LOG_TO_STDOUT: 'true' + RAILS_SERVE_STATIC_FILES: 'true' REDIS_URL: redis://redis:6379/ # for ActionCable - REMOTE_USER: sdr.user@stanford.edu - volumes: - - .:/app - working_dir: /app + REMOTE_USER: auser@stanford.edu + ROLES: dlss:hydrus-app-administrators + LOCAL_DOCKER: 'true' ports: - 3000:3000 depends_on: - db - redis - workers + command: "./docker/invoke-app.sh" workers: - build: - context: . - dockerfile: docker/workers/Dockerfile - environment: - DATABASE_NAME: h2 - DATABASE_USERNAME: postgres - DATABASE_PASSWORD: postgres - DATABASE_HOSTNAME: db - REDIS_URL: redis://redis:6379/ # for Sidekiq - volumes: - - .:/app - working_dir: /app + build: *build + environment: *environment depends_on: - db - redis + command: "./docker/invoke-worker.sh" db: image: postgres:12 environment: diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..c35d8fa56 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,56 @@ +FROM ruby:3.1-alpine + +# curl is to install supercronic +# postgresql-client and redis is required for invoke.sh +RUN apk add --update --no-cache \ + build-base \ + postgresql-dev \ + postgresql-client \ + tzdata \ + yarn \ + curl \ + redis + +ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.1/supercronic-linux-amd64 +ENV SUPERCRONIC=supercronic-linux-amd64 +ENV SUPERCRONIC_SHA1SUM=d7f4c0886eb85249ad05ed592902fa6865bb9d70 + +# Cron replacement, since cron must be run as root +RUN curl -fsSLO "$SUPERCRONIC_URL" \ + && echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \ + && chmod +x "$SUPERCRONIC" \ + && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \ + && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic + +# Get bundler 2.0 +RUN gem install bundler + +ARG UID=1000 +ARG GID=1000 +ARG SECRET_KEY_BASE +ENV SECRET_KEY_BASE=${SECRET_KEY_BASE} + +RUN addgroup -g $GID h2 +RUN adduser -G h2 -u $UID -D h2 + +WORKDIR /app + +COPY Gemfile Gemfile.lock package.json yarn.lock ./ + +ENV RAILS_ENV=production +ENV RAILS_LOG_TO_STDOUT=true +ENV BUNDLE_WITHOUT="test:development:deployment" +ENV NODE_ENV=production + +RUN bundle install +RUN yarn install + +RUN chown -R h2:h2 /app +COPY --chown=h2:h2 . . +USER h2:h2 + +RUN bin/rails assets:precompile +# Write out the crontab file +RUN sh -c 'bundle exec whenever . | tee -a config/crontab' + +CMD bin/puma -C config/puma.rb config.ru 2>&1 | tee -a log/production.log diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile deleted file mode 100644 index ec1bbf24c..000000000 --- a/docker/app/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -# This Dockerfile is optimized for running in development. That means it trades -# build speed for size. If we were using this for production, we might instead -# optimize for a smaller size at the cost of a slower build. -FROM ruby:3.1-alpine - -# postgresql-client is required for invoke.sh -RUN apk add --update --no-cache \ - build-base \ - postgresql-dev \ - postgresql-client \ - tzdata \ - yarn \ - git - -# Get bundler 2.0 -RUN gem install bundler - -WORKDIR /app - -COPY Gemfile Gemfile.lock package.json yarn.lock ./ - -RUN bundle config set without 'production' && \ - bundle install && \ - yarn install - -COPY . . - -RUN bin/rails assets:precompile - -CMD ["./docker/app/invoke.sh"] diff --git a/docker/app/invoke.sh b/docker/invoke-app.sh similarity index 94% rename from docker/app/invoke.sh rename to docker/invoke-app.sh index 17455c88e..33320d5f4 100755 --- a/docker/app/invoke.sh +++ b/docker/invoke-app.sh @@ -22,5 +22,8 @@ set -e echo "Migrating db" bin/rails db:migrate +echo "Seeding db" +bin/rails db:seed + echo "Running server" exec bin/puma -C config/puma.rb config.ru diff --git a/docker/workers/invoke.sh b/docker/invoke-worker.sh similarity index 100% rename from docker/workers/invoke.sh rename to docker/invoke-worker.sh diff --git a/docker/workers/Dockerfile b/docker/workers/Dockerfile deleted file mode 100644 index 1b24a46bb..000000000 --- a/docker/workers/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# This Dockerfile is optimized for running in development. That means it trades -# build speed for size. If we were using this for production, we might instead -# optimize for a smaller size at the cost of a slower build. -FROM ruby:3.1-alpine - -# postgresql-client is required for invoke.sh -RUN apk add --update --no-cache \ - build-base \ - postgresql-dev \ - postgresql-client \ - redis \ - tzdata \ - git - -# Get bundler 2.0 -RUN gem install bundler - -WORKDIR /app - -COPY Gemfile Gemfile.lock ./ - -RUN bundle config set without 'production' && \ - bundle install - -COPY . . - -CMD ["./docker/workers/invoke.sh"] diff --git a/lib/tasks/deposit.rake b/lib/tasks/deposit.rake index 026016302..f6fd99df8 100644 --- a/lib/tasks/deposit.rake +++ b/lib/tasks/deposit.rake @@ -2,7 +2,7 @@ desc 'Complete deposit of works and collections (only for development)' task complete_deposits: :environment do - abort 'ERROR: This task only runs in the development environment!' unless Rails.env.development? + abort 'ERROR: This task only runs in the development environment!' unless can_run? objects_awaiting_deposit.each do |object_version| deposit_completer = DepositCompleter.new(object_version:) @@ -15,7 +15,7 @@ end desc 'Complete the assignment of a druid to purl reservation works that need one' task assign_pids: :environment do - abort 'ERROR: This task only runs in the development environment!' unless Rails.env.development? + abort 'ERROR: This task only runs in the development environment!' unless can_run? WorkVersion.with_state('reserving_purl').each do |object| druid = random_druid @@ -39,3 +39,7 @@ def random_druid # => "{druid:,}qj078cn5200" "druid:#{Faker::Base.regexify(DruidTools::Druid.strict_glob).last(11)}" end + +def can_run? + Rails.env.development? || ENV.fetch('LOCAL_DOCKER', false) +end diff --git a/lib/tasks/rabbitmq.rake b/lib/tasks/rabbitmq.rake index 36e4628e3..c70d959da 100644 --- a/lib/tasks/rabbitmq.rake +++ b/lib/tasks/rabbitmq.rake @@ -14,15 +14,15 @@ namespace :rabbitmq do # connect topic to the queue exchange = channel.topic('sdr.workflow') - queue = channel.queue('h2.deposit_complete', durable: true) + queue = channel.queue(Settings.rabbitmq.queues.deposit_complete, durable: true) queue.bind(exchange, routing_key: 'end-accession.completed') exchange = channel.topic('sdr.objects.created') - queue = channel.queue('h2.druid_assigned', durable: true) + queue = channel.queue(Settings.rabbitmq.queues.druid_assigned, durable: true) queue.bind(exchange, routing_key: Settings.h2.project_tag) exchange = channel.topic('sdr.objects.embargo_lifted') - queue = channel.queue('h2.embargo_lifted', durable: true) + queue = channel.queue(Settings.rabbitmq.queues.embargo_lifted, durable: true) queue.bind(exchange, routing_key: Settings.h2.project_tag) conn.close end