add dockerfiles

This commit is contained in:
zema1
2017-10-23 20:59:44 +08:00
parent 1b0952cd0d
commit e8841eae82
13 changed files with 67 additions and 65 deletions

View File

@@ -1,10 +1,13 @@
FROM python:3.6-alpine3.6
ADD requirements.txt /tmp
RUN apk add --no-cache --virtual .build-deps build-base jpeg-dev zlib-dev postgresql-dev && \
pip install -r /tmp/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple && \
apk del .build-deps --purge
ENV OJ_ENV production
RUN apk add --no-cache nginx supervisor jpeg-dev zlib-dev postgresql-dev freetype-dev
Volume ["/app"]
ADD requirements.txt /tmp
RUN apk add --no-cache build-base && \
pip install --no-cache-dir -r /tmp/requirements.txt -i https://pypi.doubanio.com/simple && \
apk del build-base --purge
VOLUME [ "/app" ]
CMD sh /app/deploy/run.sh

View File

@@ -46,7 +46,7 @@ http {
# Timeout for keep-alive connections. Server will close connections after
# this time.
keepalive_timeout 65;
keepalive_timeout 10;
# Sendfile copies data between one FD and other from within the kernel,
# which is more efficient than read() + write().
@@ -89,12 +89,11 @@ http {
# Sets the path, format, and configuration for a buffered log write.
# access_log /var/log/nginx/access.log main;
access_log off
access_log off;
server {
listen 80 default_server;
server_name _;
keetalive_timeout 5;
location /static/avatar {
expires max;

View File

@@ -13,3 +13,5 @@ flake8-coding
requests
django-redis
psycopg2
gunicorn
jsonfield

View File

@@ -12,11 +12,29 @@ fi
cd $BASE
find . -name "*.pyc" -delete
chown -R nobody:nogroup $BASE/log
# wait for postgresql start
sleep 5
n=0
while [ $n -lt 3 ]
do
python manage.py migrate
if [ $? -ne 0 ]; then
echo "Can't start server"
exit 1
echo "Can't start server, try again in 3 seconds.."
sleep 3
let "n+=1"
continue
fi
python manage.py initadmin
python manage.py runserver 0.0.0.0:8080
break
done
if [ $n -eq 3 ]; then
echo "Can't start server, please check log file for details."
exit 1
fi
exec supervisord -c /app/deploy/supervisor.conf

View File

@@ -11,7 +11,7 @@ childlogdir=/app/log/
serverurl=unix:///tmp/supervisor.sock
[program:gunicorn]
command=gunicorn oj.wsgi --user nobody -b 127.0.0.1:8080 --reload -w `grep -c ^processor /proc/cpuinfo`
command=sh -c "gunicorn oj.wsgi --user nobody -b 127.0.0.1:8080 --reload -w `grep -c ^processor /proc/cpuinfo`"
directory=/app/
stdout_logfile=/app/log/gunicorn.log
stderr_logfile=/app/log/gunicorn.log
@@ -21,7 +21,7 @@ startsecs=5
stopwaitsecs = 5
killasgroup=true
[program:task_queue]
[program:celery]
command=celery -A oj worker -l warning
directory=/app/
user=nobody
@@ -42,4 +42,4 @@ autostart=true
autorestart=true
startsecs=5
stopwaitsecs = 5
killasgroup=true
killasgroup=true