-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathdocker-entrypoint.py
executable file
·64 lines (47 loc) · 1.45 KB
/
docker-entrypoint.py
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
#!/usr/bin/env python3
import socket
import os
import sys
import logging
from time import sleep
from distutils import spawn
try:
from urlparse import urlparse as parse_url
except ImportError:
from urllib.parse import urlsplit as parse_url
logging.basicConfig(level=logging.INFO)
log = logging.getLogger()
def check_port(host, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
return sock.connect_ex((host, port)) == 0
DEFAULT_PORTS = {
'postgres': 5432,
'postgresql': 5432,
'mysql': 3306,
}
if __name__ == '__main__':
args = sys.argv[1:]
if not args or args[0].startswith('-'):
db_url = parse_url(os.getenv(
'DB', "sqlite:///var/lib/pypi-server/pypi-server.sqlite3"
))
host = db_url.hostname
if 'sqlite' in db_url.scheme.lower():
port = None
else:
port = int(db_url.port or DEFAULT_PORTS[db_url.scheme])
args.insert(0, '/usr/bin/pypi-server')
while port and not check_port(db_url.hostname, port):
log.info('Awaiting database...')
sleep(1)
continue
# Ensure database engine is ready
if port:
sleep(5)
executable = args[0]
if not executable.startswith('/'):
executable = spawn.find_executable(executable)
if not executable or not os.path.exists(executable):
log.error('Command not found')
exit(127)
os.execv(executable, args)