diff --git a/Dockerfile b/Dockerfile index b017c18..03f3209 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,6 +76,9 @@ RUN mkdir -p /opt/app/tmp \ # Add binstubs to the path. ENV PATH="/usr/bin:/opt/app/bin:/usr/local/yarn/node_modules/.bin:$PATH" +# Add path to node_modules +ENV NODE_PATH=/usr/local/yarn/node_modules + # If run with no other arguments, the image will start the rails server by # default. Note that we must bind to all interfaces (0.0.0.0) because when # running in a docker container, the actual public interface is created @@ -85,7 +88,7 @@ ENV PATH="/usr/bin:/opt/app/bin:/usr/local/yarn/node_modules/.bin:$PATH" # yet, so if the build fails before the `bundle install` step below, you # will need to override the default command when troubleshooting the buggy # image. -CMD ["rails", "server", "-b", "0.0.0.0"] +CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] # ============================================================================= # Target: development @@ -131,7 +134,7 @@ RUN bundle install # re-install. COPY --chown=$APP_USER:$APP_USER . . -RUN yarn install --cwd /usr/local/yarn +RUN yarn install --frozen-lockfile --cwd /usr/local/yarn # ============================================================================= # Target: production @@ -160,18 +163,19 @@ COPY --from=development --chown=$APP_USER /usr/local/yarn /usr/local/yarn # Ensure the bundle is installed and the Gemfile.lock is synced. RUN bundle config set frozen 'true' RUN bundle install --local - +RUN ln -s /usr/local/yarn/node_modules /opt/app/node_modules # ------------------------------------------------------------ # Precompile production assets # TODO: Figure out why jsbundling-rails doesn't invoke `yarn build` # *before* Sprockets reads app/assets/config/manifest.js -RUN yarn install --cwd /usr/local/yarn +WORKDIR /opt/app +RUN yarn build # Pre-compile assets so we don't have to do it after deployment. # NOTE: dummy SECRET_KEY_BASE to prevent spurious initializer issues # -- see https://github.com/rails/rails/issues/32947 -RUN SECRET_KEY_BASE=1 rails assets:precompile --trace +RUN SECRET_KEY_BASE=1 bundle exec rails assets:precompile --trace # ------------------------------------------------------------ # Preserve build arguments diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 22a2aed..2391434 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,8 +9,7 @@ <%= csp_meta_tag %> - - <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> + <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true, type: "module" %> <%= javascript_include_tag "items", "data-turbo-track": "reload", defer: true %> <%= javascript_include_tag "terms", "data-turbo-track": "reload", defer: true %> <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index e77b173..404859e 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -13,6 +13,13 @@ # folder are already added. Rails.application.config.assets.precompile += %w[*.png] +Rails.application.config.assets.precompile += %w[ + application.js + items.js + terms.js + viewer.js + marc-reload.js +] # Rails.application.config.assets.configure do |env| # env.css_compressor = :sass # end