-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·33 lines (29 loc) · 1.39 KB
/
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
#!/bin/sh
set -e
# prime the DB to be sure that it is up and running
printf "import os\nimport time\n\nimport psycopg2\n\n\ndef primes():\n \
def connect():\n connection = None\n \
host, database = os.getenv('POSTGRES_HOST'), os.getenv('POSTGRES_DB')\n \
user, password = os.getenv('POSTGRES_USER'), os.getenv('POSTGRES_PASSWORD')\n\n \
try:\n \
connection = psycopg2.connect(\n \
**{\n \
'host': host,\n \
'database': database,\n \
'user': user,\n \
'password': password,\n \
}\n )\n return True\n \
except (Exception,):\n \
return False\n finally:\n if connection:\n \
connection.close()\n\n while True:\n if connect():\n \
break\n\n print('sleeping for 3s..')\n time.sleep(3)\n\n\nprimes()" \
| /usr/bin/env python3 > /dev/null 2>&1
# a hack to run migrations
printf 'import os\nimport subprocess\n\n\nwith open(os.devnull, "w") as pipe:\n \
subprocess.call(["flask", b"dbm"], stdout=pipe, stderr=subprocess.STDOUT)\n \
subprocess.call(["flask", b"dbu-no-sql"], stdout=pipe, stderr=subprocess.STDOUT)' \
| /usr/bin/env python3
if [ "$1" = 'supervisord' ]; then
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi
exec "$@"