diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 00000000..841f358d --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,37 @@ +FROM ruby:2.6 +ARG UNAME=app +ARG UID=1000 +ARG GID=1000 +ARG URL_ROOT=/ + +RUN curl https://deb.nodesource.com/setup_18.x | bash +RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + +RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends nodejs yarn +RUN gem install bundler + +RUN groupadd -g $GID -o $UNAME +RUN useradd -m -d /usr/src/app -u $UID -g $GID -o -s /bin/bash $UNAME +RUN mkdir -p /gems && chown $UID:$GID /gems + +COPY --chown=$UID:$GID Gemfile* /usr/src/app/ + +ENV RAILS_SERVE_STATIC_FILES true +ENV RAILS_LOG_TO_STDOUT true +ENV RAILS_ENV production +ENV BUNDLE_PATH /gems + +# This can be anything but must be set. +ENV SECRET_KEY_BASE 121222bccca + +WORKDIR /usr/src/app +RUN bundle install --without development test + +COPY --chown=$UID:$GID . /usr/src/app +RUN RAILS_ENV=production bin/rails assets:precompile +RUN chown -R $UID:$GID /usr/src/app +USER $UNAME + + +CMD ["bin/rails", "s", "-b", "0.0.0.0"] diff --git a/Gemfile.lock b/Gemfile.lock index 33c4de18..3ebcb0c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -204,7 +204,7 @@ GEM parser (3.2.1.1) ast (~> 2.4.1) pg (1.4.6) - prometheus-client (4.0.0) + prometheus-client (4.1.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -346,10 +346,10 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.3.13) - standard (1.25.0) + standard (1.25.3) language_server-protocol (~> 3.17.0.2) - rubocop (= 1.48.1) - rubocop-performance (= 1.16.0) + rubocop (~> 1.48.1) + rubocop-performance (~> 1.16.0) thor (1.2.1) thread_safe (0.3.6) tilt (2.1.0) diff --git a/Rakefile b/Rakefile index 9ca41066..348297fc 100644 --- a/Rakefile +++ b/Rakefile @@ -3,5 +3,43 @@ require_relative "config/application" require "standard/rake" +require_relative "app/jobs/job_index" +require_relative "lib/med_installer/job_monitoring" Rails.application.load_tasks + +desc "sanity-check sidekiq" +task :poke_sidekiq do + Dromedary::PokeSidekiqJob.perform_async +end + +desc "Check for updated data file" +task :check_data do + # metrics = MiddleEnglishIndexMetrics.new({type: "check_data"}) + + # standard:disable Lint/ConstantDefinitionInBlock + UPDATE_WINDOW_SECONDS = 7 * 24 * 60 * 60 # should update once weekly + # standard:enable Lint/ConstantDefinitionInBlock + begin + puts ENV["DATA_FILE"] + last_modified = File.mtime(ENV["DATA_FILE"]) + puts last_modified + if (Time.now - last_modified) < UPDATE_WINDOW_SECONDS + # metrics.log_success + puts "kicking off data job" + Dromedary::IndexDataJob.perform_async(ENV["DATA_FILE"]) + end + rescue => _e + # metrics.log_error(e) + end +end + +desc "add indexing job to sidekiq queue" +task :queue_indexing do + Dromedary::IndexDataJob.perform_async(ENV["DATA_FILE"]) +end + +desc "do indexing job now" +task :perform_indexing do + Dromedary::IndexDataJob.perform(ENV["DATA_FILE"]) +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb deleted file mode 100644 index a009ace5..00000000 --- a/app/jobs/application_job.rb +++ /dev/null @@ -1,2 +0,0 @@ -class ApplicationJob < ActiveJob::Base -end diff --git a/app/jobs/index_data_job.rb b/app/jobs/index_data_job.rb new file mode 100644 index 00000000..7bd4e8ca --- /dev/null +++ b/app/jobs/index_data_job.rb @@ -0,0 +1,15 @@ +require "sidekiq" + +module Dromedary + class IndexDataJob + include Sidekiq::Job + + queue_as :default + + def perform(filename) + puts "indexing data" + exit_code = `bin/dromedary extract_convert_index #{filename}` + puts "finished preparing with exit code #{exit_code}" + end + end +end diff --git a/app/jobs/job_index.rb b/app/jobs/job_index.rb new file mode 100644 index 00000000..9f6db10e --- /dev/null +++ b/app/jobs/job_index.rb @@ -0,0 +1,2 @@ +require_relative "./poke_sidekiq" +require_relative "./index_data_job" diff --git a/app/jobs/poke_sidekiq.rb b/app/jobs/poke_sidekiq.rb new file mode 100644 index 00000000..b7373dac --- /dev/null +++ b/app/jobs/poke_sidekiq.rb @@ -0,0 +1,11 @@ +require "sidekiq" + +module Dromedary + class PokeSidekiqJob + include Sidekiq::Job + + def perform + puts "hiiiiii" + end + end +end diff --git a/app/views/catalog/home.html.erb b/app/views/catalog/home.html.erb index 5d50c4ab..a2a8aff6 100644 --- a/app/views/catalog/home.html.erb +++ b/app/views/catalog/home.html.erb @@ -9,10 +9,11 @@
- <%= render_search_bar %> + <%= render_search_bar %>
- + + diff --git a/app/views/catalog/splash.html.erb b/app/views/catalog/splash.html.erb index 224dd756..1b3a7995 100644 --- a/app/views/catalog/splash.html.erb +++ b/app/views/catalog/splash.html.erb @@ -42,7 +42,8 @@ Shown is the introduction to "The Knight's Tale." Available online at the Huntington - Library <%= image_tag('external-link-white.svg', alt: 'Opens in a new window') %> + + Library <%= image_tag(asset_path('external-link-white.svg'), alt: 'Opens in a new window') %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6ac074dd..ffc5a1f9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -35,6 +35,10 @@ <%= render :partial => 'shared/header_navbar' %> <% end %> + <% if ENV['DEBUG_ENV'] %> + x-forwarded host: <%= ENV["HTTP_X_FORWARDED_HOST"].inspect %> + <% end %> + <%= area :main do %>

Main content goes here.

<% end %> diff --git a/app/views/shared/_footer.html.erb b/app/views/shared/_footer.html.erb index 2d5387bb..5e0ee4cf 100644 --- a/app/views/shared/_footer.html.erb +++ b/app/views/shared/_footer.html.erb @@ -5,11 +5,11 @@
  • Middle English Compendium
  • Middle English Dictionary
  • Bibliography
  • -
  • Corpus <%= image_tag('external-link-white.svg', alt:'Opens in a new window') %>
  • + +
  • Corpus <%= image_tag(asset_path('external-link-white.svg'), alt:'Opens in a new window') %>
  • -