-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·84 lines (65 loc) · 1.77 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·84 lines (65 loc) · 1.77 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
83
84
#!/usr/bin/env bash
# bash options
set -o errexit
set -o nounset
# basic funtions
function log {
local -r level="$1"
shift
local -ra message=("$@")
local -r timestamp=$(date +"%Y-%m-%d %H:%M:%S")
local -r scriptname="$(basename "$0")"
>&2 echo -e "${timestamp} [${level}] [$scriptname] ${message[*]}"
}
function log_info {
local -ra message=("$@")
log "INFO" "${message[@]}"
}
function log_warn {
local -ra message=("$@")
log "WARN" "${message[@]}"
}
function log_error {
local -ra message=("$@")
log "ERROR" "${message[@]}"
}
if [ -z "${DB_USER}" ]; then
base_postgres_image_default_user='postgres'
export POSTGRES_USER="${base_postgres_image_default_user}"
fi
export DATABASE_URL="postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}"
# health of dependent services
postgres_ready() {
python << END
import sys
from psycopg2 import connect
from psycopg2.errors import OperationalError
try:
connect(
dbname="${DB_NAME}",
user="${DB_USER}",
password="${DB_PASSWORD}",
host="${DB_HOST}",
port="${DB_PORT}",
)
except OperationalError:
sys.exit(-1)
END
}
until postgres_ready; do
log_info "Waiting for PostgreSQL to become available"
sleep 5
done
log_info "PostgreSQL is available"
# idempotent Django commands
log_info "[run] make migrations"
python manage.py makemigrations || exit 1
log_info "[run] Migrate DB"
python manage.py migrate || exit 1
INITIAL_RUN_CHECK=$(python manage.py shell -c "from apps.user.models import User; print(User.objects.filter(is_superuser=True).exists())")
if [ "${INITIAL_RUN_CHECK}" == "False" ]; then
log_info "[run] Load initial data"
# Example
# python manage.py loaddata initial_data.json || exit 1
fi
python manage.py runserver 0.0.0.0:8000