【问题标题】:Is there a way to install packages in app engine once to avoid the long deploy each time?有没有办法在应用引擎中安装一次软件包以避免每次长时间部署?
【发布时间】:2019-06-19 14:36:33
【问题描述】:

我需要使用 ghostscript 和 ImageMagick 来进行一些 PDF 编辑和 OCR。我已经到了使用 Dockerfile 的地步,但似乎 gcloud app deploy 每次都会从头开始。有没有办法通过安装一次软件包来加快速度?

这是我的 Dockerfile:

ROM gcr.io/google-appengine/python
LABEL python_version=python3.6
RUN virtualenv --no-download /env -p python3.6

# Set virtualenv environment variables. This is equivalent to running
# source /env/bin/activate

ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/
RUN pip install -r requirements.txt
ADD . /app/

RUN apt-get update
RUN apt-get install imagemagick -y
RUN apt-get install ghostscript

CMD exec gunicorn -b :$PORT main:app

【问题讨论】:

    标签: docker google-app-engine google-app-engine-python app-engine-flexible


    【解决方案1】:

    在 Dockerfile 中将这些步骤移到前面。

    Docker 的层缓存功能意味着它不会重建已经从完全相同的基础映像运行该步骤的步骤。但是,一旦您运行了使缓存无效的步骤,之后的任何内容都不会被缓存。特别是如果源代码树中的任何内容发生更改,ADD . 步骤将使缓存无效。

    在风格方面,我会改变另外两件事。首先,出于类似的缓存原因,在同一 RUN 步骤中运行 apt-get updateapt-get install 很重要,因为“更新”中先前缓存的 URL 可能会变得无效。其次,我不会费心尝试设置 Python 虚拟环境,因为 Docker 映像已经提供了独立的文件系统和 Python 安装。

    这最终给你留下了:

    FROM gcr.io/google-appengine/python
    LABEL python_version=python3.6
    RUN apt-get update \
     && apt-get install -y ghostscript imagemagick
    COPY requirements.txt /app/
    RUN pip install -r requirements.txt
    COPY . /app/
    EXPOSE 8000
    CMD ["gunicorn", "-b", ":8000", "main:app"]
    

    【讨论】:

    • 你先生,摇滚!我是 Docker 新手,但我很喜欢它。我的部署完成后将立即接受这一点。干杯
    猜你喜欢
    • 2018-07-11
    • 2013-04-17
    • 2023-04-01
    • 1970-01-01
    • 2020-04-19
    • 2018-08-24
    • 2015-06-07
    • 2017-12-07
    相关资源
    最近更新 更多