【发布时间】:2017-12-05 08:55:27
【问题描述】:
我正在编辑我的 .ebextensions .config 文件以在部署前运行一些初始化命令。我认为此命令将在包含我的应用程序的提取 .zip 的同一文件夹中运行。但事实并非如此。 manage.py 在我的 zip 的根目录中,如果我执行命令:
01_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
我收到了ERROR: [Instance: i-085e84b9d1df851c9] Command failed on instance. Return code: 2 Output: python: can't open file 'manage.py': [Errno 2] No such file or directory.
我可以执行command: "python /opt/python/current/app/manage.py collectstatic --noinput",但这将运行之前成功部署的manage.py,而不是运行正在部署的atm。
我尝试通过执行command: "pwd" 来检查.config 运行的命令的工作目录是什么,似乎pwd 是/opt/elasticbeanstalk/eb_infra,其中不包含我的应用程序。
所以我可能需要更改$PYTHONPATH 以包含正确的路径,但我不知道它是哪条路径。
在这个comment 中,用户将以下内容添加到他的.config 文件中:
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: myapp.settings
PYTHONPATH: "./src"
因为他的manage.py 位于 zip 根目录下的 src 文件夹中。在我的情况下,我会做 PYTHONPATH: "." 但它不起作用。
【问题讨论】:
标签: python django amazon-web-services amazon-elastic-beanstalk