【问题标题】:EB Django config commands errorEB Django 配置命令错误
【发布时间】:2017-06-21 05:51:28
【问题描述】:

几天来,我一直在尝试在 EB 上部署我的 django 应用程序,但尝试运行命令时一直出错。所以基本上,当我尝试部署应用程序时,它给了我“python:无法打开文件'manage.py':[Errno 2] 没有这样的文件或目录。” 对于完整的错误,这是我在终端上运行 eb deploy 后得到的。

Starting environment deployment via CodeCommit
--- Waiting for Application Versions to be pre-processed ---
Finished processing application version app-e8a0-170203_135603 
INFO: Environment update is starting.                               
INFO: Deploying new version to instance(s).                          
WARN: Environment health has transitioned from Severe to Degraded. 100.0 % of the requests are erroring with HTTP 4xx. Insufficient request rate (6.0 requests/min) to determine application health. Command failed on all instances. Incorrect application version found on all instances. Expected version "app-e8a0-170203_135603" (deployment 43). Application update in progress (running for 2 seconds).
ERROR: [Instance: i-05377fd0bcfa86dd6] Command failed on instance. Return code: 2 Output: python: can't open file 'HungryBoat/manage.py': [Errno 2] No such file or directory. 
command 03_migrate in .ebextensions/03_commands.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Unsuccessful command execution on instance id(s) 'i-05377fd0bcfa86dd6'. Aborting the operation.
ERROR: Failed to deploy application. 

来自日志的错误消息

[2017-02-03T21:05:46.082Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1/StartupStage0/EbExtensionPreBuild/Infra-EmbeddedPreBuild/prebuild_1_HungryBoat] : Starting activity...
[2017-02-03T21:05:46.082Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1/StartupStage0/EbExtensionPreBuild/Infra-EmbeddedPreBuild/prebuild_1_HungryBoat/Command 01_migrate] : Starting activity...
[2017-02-03T21:05:46.147Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1/StartupStage0/EbExtensionPreBuild/Infra-EmbeddedPreBuild/prebuild_1_HungryBoat/Command 01_migrate] : Activity execution failed, because: python: can't open file '/opt/python/current/app/hungryboat/manage.py': [Errno 2] No such file or directory
   (ElasticBeanstalk::ExternalInvocationError)


[2017-02-03T21:05:46.147Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1/StartupStage0/EbExtensionPreBuild/Infra-EmbeddedPreBuild/prebuild_1_HungryBoat/Command 01_migrate] : Activity failed.
[2017-02-03T21:05:46.147Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1/StartupStage0/EbExtensionPreBuild/Infra-EmbeddedPreBuild/prebuild_1_HungryBoat] : Activity failed.
[2017-02-03T21:05:46.147Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1/StartupStage0/EbExtensionPreBuild/Infra-EmbeddedPreBuild] : Activity failed.
[2017-02-03T21:05:46.413Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1/StartupStage0/EbExtensionPreBuild] : Activity failed.
[2017-02-03T21:05:46.413Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1/StartupStage0] : Activity failed.
[2017-02-03T21:05:46.414Z] INFO  [2980]  - [Application deployment app-019d3-170203_154910@1] : Completed activity. Result:
  Application deployment - Command CMD-Startup failed

这是我的配置文件

option_settings:
    "aws:elasticbeanstalk:application:environment":
        DJANGO_SETTINGS_MODULE: "hungryboat.settings"
        PYTHONPATH: "./hungryboat"
    "aws:elasticbeanstalk:container:python":
        WSGIPath: "hungryboat/wsgi.py"
        NumProcesses: 3
        NumThreads: 20
    "aws:elasticbeanstalk:container:python:staticfiles":
        "/static/": "www/static/"

commands:

    01_pip_update:
        command: "pip install --upgrade pip"
        leader_only: true
    02_pip_freeze:
        command: "pip freeze > requirements.txt"
    03_migrate:
        command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
        leader_only: true
    04_collect_static:
        command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"

我尝试将项目名称放在 manage.py 前面,但仍然给我同样的错误。我不知道我该如何解决这个问题。请拯救这个可怜的灵魂。谢谢。

编辑:项目目录树看起来或多或少像这样:

