diff --git a/Dockerfile b/Dockerfile index 2c1e8b4..7e6d325 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,13 +13,12 @@ ENV RAILS_ENV="production" \ BUNDLE_PATH="/usr/local/bundle" \ BUNDLE_WITHOUT="development" - # Throw-away build stage to reduce size of final image FROM base as build -# Install packages needed to build gems +# Install packages needed to build gems and node modules RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config + apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips node-gyp pkg-config python-is-python3 # Install application gems COPY Gemfile Gemfile.lock ./ @@ -27,6 +26,16 @@ RUN bundle install && \ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ bundle exec bootsnap precompile --gemfile +# Install node modules if package.json is present +COPY package.json yarn.lock ./ +RUN if [ -f package.json ]; then \ + curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \ + /tmp/node-build-master/bin/node-build "21.5.0" /usr/local/node && \ + npm install -g yarn@1.22.19 && \ + yarn install --frozen-lockfile && \ + rm -rf /tmp/node-build-master; \ + fi + # Copy application code COPY . . @@ -36,7 +45,6 @@ RUN bundle exec bootsnap precompile app/ lib/ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile - # Final stage for app image FROM base @@ -49,6 +57,9 @@ RUN apt-get update -qq && \ COPY --from=build /usr/local/bundle /usr/local/bundle COPY --from=build /rails /rails +# Ensure mini_racer is installed for ExecJS +RUN gem install mini_racer + # Run and own only the runtime files as a non-root user for security RUN useradd rails --create-home --shell /bin/bash && \ chown -R rails:rails db log storage tmp diff --git a/Gemfile b/Gemfile index 854cdbb..10e0a1b 100644 --- a/Gemfile +++ b/Gemfile @@ -82,3 +82,5 @@ gem "sidekiq" gem "ruby-vips", "~> 2.2" gem "stripe", "~> 12.3" + +gem "mini_racer" diff --git a/Gemfile.lock b/Gemfile.lock index fe948b0..e36971b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -158,6 +158,7 @@ GEM childprocess (~> 5.0) letter_opener (1.10.0) launchy (>= 2.2, < 4) + libv8-node (21.7.2.0-x86_64-linux) logger (1.6.0) loofah (2.22.0) crass (~> 1.0.2) @@ -171,6 +172,8 @@ GEM matrix (0.4.2) mini_magick (4.12.0) mini_mime (1.1.5) + mini_racer (0.12.0) + libv8-node (~> 21.7.2.0) minitest (5.24.0) msgpack (1.7.2) mutex_m (0.2.0) @@ -334,6 +337,7 @@ DEPENDENCIES importmap-rails jbuilder letter_opener + mini_racer pg (~> 1.1) puma (>= 5.0) rails (~> 7.1.3, >= 7.1.3.4) diff --git a/config/database.yml b/config/database.yml index c9f87a9..2311475 100644 --- a/config/database.yml +++ b/config/database.yml @@ -88,5 +88,6 @@ test: production: <<: *default database: ror_gen_ai_production - username: ror_gen_ai + username: postgres password: <%= ENV["ROR_GEN_AI_DATABASE_PASSWORD"] %> + host: <%= ENV["ROR_GEN_AI_DATABASE_HOST"] %> diff --git a/config/routes.rb b/config/routes.rb index ad6bedc..5e04f8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,10 @@ post "create_checkout_session" => "subscriptions#create_checkout_session", as: :create_checkout_session get "success" => "subscriptions#success" - mount Sidekiq::Web => "/sidekiq" + + if defined?(Sidekiq::Web) + mount Sidekiq::Web => "/sidekiq" + end # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html resource :session # where login and logout routes are defined