Skip to content

Commit

Permalink
Fix config issue in production environment
Browse files Browse the repository at this point in the history
  • Loading branch information
aidewoode committed Nov 18, 2022
1 parent 4f04748 commit eee79d7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM ruby:3.1-alpine
FROM ruby:3.1.2-alpine

ENV LANG C.UTF-8

ENV RAILS_ENV production

ENV NODE_ENV production
ENV RAILS_SERVE_STATIC_FILES true

LABEL maintainer="[email protected]/aidewoode"

Expand All @@ -16,15 +15,15 @@ RUN apk add --no-cache \
yarn \
imagemagick \
ffmpeg \
nginx \
gcompat

WORKDIR /app

ADD . /app

RUN apk add --no-cache --virtual .build-deps build-base \
&& bundle install --without development test \
&& bundle config --local without 'development test' \
&& bundle install \
&& rm -rf /usr/local/bundle/cache/*.gem \
&& apk del --no-network .build-deps

Expand All @@ -33,8 +32,6 @@ RUN bundle exec rails assets:precompile SECRET_KEY_BASE=fake_secure_for_compile
&& yarn cache clean \
&& rm -rf node_modules tmp/cache/* /tmp/*

RUN cp config/nginx/nginx.conf /etc/nginx/nginx.conf

ENTRYPOINT ["docker/entrypoint.sh"]

EXPOSE 3000
Expand Down
7 changes: 6 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
config.log_tags = [:request_id]

# Use a different cache store in production.
config.cache_store = (ENV["REDIS_URL"].present? || ENV["REDIS_CACHE_URL"].present?) ? [:redis_cache_store, {url: ENV.fetch("REDIS_CACHE_URL", ENV["REDIS_URL"])}] : :file_store
config.cache_store = (ENV["REDIS_URL"].present? || ENV["REDIS_CACHE_URL"].present?) ?
[:redis_cache_store, {url: ENV.fetch("REDIS_CACHE_URL", ENV["REDIS_URL"])}] :
[:file_store, "#{root}/tmp/cache/"]

# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = (ENV["REDIS_URL"].present? || ENV["REDIS_SIDEKIQ_URL"].present?) ? :sidekiq : :async
Expand Down Expand Up @@ -72,4 +74,7 @@
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.active_record.async_query_executor = :global_thread_pool

# Disable warning of running SQLite in production
config.active_record.sqlite3_production_warning = false
end
2 changes: 1 addition & 1 deletion config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
embedded_sidekiq = Rails.configuration.active_job.queue_adapter == :sidekiq && ENV.fetch("EMBEDDED_SIDEKIQ", "true") == "true"
embedded_sidekiq = ENV.fetch("EMBEDDED_SIDEKIQ", "false") == "true"

# Accroding to the documentation, we should keep embedded sidekiq concurrency very low, i.e. 1-2
embedded_sidekiq_concurrency = [ENV.fetch("EMBEDDED_SIDEKIQ_CONCURRENCY", 2), 2].min
Expand Down
5 changes: 3 additions & 2 deletions docker/production_start.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh

# Prepare Database
rails db:prepare
# Prepare database. Beacuse when the database adapter is sqlite, the task 'db:prepare' won't run 'db:seed'.
# So add 'db:seed' task explicitly to avoit it. See https://github.com/rails/rails/issues/36383
rails db:prepare && rails db:seed

bundle exec puma -C config/puma.rb

0 comments on commit eee79d7

Please sign in to comment.