forked from astuto/astuto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-entrypoint.sh
executable file
·53 lines (45 loc) · 1.3 KB
/
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
52
53
#!/bin/bash
# This file serves 3 use cases:
# 1: if the env variable UPDATE is 1, db is prepared
# 2: if a command was supplied, it is executed
# 3: otherwise, check env variable ENVIRONMENT and launch server
# Exit immediately if a command exits with a non-zero status.
set -e
# Check environment variables
/bin/bash ./check-env.sh
# Remove a potentially pre-existing server.pid for Rails.
rm -f $APP_ROOT/tmp/pids/server.pid
# Use case 1
if [ "$UPDATE" = 1 ]; then
# Create database, load schema, run migrations and seed data in an idempotent way.
echo "Preparing database..."
db_version=$(bundle exec rake db:version)
echo "$db_version"
if [ "$db_version" = "Current version: 0" ]; then
bundle exec rake db:create
bundle exec rake db:schema:load
bundle exec rake db:migrate
bundle exec rake db:seed
else
bundle exec rake db:migrate
fi
echo "Database prepared."
exit 0
fi
# Use case 2
if [ ! $# -eq 0 ]; then
exec "$@"
exit 0
fi
# Use case 3
echo "Environment is: $ENVIRONMENT"
export RAILS_ENV="$ENVIRONMENT"
export NODE_ENV="$ENVIRONMENT"
if [ $ENVIRONMENT == "development" ]; then
# Launch Rails server and webpack-dev-server using Foreman
foreman start -p 3000
else # production
# Compile assets and launch server
rails assets:precompile
rails server -e production
fi