From f8b68be99264e4b68780192b29f0a8d2c5b600ab Mon Sep 17 00:00:00 2001 From: Christina Cortland Date: Wed, 2 Oct 2024 11:47:55 -0400 Subject: [PATCH 1/3] Make sure bundle install is run before tests in docker --- Dockerfile | 4 ---- docker/build_test.sh | 5 ++++- docker/run_test.sh | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 015222f..08d00e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,11 +30,7 @@ FROM dev_base as test ENV RAILS_ENV=test \ APP_PATH=/exhibits -# Install application gems WORKDIR $APP_PATH -COPY Gemfile Gemfile.lock ./ -RUN bundle install - COPY . . ENTRYPOINT [ "docker/build_test.sh" ] diff --git a/docker/build_test.sh b/docker/build_test.sh index bc3e63c..73c8e46 100755 --- a/docker/build_test.sh +++ b/docker/build_test.sh @@ -2,8 +2,11 @@ set -e +# Install gems +bundle install + # Prepare DB (Migrate if exists; else Create db & Migrate) sh ./docker/db_prepare.sh -# Run the command defined in compose.test.yaml +# Run commands exec "$@" diff --git a/docker/run_test.sh b/docker/run_test.sh index bac39bc..8460fbf 100755 --- a/docker/run_test.sh +++ b/docker/run_test.sh @@ -9,7 +9,7 @@ done if [ $interactive = true ] then - docker compose -p exhibits-test -f compose.test.yaml run --entrypoint=bash webapp + docker compose -p exhibits-test -f compose.test.yaml run webapp bash else docker compose -p exhibits-test -f compose.test.yaml run webapp bundle exec rspec fi From 58d3bc5e209ef63d3925e8c512d2edbea694c82d Mon Sep 17 00:00:00 2001 From: Christina Cortland Date: Wed, 2 Oct 2024 12:15:27 -0400 Subject: [PATCH 2/3] Dev and test db script should not be run in other envs --- Dockerfile | 4 ++-- docker/build_test.sh | 6 ++++-- docker/db_prepare.sh | 6 ------ docker/{puma.sh => run.sh} | 12 +++++++----- docker/run_dev.sh | 18 ++++++++++++++++++ 5 files changed, 31 insertions(+), 15 deletions(-) delete mode 100755 docker/db_prepare.sh rename docker/{puma.sh => run.sh} (77%) mode change 100755 => 100644 create mode 100755 docker/run_dev.sh diff --git a/Dockerfile b/Dockerfile index 08d00e1..192d92c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,7 +60,7 @@ COPY --chown=${USER}:${GROUP} . . # Run the web server EXPOSE 9292 -ENTRYPOINT [ "docker/puma.sh" ] +ENTRYPOINT [ "docker/run_dev.sh" ] ################################################################################ # Bundle production/integration/staging environment @@ -122,4 +122,4 @@ WORKDIR ${APP_PATH} # Run the web server EXPOSE 9292 -ENTRYPOINT [ "docker/puma.sh" ] +ENTRYPOINT [ "docker/run.sh" ] diff --git a/docker/build_test.sh b/docker/build_test.sh index 73c8e46..9f7f33d 100755 --- a/docker/build_test.sh +++ b/docker/build_test.sh @@ -5,8 +5,10 @@ set -e # Install gems bundle install -# Prepare DB (Migrate if exists; else Create db & Migrate) -sh ./docker/db_prepare.sh +# If the database exists, migrate. Otherwise setup (create and migrate) +echo "Preparing Database..." +bundle exec rake db:environment:set RAILS_ENV=test db:migrate 2>/dev/null || bundle exec rake db:environment:set RAILS_ENV=test db:create db:schema:load +echo "Database Migration Done!" # Run commands exec "$@" diff --git a/docker/db_prepare.sh b/docker/db_prepare.sh deleted file mode 100755 index f975303..0000000 --- a/docker/db_prepare.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -# 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=$RAILS_ENV db:create db:schema:load -echo "Database Migration Done!" diff --git a/docker/puma.sh b/docker/run.sh old mode 100755 new mode 100644 similarity index 77% rename from docker/puma.sh rename to docker/run.sh index 47d8be0..5e39dc8 --- a/docker/puma.sh +++ b/docker/run.sh @@ -16,11 +16,10 @@ then cron fi -# Prepare DB (Migrate if exists; else Create db & Migrate) -sh ./docker/db_prepare.sh - -# Run the command defined in compose.yaml -exec "$@" +# Run db migrations +echo "Preparing Database..." +bundle exec rake db:migrate RAILS_ENV=$RAILS_ENV +echo "Database Migration Done!" # Start sidekiq bundle exec sidekiq -L log/sidekiq.log -e $RAILS_ENV -C config/sidekiq.yml -d @@ -28,3 +27,6 @@ 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 + +# Run commands +exec "$@" diff --git a/docker/run_dev.sh b/docker/run_dev.sh new file mode 100755 index 0000000..1b63869 --- /dev/null +++ b/docker/run_dev.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e + +# 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: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 + +# Run commands +exec "$@" From 86bbd51dd618dc86ad191a94eae1c78597a130ed Mon Sep 17 00:00:00 2001 From: Christina Cortland Date: Tue, 1 Oct 2024 17:26:12 -0400 Subject: [PATCH 3/3] letter_opener gem doesn't work well with docker --- Gemfile | 1 - Gemfile.lock | 3 --- config/environments/development.rb | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index d845293..a7e5005 100644 --- a/Gemfile +++ b/Gemfile @@ -53,7 +53,6 @@ gem 'blacklight-spotlight', '~> 3.5' group :development do gem 'better_errors' # add command line in browser when errors gem 'binding_of_caller' # deeper stack trace used by better errors - gem 'letter_opener' # show emails in browser gem 'listen' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index b2fc543..cb1358a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -356,8 +356,6 @@ GEM railties (>= 4.2.0) legato (0.7.0) multi_json - letter_opener (1.8.1) - launchy (>= 2.2, < 3) listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -713,7 +711,6 @@ DEPENDENCIES irb jbuilder (~> 2.5) jquery-rails - letter_opener listen mina mysql2 diff --git a/config/environments/development.rb b/config/environments/development.rb index 848a75d..cccc96a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -33,7 +33,7 @@ config.active_storage.service = :local # Configure Email Notifications - config.action_mailer.delivery_method = :letter_opener # Open emails in a web browser + config.action_mailer.delivery_method = :test config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_caching = false