Skip to content

Commit

Permalink
fix: DB, JS RunTime, Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarMWarraich committed Jul 24, 2024
1 parent 3a722c1 commit 0d24b17
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
19 changes: 15 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,29 @@ 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 ./
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 [email protected] && \
yarn install --frozen-lockfile && \
rm -rf /tmp/node-build-master; \
fi

# Copy application code
COPY . .

Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ gem "sidekiq"
gem "ruby-vips", "~> 2.2"

gem "stripe", "~> 12.3"

gem "mini_racer"
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] %>
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d24b17

Please sign in to comment.