天天看點

Dockerfile和supervisor部署項目配置檔案模闆

 Dockerfile模闆

FROM python:latest

WORKDIR /root/

RUN mkdir /etc/supervisor # 建立存放supervisor配置檔案的檔案夾
RUN mkdir -p /root/projects/logs/gunicorn/ # 建立gunicorn日志檔案夾 要和supervisor中gunicorn日志檔案路徑一緻
RUN mkdir -p /root/projects/logs/celery/ # 建立celery日志檔案夾 要和supervisor中celery日志檔案路徑一緻
ADD sy.ini /etc/supervisor/sy.ini # 複制本地的supervisor配置檔案到鏡像内

# 根據具體項目名稱替換Sy_EvaluateJkApi
ADD Sy_EvaluateJkApi /root/projects/Sy_EvaluateJkApi # 複制代碼到鏡像内
RUN pip3 install -r /root/projects/Sy_EvaluateJkApi/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ #安裝python相關包
RUN mkdir -p /root/projects/Sy_EvaluateJkApi/logs/ # 建立項目日志檔案夾


RUN pip install supervisor -i https://mirrors.aliyun.com/pypi/simple/
RUN pip install gunicorn -i https://mirrors.aliyun.com/pypi/simple/
RUN pip install gevent -i https://mirrors.aliyun.com/pypi/simple/
RUN pip install eventlet-i https://mirrors.aliyun.com/pypi/simple/
RUN /usr/local/bin/echo_supervisord_conf > /etc/supervisor/supervisord.conf
RUN echo "[include]">>/etc/supervisor/supervisord.conf
RUN echo "files = /etc/supervisor/*.ini">>/etc/supervisor/supervisord.conf

EXPOSE 8800 # 容器暴露的端口與sy.ini内啟動項目的端口必須一緻
CMD ["supervisord","-n","-c","/etc/supervisor/supervisord.conf"]
           

supervisor配置檔案檔案模闆

[group:sy_group]
programs=sy,celery_work,celery_beat
priority=5


[program:sy]
command=gunicorn --limit-request-line 8188  -w 1 -k gevent -b 0.0.0.0:8800 EvaluateJK.wsgi -e DJANGO_SETTINGS_MODULE=EvaluateJK.settings.dev
directory=/root/projects/Sy_EvaluateJkApi                ; directory to cwd to before exec (def no cwd)
priority=5                  ; the relative start priority (default 999)
autostart=true                ; start at supervisord start (default: true)
startsecs=15                   ; # of secs prog must stay up to be running (def. 1)
startretries=3                ; max # of serial start failures when starting (default 3)
autorestart=true        ; when to restart if exited after running (def: unexpected)
stopsignal=QUIT               ; signal used to kill process (default TERM)
stopwaitsecs=0               ; max num secs to wait b4 SIGKILL (default 10)
user=root                   ; setuid to this UNIX account to run the program
stdout_logfile=/root/projects/logs/gunicorn/sy_success.log        ; stdout log path, NONE for none; default AUTO
stderr_logfile=/root/projects/logs/gunicorn/sy_error.err        ; stderr log path, NONE for none; default AUTO

[program:celery_work]
command=celery -A EvaluateJK worker -l info -P eventlet --logfile=/root/projects/logs/celery/celery_worker.log
directory=/root/projects/Sy_EvaluateJkApi
priority=5                  ; the relative start priority (default 999)
startsecs=15                   ; # of secs prog must stay up to be running (def. 1)
startretries=3                ; max # of serial start failures when starting (default 3)
autorestart=true        ; when to restart if exited after running (def: unexpected)
stopsignal=QUIT               ; signal used to kill process (default TERM)
stopwaitsecs=0               ; max num secs to wait b4 SIGKILL (default 10)
user=root                   ; setuid to this UNIX account to run the program
stdout_logfile=/root/projects/logs/celery/celery.log
stderr_logfile=/root/projects/logs/celery/celery.err

[program:celery_beat]
command=celery -A EvaluateJK beat -l info --logfile=/root/projects/logs/celery/celery_beat.log
directory=/root/projects/Sy_EvaluateJkApi
priority=5                  ; the relative start priority (default 999)
startsecs=15                   ; # of secs prog must stay up to be running (def. 1)
startretries=3                ; max # of serial start failures when starting (default 3)
autorestart=true        ; when to restart if exited after running (def: unexpected)
stopsignal=QUIT               ; signal used to kill process (default TERM)
stopwaitsecs=0               ; max num secs to wait b4 SIGKILL (default 10)
user=root                   ; setuid to this UNIX account to run the program
stdout_logfile=/root/projects/logs/celery/celery_beat.log
stderr_logfile=/root/projects/logs/celery/celery_beat.err
           

繼續閱讀