dm/python/Dockerfile

42 lines
1.4 KiB
Docker

#flask-app
FROM base
# 创建一个用户运行flask
RUN useradd -m -s /bin/bash flask && \
chown -R flask:flask /home/flask && \
mkdir -p /var/log/flask-app && touch /var/log/flask-app/flask-app.err.log && touch /var/log/flask-app/flask-app.out.log && \
chown -R flask:flask /var/log/flask-app \
&& apt-get -y update \
&& apt-get install -y --no-install-recommends \
python3 python3-dev python3-pip python3-venv libssl-dev \
&& apt-get clean \
&& rm -rf /config/* /tmp/* /var/lib/apt/lists/* /var/tmp/* \
&& pip install --upgrade pip
WORKDIR /home/flask
USER flask
# 复制
COPY --chown=flask:flask . .
# venv
ENV VIRTUAL_ENV=/home/flask/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# 安装包
COPY --from=build-dmpython --chown=flask:flask /home/dmdba/build_artifacts/dmPython-2.5.5-cp310-cp310-linux_x86_64.whl .
RUN python3 -m venv "$VIRTUAL_ENV" && \
pip3 config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple && \
export FLASK_APP=app.py && \
pip3 install dmPython-2.5.5-cp310-cp310-linux_x86_64.whl && rm dmPython-2.5.5-cp310-cp310-linux_x86_64.whl && \
MAKEFLAGS="-j$(nproc)" pip install -r requirements.txt
COPY --from=build-dmpython /home/dmdba/build_artifacts/libdmdpi.so /usr/lib/
COPY --from=build-frontend /usr/src/app/build/ /home/flask/public/
# 暴露端口
EXPOSE 8000 22 8765
USER root
CMD ["gunicorn", "-w", "3", "-t", "60", "-b", "0.0.0.0:8000", "app:app"]