-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·82 lines (62 loc) · 2.1 KB
/
entrypoint.sh
File metadata and controls
executable file
·82 lines (62 loc) · 2.1 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -e
bun_set_up() {
bundle exec bun install
bundle exec bun run build
bundle exec bun run build:css
bunx cowsay 'Я, как его утилита, утверждаю, что Bun установлен!'
}
check_and_create_db() {
DB_HOST=db
POSTGRES_USER=user
POSTGRES_PASSWORD=password
DB_NAME=$1
SERVICE_TYPE=$2
DB_EXIST=$(PGPASSWORD=$POSTGRES_PASSWORD psql -h $DB_HOST -U $POSTGRES_USER -lqt | cut -d \| -f 1 | grep -w $DB_NAME | wc -l)
echo "Checking if $DB_NAME exists..."
if [ "$DB_EXIST" -eq 0 ]; then
echo "Database $DB_NAME does not exist. Creating..."
RAILS_ENV=$SERVICE_TYPE bundle exec rake db:create db:migrate
if [[ "$SERVICE_TYPE" != "test" ]]; then
echo "Seeding database..."
RAILS_ENV=$SERVICE_TYPE bundle exec rake db:seed
fi
touch /opt/app-initialized/$DB_NAME-initialized
echo "Database $DB_NAME created and seeded (if applicable)."
else
echo "Database $DB_NAME already exists."
if [ ! -f /opt/app-initialized/$DB_NAME-initialized ]; then
echo "Running migrations and seeding (if applicable) for $DB_NAME..."
RAILS_ENV=$SERVICE_TYPE bundle exec rake db:migrate
if [[ "$SERVICE_TYPE" != "test" ]]; then
RAILS_ENV=$SERVICE_TYPE bundle exec rake db:seed
fi
touch /opt/app-initialized/$DB_NAME-initialized
else
echo "Running migrations for $DB_NAME..."
RAILS_ENV=$SERVICE_TYPE bundle exec rake db:migrate
fi
fi
}
if [ "$1" == "tests" ]; then
echo "No command specified, running tests by default..."
echo "Waiting for PostgreSQL to become available..."
until pg_isready -h db -p 5432 -U user; do
sleep 2
done
# check_and_create_db "docker_chat_test" "test"
bin/rails db:environment:set RAILS_ENV=test
RAILS_ENV=test bundle exec rake db:drop db:create db:migrate
echo "PostgreSQL is available now."
echo "Running tests..."
bundle exec cucumber
INSPECTOR=true bundle exec rspec -f d
exit 0
fi
if [ -f tmp/pids/server.pid ]; then
rm tmp/pids/server.pid
fi
bun_set_up
check_and_create_db
bundle exec rails assets:precompile
exec "$@"