Ошибка возникает при добавлении команды контейнера в Django aws eb - PullRequest
0 голосов
/ 04 августа 2020

Я использую Python 3,7 Django 3.0.9 postgresql 11

-ebextension / django .config

container_commands:
  01_migrate:
    command: "django-admin.py migrate"
    leader_only: true
  02_compilemessages:
    command: "django-admin.py compilemessages"

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: config.wsgi:application
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: config.settings

Сообщение об ошибке при запуске eb deploy

2020-08-04 14:48:51    INFO    Environment update is starting.
2020-08-04 14:49:30    INFO    Deploying new version to instance(s).
2020-08-04 14:49:45    ERROR   [Instance: i-0719a2ed67b621907] Command failed on instance. An unexpected error has occurred [ErrorCode: 0000000001].
2020-08-04 14:49:45    INFO    Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-08-04 14:49:45    ERROR   Unsuccessful command execution on instance id(s) 'i-0719a2ed67b621907'. Aborting the operation.
2020-08-04 14:49:45    ERROR   Failed to deploy application.

содержимое ошибок журналов eb

2020/08/04 11:35:55.132182 ERROR Requirements file provided! Importing into Pipfile…
2020/08/04 11:35:56.227858 ERROR Error occurred during build: Command 01_migrate failed
2020/08/04 11:35:56.227884 ERROR An error occurred during execution of command app-deploy - PostBuildEbExtension. Stop running the command. Error: Container commands build failed. Please refer to /var/log/cfn-init.log for more details.

После проверки сообщения об ошибке команды 01_migrate кажется, что есть проблема с командами continer, поэтому я запустил django -admin migrate .

django .core.exceptions.ImproperlyConfigured: запрошенный параметр БАЗЫ ДАННЫХ, но параметры не настроены. Вы должны либо определить переменную среды DJANGO_SETTINGS_MODULE, либо вызвать settings.configure () перед доступом к настройкам.

Я определил переменные среды в django .config, но возникла ошибка, я не могу развернуть свой site django -admin migrate заменяется на python manage.py migrate, но все еще не развертывается. Вы также можете найти подробный код на моем GitHub

https://github.com/dopza86/air_bnb_clone

Не знаю, как это сделать, мне нужна ваша помощь, спасибо

1 Ответ

0 голосов
/ 05 августа 2020

Когда ваша команда container_commands будет запущена, вы не окажетесь в среде вашего python. Также убедитесь, что переменные env установлены перед запуском container_commands.

Для этого вы можете изменить свой .ebextentions:

01-env_var.config

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: config.wsgi:application
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: config.settings

05-packages.config

packages:
  yum:
    postgresql-devel: []

10- django .config

container_commands:
  01_migrate:
    command: |
      env # just to print out the env variables for checking in logs
      source $PYTHONPATH/activate
      django-admin.py migrate
    leader_only: true
  02_compilemessages:
    command: |
      env # just to print out the env variables for checking in logs
      source $PYTHONPATH/activate
      django-admin.py compilemessages
...