EBS容器命令:错误的django-admin工作目录?

时间:2015-10-07 13:39:05

标签: python django django-admin elastic-beanstalk

我有一个相当简单的django应用程序,我在弹性beanstalk环境中部署。我已经为部署过程创建了许多自定义,包括容器命令中的经典“collectstatic”脚本。这是我配置的一部分:

container_commands:
    01_replace_wsgi_config:
        command: cp .ebextensions/wsgi.conf /opt/python/ondeck/wsgi.conf
    02_collect_static:
        command: django-admin.py collectstatic --noinput

如您所见,我使用ondeck文件夹来自定义wsgi.conf文件,因为自动生成的文件对我来说不够好。

现在我偶然发现的问题是上面的django-admin.py调用正在处理旧的“当前”目录,并且一旦“ondeck”目录变为“当前”,其结果就不可见 - 这发生了,显然, container_commands之后执行。对于来自django安装的应用程序的javascript文件,这看起来像404。我发现这一点的方法是观察/var/log/eb-actions.log输出:

  ...
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/jquery/static/js/jquery.js'
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/django_ajax/static/django_ajax/js/jquery.ajax.min.js'
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/django_ajax/static/django_ajax/js/jquery.ajax-plugin.js'
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/django_ajax/static/django_ajax/js/jquery.ajax.js'
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/django_ajax/static/django_ajax/js/jquery.ajax-plugin.min.js'

  0 static files copied to '/opt/python/current/app/dashboard/dashboard/static', 74 unmodified.

我找到了一个对我有用的解决方案:

02_collect_static:
    command: python dashboard/manage.py collectstatic --noinput

此命令确保collectstatic在“ondeck”forder上运行,该onder将成为“当前”:

  ...
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/jquery/static/js/jquery.js'
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/django_ajax/static/django_ajax/js/jquery.ajax.min.js'
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/django_ajax/static/django_ajax/js/jquery.ajax-plugin.js'
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/django_ajax/static/django_ajax/js/jquery.ajax.js'
  Copying '/opt/python/run/venv/local/lib/python2.7/site-packages/django_ajax/static/django_ajax/js/jquery.ajax-plugin.min.js'

  67 static files copied to '/opt/python/bundle/15/app/dashboard/dashboard/static', 7 unmodified.

令我担心的是,我必须根据official documentation更改应该工作的内容。

我怀疑我的问题可能隐藏在这里(app.config):

option_settings:
  "aws:elasticbeanstalk:application:environment":
    DJANGO_SETTINGS_MODULE: "dashboard.settings"
    PYTHONPATH: "/opt/python/current/app/dashboard:$PYTHONPATH"

PYTHONPATH设置为“current”,这可能会在处理container_commands时强制django-admin.py看起来而不是“ondeck”。 如果是这样,这个设置应该如何才能使正确的经典部署工作?我采用了这种格式from documentation ...

1 个答案:

答案 0 :(得分:0)

我已将它用于许多项目,效果很好。

02_collectstatic:
  command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"

option_settings看起来不错。