【问题标题】:Beanstalk cannot find Django application in subdirectoryBeanstalk 在子目录中找不到 Django 应用程序
【发布时间】:2021-03-26 00:49:00
【问题描述】:

我正在使用 Beanstalk 来部署一个私有网站项目。目前,我的项目组织在一个 Monorepo 中,其中前端是 vue.js,后端是 Django。看起来像这样:

-.ebextension
    -django.config
-.elasticbeanstalk
    -config.yml
-frontend
     -...
-backend
    -backend
        -settings.py
        -wgsgi.py
        -...
    -manage.py
    -...

起初,我从后端目录中部署后端,效果很好,但现在我试图更改它以触发从 GitHub 的部署。 CodePipeline 原则上可以工作,除了最后一步,因为它在子目录中找不到应用程序,所以它将在失败的地方启动应用程序。如何在子目录中引用 WSGIPath? 我现在尝试了很多组合,比如./backend/backend.wsgi 等。但没有一个被接受。

option_settings:
  aws:elasticbeanstalk:container:python:
      WSGIPath: backend/backend.wsgi:application <--Not found
  aws:elasticbeanstalk:application:environment:
      DJANGO_SETTINGS_MODULE: backend.settings


packages: 
  yum:
    python3-devel: []
    postgresql-devel: []

container_commands:
  00_list:
    command: "ls && ls backend/"
    leader_only: true
  01_start:
    command: "echo starting initialization"
  02_makemigrations:
    command: "source /var/app/venv/staging-LQM1lest/bin/activate && cd backend/ && python manage.py makemigrations"
    leader_only: true
  02_migrate:
    command: "source /var/app/venv/staging-LQM1lest/bin/activate && cd backend/ && python manage.py migrate"
    leader_only: true

提前致谢

【问题讨论】:

  • 嘿,我遇到了完全相同的问题。您设法以某种方式解决了吗?
  • 尝试将backend.backend.wsgi:application 用于WSGIPath。您还需要在 AWS 控制台的 Elastic Beanstalk 环境中设置 uwsgi 路径。

标签: django github amazon-elastic-beanstalk aws-codepipeline


【解决方案1】:

我通过 CodePipeline 和相应的 buildspec.yml 解决了这个问题,您可以在其中指定输出目录


env:
  variables:
    FRONT_URL: 'http://localhost:8000/'

phases:
  pre_build:
    commands:
      - echo "Before running tests"
      - cd backend/
      - pip install -r requirements.txt
  build:
    commands:
      - echo "Running all unit tests"
      - python manage.py test
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - '**/*' <--- use all files
  base-directory: 'backend' <--normally for specifiying the build output dir, in this case it's my backend dir

【讨论】:

    猜你喜欢
    • 2019-11-10
    • 2020-03-14
    • 2017-11-22
    • 2023-03-25
    • 2014-08-10
    • 2015-01-04
    • 1970-01-01
    • 2019-05-19
    • 2010-10-29
    相关资源
    最近更新 更多