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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章