使用python + django + gunicorn的Gcloud应用程序部署失败+工作程序无法启动

时间:2019-03-18 03:31:39

标签: django google-app-engine gunicorn gcloud

我正在尝试使用django部署网站/ webapp ...构建了app.yaml和Requirements.txt ...一切都完成了,当我点击gcloud app deploy时,最后出现了以下错误日志。

DONE
-----------------------------------------------------------------------------------------------------------------------------------------

Updating service [default] (this may take several minutes)...failed.                                                                    
ERROR: (gcloud.app.deploy) Error Response: [9] 
Application startup error:
[2019-03-18 03:14:29 +0000] [1] [INFO] Starting gunicorn 19.9.0
[2019-03-18 03:14:29 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2019-03-18 03:14:29 +0000] [1] [INFO] Using worker: sync
[2019-03-18 03:14:29 +0000] [9] [INFO] Booting worker with pid: 9
[2019-03-18 03:14:29 +0000] [9] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/env/local/lib/python2.7/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
[2019-03-18 03:14:29 +0000] [9] [INFO] Worker exiting (pid: 9)
[2019-03-18 03:14:29 +0000] [1] [INFO] Shutting down: Master
[2019-03-18 03:14:29 +0000] [1] [INFO] Reason: Worker failed to boot.

这是我的app.yaml

runtime: python

api_version: 1
threadsafe: true

# the PROJECT-DIRECTORY is the one with settings.py and wsgi.py
entrypoint: gunicorn -b :$PORT ~/NovUs/rec/rec.wsgi
# specific to a GUnicorn HTTP server deployment
env: flex 
# for Google Cloud Flexible App Engine

# any environment variables you want to pass to your application.
# accessible through os.environ['VARIABLE_NAME']
env_variables:
# the secret key used for the Django app (from PROJECT-DIRECTORY/settings.py)
  SECRET_KEY: '***i removed this***' 
  DEBUG: 'False' # always False for deployment

# everything after /cloudsql/ can be found by entering >> gcloud sql instances describe DATABASE-NAME << in your Terminal
# the DATABASE-NAME is the name you gave your project's PostgreSQL database
# the second line from the describe output called connectionName can be copied and pasted after /cloudsql/
  DB_HOST: '/cloudsql/ final-234816:us-central1:novusdb'
  DB_PORT: '5432' # PostgreSQL port
  DB_NAME: 'novusdb'
  DB_USER: 'postgres' # either 'postgres' (default) or one you created on the PostgreSQL instance page
  DB_PASSWORD: ''

  STATIC_URL: 'https://storage.googleapis.com/BUCKET-NAME/static/' # this is the url that you sync static files to

handlers:
- url: /static
  static_dir: static

- url: /
  script: home.app

- url: /index\.html
  script: home.app

- url: /stylesheets
  static_dir: stylesheets

- url: /(.*\.(gif|png|jpg))$
  static_files: static/\1
  upload: static/.*\.(gif|png|jpg)$

- url: /admin/.*
  script: admin.app
  login: admin

- url: /.*
  script: not_found.app

beta_settings:
# from command >> gcloud sql instances describe DATABASE-NAME <<
  cloud_sql_instances: final-234816:us-central1:novusdb 

#runtime_config:
#python_version: 2 # enter your Python version BASE ONLY here. Enter 2 for 2.7.9 or 3 for 3.6.4

#manual_scaling:
#  instances: 1
#resources:
#  cpu: 1
#  memory_gb: 0.5
#  disk_size_gb: 10   

在我的settings.py中 WSGI_APPLICATION = 'rec.wsgi.application' 即使我将其更改为WSGI_APPLICATION = 'wsgi.application' 也无法解决,错误仍然保持不变。

并且我尝试用main:app编辑入口点,问题是一样的...。 有人请解决这个问题。谢谢

2 个答案:

答案 0 :(得分:0)

在您的app.yaml中,添加默认的gunicorn入口点行,但还要添加更长的超时时间以满足您的需要:entrypoint: gunicorn -b :$PORT YOURSITE.wsgi --timeout 120

答案 1 :(得分:0)

通常可能存在两个问题,前一段时间在Google App Engine上部署Dash应用程序时遇到了这个问题。

GAE的gunicorn版本可能存在版本冲突。请改用Gunicorn 19.7.1或更高版本。使用旧版本的Gunicorn时,我遇到了同样的问题。

另一个冲突可能是requirements.txt与main.py入口点不在同一目录中。因此,该应用将在未安装所有软件包的情况下进行部署,部署到GAE时不会返回任何错误。

相关问题