GAE的Weasyprint Docker文件。

问题描述 投票:0回答:1

我想在gae上安装weasyprint,我知道我们可以通过在app.yaml中把运行时从python改为custom来安装外部库。我在创建Weasyprint库的Docker文件时遇到了问题。

google-app-engine weasyprint
1个回答
0
投票

下面是一个简单的 例子 我下面写的 这些 说明。我已经测试过了,在GAE上的部署对我来说是成功的。

Docker文件

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

rquirements.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)

那作为WeasyPrint 文件 提,平台的包 (如cairo、Pango和GDK-PixBuf) 必须单独安装。它们是通过我在Docker文件中添加的以下命令安装的。

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
© www.soinside.com 2019 - 2024. All rights reserved.