Browse Source

change gunicorn

Zhang Li 2 years ago
parent
commit
bab81ff263
5 changed files with 14 additions and 9 deletions
  1. 3 4
      Dockerfile
  2. 1 1
      Makefile
  3. 6 0
      README.md
  4. 3 4
      cpu.Dockerfile
  5. 1 0
      environment.yml

+ 3 - 4
Dockerfile

@@ -53,6 +53,7 @@ RUN conda install mamba -n base -c conda-forge
 RUN ln /opt/conda/bin/mamba /usr/local/bin/mamba && mamba init zsh
 
 
+
 FROM builder1 as builder2
 
 RUN apt-get update && apt-get install -y --no-install-recommends openssh-server && rm -rf /var/lib/apt/lists/*
@@ -72,7 +73,6 @@ redirect_stderr = true\n\
 
 EXPOSE 22
 
-
 FROM builder2 as builder3
 
 WORKDIR /workspace
@@ -80,13 +80,12 @@ ADD environment.yml /environment.yml
 RUN sed -i 's#- paddlepaddle#- paddlepaddle-gpu==2.3.0.post110#g' /environment.yml && cat /environment.yml
 RUN mamba update -n base -c defaults conda -y && mamba env create -f /environment.yml && rm -rf /root/.cache
 
-
 # RUN /opt/conda/envs/py38/bin/python -m ipykernel install --name py38 --display-name "py38"
 # RUN echo "c.MultiKernelManager.default_kernel_name = 'py38'">>/root/.jupyter/jupyter_notebook_config.py
 RUN echo "\
 [program:be]\n\
 directory=/workspace\n\
-command=/opt/conda/envs/py38/bin/python server.py --host 0.0.0.0 --port 8080 \n\
+command=/opt/conda/envs/py38/bin/gunicorn server:app --workers 1 --worker-class=uvicorn.workers.UvicornWorker  --bind 0.0.0.0:8080 --reload \n\
 autorestart=true\n\
 startretries=0\n\
 redirect_stderr=true\n\
@@ -96,11 +95,11 @@ stdout_logfile_maxbytes=0\n\
 
 ARG VERSION
 ENV USE_CUDA $VERSION
-
 Add . /workspace
 EXPOSE 8080
 
 
+
 # RUN mamba install -y jupyterlab -n base && mamba init zsh
 # RUN /opt/conda/bin/jupyter notebook --generate-config && \
 #     echo "c.NotebookApp.password='argon2:\$argon2id\$v=19\$m=10240,t=10,p=8\$+zIUCF9Uk2FiCHlV8njX5A\$I5Mm/64DORArcXYTXWRVng'">>/root/.jupyter/jupyter_notebook_config.py

+ 1 - 1
Makefile

@@ -7,7 +7,7 @@ AUTHOR          := $(shell git show -s --format='%an')
 
 .PHONY: all cpu gpu
 
-all: cpu gpu
+all: gpu cpu
 gpu:
 	@docker build -t registry.cn-hangzhou.aliyuncs.com/sxtest/$(NAME):gpu --build-arg VERSION=gpu .
 	@docker push registry.cn-hangzhou.aliyuncs.com/sxtest/$(NAME):gpu

+ 6 - 0
README.md

@@ -36,4 +36,10 @@ python server.py --port 8080
 
 ```shell
  python -m unittest discover testing '*_test.py' -v
+```
+
+## 镜像打包
+
+```shell
+make all
 ```

+ 3 - 4
cpu.Dockerfile

@@ -53,6 +53,7 @@ RUN conda install mamba -n base -c conda-forge
 RUN ln /opt/conda/bin/mamba /usr/local/bin/mamba && mamba init zsh
 
 
+
 FROM builder1 as builder2
 
 RUN apt-get update && apt-get install -y --no-install-recommends openssh-server && rm -rf /var/lib/apt/lists/*
@@ -72,20 +73,18 @@ redirect_stderr = true\n\
 
 EXPOSE 22
 
-
 FROM builder2 as builder3
 
 WORKDIR /workspace
 ADD environment.yml /environment.yml
 RUN mamba update -n base -c defaults conda -y && mamba env create -f /environment.yml && rm -rf /root/.cache
 
-
 # RUN /opt/conda/envs/py38/bin/python -m ipykernel install --name py38 --display-name "py38"
 # RUN echo "c.MultiKernelManager.default_kernel_name = 'py38'">>/root/.jupyter/jupyter_notebook_config.py
 RUN echo "\
 [program:be]\n\
 directory=/workspace\n\
-command=/opt/conda/envs/py38/bin/python server.py --host 0.0.0.0 --port 8080 \n\
+command=/opt/conda/envs/py38/bin/gunicorn server:app --workers 1 --worker-class=uvicorn.workers.UvicornWorker  --bind 0.0.0.0:8080 --reload \n\
 autorestart=true\n\
 startretries=0\n\
 redirect_stderr=true\n\
@@ -95,11 +94,11 @@ stdout_logfile_maxbytes=0\n\
 
 ARG VERSION
 ENV USE_CUDA $VERSION
-
 Add . /workspace
 EXPOSE 8080
 
 
+
 # RUN mamba install -y jupyterlab -n base && mamba init zsh
 # RUN /opt/conda/bin/jupyter notebook --generate-config && \
 #     echo "c.NotebookApp.password='argon2:\$argon2id\$v=19\$m=10240,t=10,p=8\$+zIUCF9Uk2FiCHlV8njX5A\$I5Mm/64DORArcXYTXWRVng'">>/root/.jupyter/jupyter_notebook_config.py

+ 1 - 0
environment.yml

@@ -20,6 +20,7 @@ dependencies:
       - python-multipart
       - requests
       - cpca
+      - gunicorn
       - -i https://mirror.baidu.com/pypi/simple
       - paddlepaddle  # gpu==2.3.0.post110
       - -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html