我正在尝试在gae上安装weasyprint,我知道我们可以通过在app.yaml中将运行时从python更改为自定义来在Dockerfile文件中传递它来安装外部库。我在为weasyprint库创建Dockerfile时遇到了问题。
发布于 2020-05-06 21:39:57
这是一个简单的示例,它是我按照these说明编写的。我已经测试过了,在GAE上的部署对我来说是成功的:
文档文件
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:appapp.yaml
runtime: custom
env: flexrquirements.txt
gunicorn==19.1.1
Flask==1.0.2
WeasyPrint>=0.34main.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)注意到,正如WeasyPrint documentation提到的那样,平台的软件包(如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-infohttps://stackoverflow.com/questions/61600712
复制相似问题