Skip to content

Commit

Permalink
Merge pull request #694 from cul-it/LP-1155-sidekiq-stdout
Browse files Browse the repository at this point in the history
LP-1155: Set up sidekiq service
  • Loading branch information
chrisrlc authored Dec 2, 2024
2 parents 7b8a7dd + 89f3d64 commit c7a4f7f
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 18 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ WORKDIR ${APP_PATH}
COPY ./Gemfile ./Gemfile.lock ./
RUN bundle config set --local with "${RAILS_ENV}" && \
bundle config set --local without "${BUNDLE_WITHOUT}" && \
bundle config set --local path "${BUNDLE_PATH}" && \
bundle install && \
gem install aws-sdk-s3 && \
rm -rf ${BUNDLE_PATH}/cache/*.gem && \
find ${BUNDLE_PATH}/ -name "*.c" -delete && \
find ${BUNDLE_PATH}/ -name "*.o" -delete

COPY . .
RUN bundle exec rake assets:precompile && rm .env
RUN rm .env

################################################################################
# Final image for integration/staging/production
Expand All @@ -102,9 +103,7 @@ ENV RAILS_ENV=${RAILS_ENV} \
# exhibits_cron - .ebextentions/tmp_cleanup.config
# localtime adjustment - .ebextentions/system_time.config
COPY ./cron/exhibits_cron /etc/cron.d/exhibits_cron
RUN groupadd -r $GROUP && useradd -r -g $GROUP $USER && \
mkdir -p /home/${USER} && \
chown ${USER}:${GROUP} /home/${USER} && \
RUN groupadd -r $GROUP && useradd -mr -g $GROUP $USER && \
chmod gu+rw /var/run && chmod gu+s /usr/sbin/cron && \
crontab -u root /etc/cron.d/exhibits_cron && \
ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
Expand Down
18 changes: 17 additions & 1 deletion compose.integration.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Docker compose file for integration environment
# Run with: docker compose up
# Run with: docker compose -f compose.integration.yaml up
#
# For local development testing of the integration container:
# consider setting up a redis container, instead of connecting to the remote redis host.

services:
webapp:
Expand All @@ -18,3 +21,16 @@ services:
- PORT=9292
ports:
- 9292:9292
depends_on:
- sidekiq

sidekiq:
build:
context: .
args:
BUNDLE_WITHOUT: "development test"
RACK_ENV: integration
RAILS_ENV: integration
entrypoint: docker/run_sidekiq.sh
env_file:
- .env
15 changes: 14 additions & 1 deletion compose.production.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Docker compose file for production environment
# Run with: docker compose up
# Run with: docker compose -f compose.production.yaml up

services:
webapp:
Expand All @@ -16,3 +16,16 @@ services:
- PORT=9292
ports:
- 9292:9292
depends_on:
- sidekiq

sidekiq:
build:
context: .
args:
BUNDLE_WITHOUT: "development integration test"
RACK_ENV: production
RAILS_ENV: production
entrypoint: docker/run_sidekiq.sh
env_file:
- .env
15 changes: 14 additions & 1 deletion compose.staging.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Docker compose file for staging environment
# Run with: docker compose up
# Run with: docker compose -f compose.production.yaml up

services:
webapp:
Expand All @@ -16,3 +16,16 @@ services:
- PORT=9292
ports:
- 9292:9292
depends_on:
- sidekiq

sidekiq:
build:
context: .
args:
BUNDLE_WITHOUT: "development test"
RACK_ENV: staging
RAILS_ENV: staging
entrypoint: docker/run_sidekiq.sh
env_file:
- .env
11 changes: 11 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
- mysql
- redis
- solr
- sidekiq

mysql:
image: mariadb:10.6
Expand Down Expand Up @@ -55,6 +56,16 @@ services:
volumes:
- redis:/data

sidekiq:
build:
context: .
target: development
entrypoint: docker/run_sidekiq.sh
depends_on:
- redis
env_file:
- .env

volumes:
db-data:
gems:
Expand Down
7 changes: 6 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@

config.active_job.queue_adapter = :sidekiq
# config.active_job.queue_name_prefix = "exhibits_#{Rails.env}"
config.debug_logger = Logger.new(Rails.root.join('log', 'debug.log'))

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = ::Logger::Formatter.new
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# provides access to IRB console on exception pages
# config.web_console.whitelisted_ips = ENV['IP_WHITELIST'] if ENV['IP_WHITELIST'].present?
Expand Down
1 change: 0 additions & 1 deletion config/environments/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.debug_logger = Logger.new(Rails.root.join('log', 'debug.log'))

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
Expand Down
1 change: 0 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.debug_logger = Logger.new(Rails.root.join('log', 'debug.log'))

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
Expand Down
1 change: 0 additions & 1 deletion config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.debug_logger = Logger.new(Rails.root.join('log', 'debug.log'))

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
Expand Down
10 changes: 6 additions & 4 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ then
fi

# Run db migrations
echo "Preparing Database..."
echo "Preparing database..."
bundle exec rake db:migrate RAILS_ENV=$RAILS_ENV
echo "Database Migration Done!"
echo "Database migration done!"

# Start sidekiq
bundle exec sidekiq -L log/sidekiq.log -e $RAILS_ENV -C config/sidekiq.yml -d
# Precompile assets
echo "Compiling assets..."
bundle exec rake assets:precompile
echo "Compiling assets done!"

# Start the web server
mkdir -p ./tmp/pids
Expand Down
6 changes: 3 additions & 3 deletions docker/run_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

set -e

# Direct logs to stdout
export RAILS_LOG_TO_STDOUT="1"

# If the database exists, migrate. Otherwise setup (create and migrate)
echo "Preparing Database..."
bundle exec rake db:migrate 2>/dev/null || bundle exec rake db:environment:set RAILS_ENV=development db:create db:schema:load
echo "Database Migration Done!"

# Start sidekiq
bundle exec sidekiq -L log/sidekiq.log -e $RAILS_ENV -C config/sidekiq.yml -d

# Start the web server
mkdir -p ./tmp/pids
bundle exec puma -C config/puma.rb -e $RAILS_ENV
Expand Down
17 changes: 17 additions & 0 deletions docker/run_sidekiq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

# Get environment variables
WORKDIR="/exhibits"
ENVFILE="${WORKDIR}/.env"
if [ ! -f "$ENVFILE" ]; then
ruby docker/get_env.rb $RAILS_ENV $WORKDIR
fi

# Start sidekiq
echo "Starting up sidekiq..."
bundle exec sidekiq -e $RAILS_ENV -C config/sidekiq.yml

# Run commands
exec "$@"

0 comments on commit c7a4f7f

Please sign in to comment.