Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EB Django config commands error

I've been trying to deploy my django app on EB for few days but I keep getting an error trying to run a command. So basically, when I try to deploy the app it gives me "python: can't open file 'manage.py': [Errno 2] No such file or directory." For the full error, this is what I get after running eb deploy on my terminal.

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. 

error message from logs:

[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

here's the config file I have:

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"

I've tried putting project name in front of manage.py but still gives me the same error. I don't know how I can solve this. please save this poor soul. thanks.

EDIT: project directory tree looks more or less like this:

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

** EDIT: Fixed above problem but now I'm getting different error **

inside the settings.py I have,

SECRET_KEY = os.environ['APP_SECRET_KEY']

but I'm getting this ERROR

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.

FYI, I have APP_SECRET_KEY inside EB Environment Variables.

like image 485
John D. Avatar asked Oct 17 '22 17:10

John D.


1 Answers

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"

Your pythonpath is wrong, that's why it can't find manage.py file. First change the pythonpath and try again. Also make sure you have a requirements.txt on your local project. You shouldn't create requirements in your instance, you should create on your local and when you deploy, it will install all packages in your requirements with pip.

like image 178
Çağatay Barın Avatar answered Oct 21 '22 02:10

Çağatay Barın