我正在尝试在 gae 上安装 weasyprint,我知道我们可以通过将运行时从 python 更改为 app.yaml 中的自定义来将其传递到 Dockerfile 中来安装外部库。我在为 weasyprint 库创建 Dockerfile 时遇到问题。
这是一个简单的example我在下面写的these https://github.com/GoogleCloudPlatform/python-runtime#kubernetes-engine--other-docker-hosts指示。我已经测试过了,GAE 上的部署对我来说是成功的:
Dockerfile
FROM gcr.io/google-appengine/python
# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
# Use -p python3 or -p python3.7 to select python version. Default is version 2.
RUN virtualenv /env -p python3.7
# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
# Install platform's packages required for WeasyPrint
RUN apt-get update && apt-get -y install build-essential python3-dev python3-pip \
python3-setuptools python3-wheel python3-cffi \
libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
ADD requirements.txt requirements.txt
RUN pip install -r requirements.txt
# Add the application source code.
ADD . /app
# Run a WSGI server to serve the application. gunicorn must be declared as
# a dependency in requirements.txt.
CMD gunicorn -b :$PORT main:app
app.yaml
runtime: custom
env: flex
要求.txt
gunicorn==19.1.1
Flask==1.0.2
WeasyPrint>=0.34
main.py
from flask import Flask
from weasyprint import *
app = Flask(__name__)
@app.route('/')
def hello():
return 'Success!'
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080)
Note作为 WeasyPrint文档 https://weasyprint.readthedocs.io/en/stable/install.html提及、平台的软件包(例如 cairo、Pango 和 GDK-PixBuf)必须单独安装。它们是通过我在 Dockerfile 中添加的以下命令安装的:
RUN apt-get update && apt-get -y install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)