hungryboat
├── hungryboat/.ebextensions
├── hungryboat/.elasticbeanstalk
├── hungryboat/accounts
├── hungryboat/dump.rdb
├── hungryboat/hungryboat
│   ├── hungryboat/hungryboat/asgi.py
│   ├── hungryboat/hungryboat/__init__.py
│   ├── hungryboat/hungryboat/migrations
│   ├── hungryboat/hungryboat/routing.py
│   ├── hungryboat/hungryboat/settings.py
│   ├── hungryboat/hungryboat/urls.py
│   └── hungryboat/hungryboat/wsgi.py
├── hungryboat/manage.py
├── hungryboat/menu
├── hungryboat/pickplace
├── hungryboat/README.md
├── hungryboat/requirements.txt
├── hungryboat/static
└── hungryboat/venv

** 编辑:修复了上述问题,但现在我得到了不同的错误 **

settings.py 我有,

SECRET_KEY = os.environ['APP_SECRET_KEY']

但我收到了这个错误

INFO: Deploying new version to instance(s).                         
ERROR: [Instance: i-0c46f0a9e5069d5bf] Command failed on instance. Return code: 1 Output: (TRUNCATED)...python/run/venv/local/lib/python3.4/site-packages/django/conf/__init__.py", line 116, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

仅供参考,我在 EB 环境变量中有 APP_SECRET_KEY。

【问题讨论】:

  • 为什么要在实例中安装 pip 并创建需求?您需要做的是在您的本地项目文件夹中创建一个 requirements.txt。部署时,EB 会自动安装该需求文件中的所有包。首先,您删除前 2 个命令。也许您应该从文档重新开始。部署到 AWS 时,您不必在本地执行所有操作。
  • 它们仍然运行得很好,直到它命中迁移命令,尽管这是我被困在的地方。 :(
  • 您还有其他配置文件吗?还是在这些命令之上还有其他命令?
  • 更新问题。这几乎是我所拥有的
  • 示例:03_collectstatic:命令:“source /opt/python/run/venv/bin/activate && python opt/python/current/app/manage.py collectstatic --noinput”

标签: django amazon-elastic-beanstalk


【解决方案1】:
option_settings:
  "aws:elasticbeanstalk:application:environment":
     DJANGO_SETTINGS_MODULE: "hungryboat.settings"
     PYTHONPATH: "/opt/python/current/app/hungryboat:$PYTHONPATH"
  "aws:elasticbeanstalk:container:python":
     WSGIPath: "hungryboat/wsgi.py"
     NumProcesses: 3
     NumThreads: 20
  "aws:elasticbeanstalk:container:python:staticfiles":
     "/static/": "www/static/"

container_commands:
  01_migrate:
    command: "django-admin.py migrate"
    leader_only: true
  02_collect_static:
    command: "python /opt/python/current/app/hungryboat/manage.py collectstatic --noinput"

您的pythonpath 错误,这就是它找不到manage.py 文件的原因。首先更改pythonpath,然后重试。还要确保您在本地项目中有一个 requirements.txt。您不应该在您的实例中创建需求,您应该在本地创建,当您部署时,它将使用 pip 安装您的需求中的所有包。

【讨论】:

  • @JohnD。能否再次添加你的 requirements.txt 和部署错误日志?
  • 我已在问题中添加了错误日志,但我的 requirements.txt 列表确实很长,但日志显示 requirements.txt 上的所有内容均已安装且没有错误
  • 我有更多问题 :) 1. 在您的 .elastic beanstalk 内的配置文件中,什么是源?是吉特吗?如果是 git,您是否提交并推送更改? 2. 运行“eb ssh”,进入你的项目目录,查看是否有manage.py?为此,请运行“cd /opt/python/current/app/hungryboat”
  • 它在 /opt/python/current/app 而不是 /opt/python/current/app/hungryboat :\
  • 那么最近一定发生了一些变化,因为我从项目配置中获取了它。好的,那么现在更新它并重试。如果再次出现错误,请更新有关问题的日志并告诉我。编辑:我猜项目名称应该添加到应用程序目录中,所以它应该留在那里:/
猜你喜欢
  • 2013-08-23
  • 2020-11-24
  • 2021-05-29
  • 2016-09-01
  • 1970-01-01
  • 2013-10-06
  • 2017-05-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多