Skip to content

Commit

Permalink
Dev and test db script should not be run in other envs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrlc committed Oct 2, 2024
1 parent f8b68be commit 58d3bc5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -122,4 +122,4 @@ WORKDIR ${APP_PATH}

# Run the web server
EXPOSE 9292
ENTRYPOINT [ "docker/puma.sh" ]
ENTRYPOINT [ "docker/run.sh" ]
6 changes: 4 additions & 2 deletions docker/build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
6 changes: 0 additions & 6 deletions docker/db_prepare.sh

This file was deleted.

12 changes: 7 additions & 5 deletions docker/puma.sh → docker/run.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ 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

# Start the web server
mkdir -p ./tmp/pids
bundle exec puma -C config/puma.rb -e $RAILS_ENV

# Run commands
exec "$@"
18 changes: 18 additions & 0 deletions docker/run_dev.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 58d3bc5

Please sign in to comment.