diff --git a/Dockerfile b/Dockerfile index f0d54e9..295db70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,30 @@ -# 使用基础镜像库 -FROM alpine:3.8 -RUN echo -e http://mirrors.ustc.edu.cn/alpine/v3.7/main/ > /etc/apk/repositories +# nginx-gunicorn-flask -RUN apk add --no-cache vim nginx python3 uwsgi uwsgi-python3 -RUN apk add --update --upgrade -RUN apk add --no-cache nginx python3 uwsgi uwsgi-python3 -RUN pip3 install --no-cache-dir --upgrade pip -RUN ln -s /usr/bin/python3 /usr/bin/python +FROM ubuntu:latest +MAINTAINER Hiller Liao +ENV DEBIAN_FRONTEND noninteractive - -# 创建工作路径 -RUN mkdir /app - -# 指定容器启动时执行的命令都在app目录下执行 -WORKDIR /app - -# 替换nginx的配置 -COPY nginx.conf /etc/nginx/nginx.conf - -# 将本地目录下的内容拷贝到容器的app目录下 -COPY . /app/ +RUN apt-get update +RUN apt-get install -y python3 python3-pip python3-virtualenv nginx supervisor -RUN apk update -RUN apk add --no-cache gcc musl-dev libxml2 libxslt-dev -# pip读取requirements.txt内容安装所需的库 -RUN pip install -r /app/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple some-package --no-cache-dir - -# 启动nginx和uwsgi -# ENTRYPOINT nginx -g "daemon on;" && uwsgi --ini /app/uwsgi.ini -ENTRYPOINT nginx -g "daemon on;" && gunicorn -w 4 wsgi:app \ No newline at end of file +# Setup flask application +RUN mkdir -p /app +COPY . /app +RUN pip install -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple +RUN pip install gunicorn +# RUN pip install git+https://github.com/getsyncr/notion-sdk.git + +# Setup nginx +RUN rm /etc/nginx/sites-enabled/default +COPY flask.conf /etc/nginx/sites-available/ +RUN ln -s /etc/nginx/sites-available/flask.conf /etc/nginx/sites-enabled/flask.conf +RUN echo "daemon off;" >> /etc/nginx/nginx.conf + +# Setup supervisord +RUN mkdir -p /var/log/supervisor +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY gunicorn.conf /etc/supervisor/conf.d/gunicorn.conf + +# Start processes +CMD ["/usr/bin/supervisord"] diff --git a/Dockerfile.old b/Dockerfile.old new file mode 100644 index 0000000..f0d54e9 --- /dev/null +++ b/Dockerfile.old @@ -0,0 +1,32 @@ +# 使用基础镜像库 +FROM alpine:3.8 +RUN echo -e http://mirrors.ustc.edu.cn/alpine/v3.7/main/ > /etc/apk/repositories + +RUN apk add --no-cache vim nginx python3 uwsgi uwsgi-python3 +RUN apk add --update --upgrade +RUN apk add --no-cache nginx python3 uwsgi uwsgi-python3 +RUN pip3 install --no-cache-dir --upgrade pip +RUN ln -s /usr/bin/python3 /usr/bin/python + + + +# 创建工作路径 +RUN mkdir /app + +# 指定容器启动时执行的命令都在app目录下执行 +WORKDIR /app + +# 替换nginx的配置 +COPY nginx.conf /etc/nginx/nginx.conf + +# 将本地目录下的内容拷贝到容器的app目录下 +COPY . /app/ + +RUN apk update +RUN apk add --no-cache gcc musl-dev libxml2 libxslt-dev +# pip读取requirements.txt内容安装所需的库 +RUN pip install -r /app/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple some-package --no-cache-dir + +# 启动nginx和uwsgi +# ENTRYPOINT nginx -g "daemon on;" && uwsgi --ini /app/uwsgi.ini +ENTRYPOINT nginx -g "daemon on;" && gunicorn -w 4 wsgi:app \ No newline at end of file diff --git a/flask.conf b/flask.conf new file mode 100644 index 0000000..8b7e22a --- /dev/null +++ b/flask.conf @@ -0,0 +1,8 @@ +server { + listen 80; + location / { + proxy_pass http://localhost:5000/; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} \ No newline at end of file diff --git a/gunicorn.conf b/gunicorn.conf new file mode 100644 index 0000000..4c493c1 --- /dev/null +++ b/gunicorn.conf @@ -0,0 +1,3 @@ +[program:gunicorn] +command=/usr/local/bin/gunicorn wsgi:app -b localhost:5000 +directory=/deploy/app \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2d49328..1b66a75 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..3dbc3ec --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,5 @@ +[supervisord] +nodaemon=true + +[program:nginx] +command=/usr/sbin/nginx \ No newline at end of file