-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
dev-docker-entrypoint.sh
51 lines (39 loc) · 1.29 KB
/
dev-docker-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
unset BUNDLE_PATH
unset BUNDLE_BIN
set -e
echo "Environment: $RAILS_ENV"
# set env var defaults
DATABASE_HOST=${DATABASE_HOST:-"dawarich_db"}
DATABASE_PORT=${DATABASE_PORT:-5432}
DATABASE_USERNAME=${DATABASE_USERNAME:-"postgres"}
DATABASE_PASSWORD=${DATABASE_PASSWORD:-"password"}
DATABASE_NAME=${DATABASE_NAME:-"dawarich_development"}
# Remove pre-existing puma/passenger server.pid
rm -f $APP_PATH/tmp/pids/server.pid
# Wait for the database to be ready
until nc -zv $DATABASE_HOST ${DATABASE_PORT:-5432}; do
echo "Waiting for PostgreSQL to be ready..."
sleep 1
done
# Install gems
gem update --system 3.5.7
gem install bundler --version '2.5.9'
# Create the database
if [ "$(psql "postgres://$DATABASE_USERNAME:$DATABASE_PASSWORD@$DATABASE_HOST:$DATABASE_PORT" -XtAc "SELECT 1 FROM pg_database WHERE datname='$DATABASE_NAME'")" = '1' ]; then
echo "Database $DATABASE_NAME already exists, skipping creation..."
else
echo "Creating database $DATABASE_NAME..."
bundle exec rails db:create
fi
# Run database migrations
echo "PostgreSQL is ready. Running database migrations..."
bundle exec rails db:prepare
# Run data migrations
echo "Running DATA migrations..."
bundle exec rake data:migrate
# Run seeds
echo "Running seeds..."
bundle exec rake db:seed
# run passed commands
bundle exec ${@}