File tree 3 files changed +61
-13
lines changed
3 files changed +61
-13
lines changed Original file line number Diff line number Diff line change @@ -19,15 +19,14 @@ COPY ./ /tmp
19
19
20
20
RUN set -ex && \
21
21
apk add --no-cache --virtual .build-deps gcc py-pip python-dev musl-dev && \
22
- pip list && \
23
- pip install '/tmp' && \
22
+ pip --no-cache-dir install '/tmp' && \
24
23
apk del .build-deps
25
24
26
25
VOLUME "/usr/lib/pypi-server"
27
26
28
- COPY docker-entrypoint.sh / entrypoint.sh
29
- RUN rm -rf /root/.cache /var/cache/*
27
+ COPY docker-entrypoint.py /usr/local/bin/ entrypoint.py
28
+ RUN chmod a+x /usr/local/bin/entrypoint.py
30
29
31
30
EXPOSE 80
32
31
33
- ENTRYPOINT ["/entrypoint.sh " ]
32
+ ENTRYPOINT ["/usr/local/bin/ entrypoint.py " ]
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+ import socket
3
+ import os
4
+ import sys
5
+ import logging
6
+ from time import sleep
7
+ from distutils import spawn
8
+
9
+ try :
10
+ from urlparse import urlparse as parse_url
11
+ except ImportError :
12
+ from urllib .parse import urlsplit as parse_url
13
+
14
+ logging .basicConfig (level = logging .INFO )
15
+ log = logging .getLogger ()
16
+
17
+
18
+ def check_port (host , port ):
19
+ sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
20
+ return sock .connect_ex ((host , port )) == 0
21
+
22
+
23
+ DEFAULT_PORTS = {
24
+ 'postgres' : 5432 ,
25
+ 'postgresql' : 5432 ,
26
+ 'mysql' : 3306 ,
27
+ }
28
+
29
+
30
+ if __name__ == '__main__' :
31
+ args = sys .argv [1 :]
32
+
33
+ if not args or args [0 ].startswith ('-' ):
34
+ db_url = parse_url (os .getenv ('DB' , '' ))
35
+ host = db_url .hostname
36
+ port = int (db_url .port or DEFAULT_PORTS [db_url .scheme ])
37
+
38
+ args .insert (0 , '/usr/bin/pypi-server' )
39
+
40
+ while not check_port (db_url .hostname , port ):
41
+ log .info ('Awaiting database...' )
42
+ sleep (1 )
43
+ continue
44
+
45
+ # Ensure database engine is ready
46
+ sleep (5 )
47
+
48
+ executable = args [0 ]
49
+
50
+ if not executable .startswith ('/' ):
51
+ executable = spawn .find_executable (executable )
52
+
53
+ if not executable or not os .path .exists (executable ):
54
+ log .error ('Command not found' )
55
+ exit (127 )
56
+
57
+ os .execv (executable , args )
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments