GDAL in flexible environment

后端 未结 1 1169
感动是毒
感动是毒 2020-12-03 19:37

In app engine flexible environment, I\'m trying to run django on postgresql db using GIS extensions. Can run locally, and it eventually finished deploying to cloud successfu

相关标签:
1条回答
  • 2020-12-03 19:42

    The app engine flexible environment comes with the C libraries listed here: https://cloud.google.com/appengine/docs/flexible/python/runtime

    Since GDAL is a C library that isn't in the runtimes that come standard, I had to build a custom environment using a Docker container. The trick was getting GDAL installed along with the necessary python libraries in requirements.txt and Python3, then starting the django app thru gunicorn.

    Here's my Dockerfile:

    FROM gcr.io/google-appengine/python
    
    RUN apt-get update && apt-get install -y \
      binutils \
      gdal-bin \
      python-gdal
    
    # Create a virtualenv for dependencies. This isolates these packages from
    # system-level packages.
    RUN virtualenv /env -p python3.6
    
    # Setting these environment variables are the same as running
    # source /env/bin/activate.
    ENV VIRTUAL_ENV /env
    ENV PATH /env/bin:$PATH
    
    # Copy the application's requirements.txt and run pip to install all
    # dependencies into the virtualenv.
    ADD requirements.txt /app/requirements.txt
    RUN pip install -r /app/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 mysite.wsgi
    

    My app.yaml:

    # [START runtime]
    runtime: custom
    #python
    env: flex
    entrypoint: gunicorn -b :$PORT mysite.wsgi
    
    beta_settings:
        cloud_sql_instances: <your-db-instance-identifying-string>
    
    runtime_config:
      python_version: 3
    # [END runtime]
    

    And the minimum requirements.txt (add to as needed):

    Django==1.11.4
    mysqlclient==1.3.10
    wheel==0.29.0
    gunicorn==19.7.1
    psycopg2==2.7.3
    

    Hope this helps someone,

    Dan

    0 讨论(0)
提交回复
热议问题