I am trying to use elastic beanstalk to deploy my little django app.
the app runs locally fine
and it appears that my EB stack is created fine, what's happening is that from the logs (eb-engine.log) it fails to run the container commands in the django.config file, which is:
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "personal_portfolio.settings"
PYTHONPATH: "/var/app/current:$PYTHONPATH"
AWS_STORAGE_BUCKET_NAME: "xxxx-personal-portfolio"
AWS_S3_REGION_NAME: "us-east-1"
RDS_USERNAME: "xxx"
RDS_PASSWORD: "password"
RDS_PORT: 5432
aws:elasticbeanstalk:container:python:
WSGIPath: "personal_portfolio.wsgi:application"
aws:elasticbeanstalk:environment:process:default:
HealthCheckPath: "/about"
MatcherHTTPCode: "200-499"
container_commands:
01_makemigrations:
command: "source /var/app/venv/*/bin/activate && python3 manage.py makemigrations --noinput"
leader_only: true
02_migrate:
command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate --noinput"
leader_only: true
03_createsu:
command: "source /var/app/venv/*/bin/activate && python3 manage.py createsu"
04_collectstatic:
command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput"
leader_only: true
the logs don't say why?
I am deploying using this script:
#!/bin/bash
python create_s3bucket.py
eb init
eb create portfolio1 -db.engine postgres --database.version 12 --database.username xxx --database.password "1234"
is there a way to understand what is wrong?
I have to say I deployed the same thing quicker writing Terraform.
This is the error in the cf-init logs
2022-11-08 15:21:52,613 [ERROR] Command 01_makemigrations (source /var/app/venv/*/bin/activate && python3 manage.py makemigrations --noinput) failed
2022-11-08 15:21:52,613 [ERROR] Error encountered during build of postbuild_0_personal_portfolio_project3: Command 01_makemigrations failed
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 576, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 276, in build
self._config.commands)
File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command 01_makemigrations failed
Related
I understand this problem is common, and I've tried many solutions, none of which have worked.
I'm following this tutorial to deploy a Django App to AWS EBS: https://realpython.com/deploying-a-django-app-to-aws-elastic-beanstalk/
More detail on error message from eb-engine.log:
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at
<https://www.psycopg.org/docs/install.html>).
[end of output]
.ebextensions/01_packages.config:
packages:
yum:
git: []
postgresql-devel: []
.ebextensions/02_packages.config:
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python matador-web/manage.py migrate --noinput"
leader_only: true
02_createsu:
command: "source /opt/python/run/venv/bin/activate && python matador-web/manage.py createsu"
leader_only: true
03_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python matador-web/manage.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "matador_web.settings"
"PYTHONPATH": "/opt/python/current/app/iotd:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: matador-web/matador_web/wsgi.py
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
.elasticbeanstalk/config.yaml:
branch-defaults:
feat-deploy:
environment: matador-web-dev
environment-defaults:
matador-web-dev:
branch: feat-deploy
repository: origin
global:
application_name: matador_web
branch: null
default_ec2_keyname: aws-eb
default_platform: Python 3.8 running on 64bit Amazon Linux 2
default_region: us-east-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: git
workspace_type: Application
images/management/commands/createsu.py:
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
class Command(BaseCommand):
def handle(self, *args, **options):
if not User.objects.filter(username="admin").exists():
User.objects.create_superuser("admin", "admin#admin.com", "admin")
requirements.txt:
asgiref==3.5.2
certifi==2022.6.15
charset-normalizer==2.1.0
click==8.1.3
Django==3.2
djangorestframework==3.13.1
flake8==4.0.1
idna==3.3
Jinja2==3.1.2
MarkupSafe==2.1.1
mccabe==0.6.1
nulltype==2.3.1
plaid==0.1.7
plaid-python==9.8.0
psycopg2-binary==2.8.5
pycodestyle==2.8.0
pyflakes==2.4.0
python-dateutil==2.8.2
python-dotenv==0.20.0
pytz==2022.1
PyYAML==6.0
requests==2.28.1
six==1.16.0
sqlparse==0.4.2
urllib3==1.26.10
If I left any information out please let me know.
I added the codes to below i hope it is clear and precise
Dockerfile:
FROM python:3.8.5-alpine
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
COPY ./ddc /app
WORKDIR /app
COPY ./entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]
docker-compose.yml
version: '3.7'
services:
django_gunicorn:
volumes:
- static:/static
env_file:
- .env
build:
context: .
ports:
- "8000:8000"
nginx:
build: ./nginx
volumes:
- static:/static
ports:
- "80:80"
depends_on:
- django_gunicorn
volumes:
static:
entrypoint.sh
#!/bin/sh
python manage.py migrate --no-input
python manage.py collectstatic --no-input
gunicorn ddc.wsgi:application --bind 0.0.0.0:8000
First i use docker-compose up --build
and this is what i get:
Building django_gunicorn
Sending build context to Docker daemon 19.46kB
Step 1/8 : FROM python:3.8.5-alpine
---> 0f03316d4a27
Step 2/8 : RUN pip install --upgrade pip
---> Using cache
---> ac5d6a64af93
Step 3/8 : COPY ./requirements.txt .
---> Using cache
---> 8dfb848be8a4
Step 4/8 : RUN pip install -r requirements.txt
---> Using cache
---> 0dee442b9c0a
Step 5/8 : COPY ./ddc /app
---> 21c33e5463d8
Step 6/8 : WORKDIR /app
---> Running in 9153438d9466
Removing intermediate container 9153438d9466
---> d27b60805a1b
Step 7/8 : COPY ./entrypoint.sh /
---> e497fecdfb76
Step 8/8 : ENTRYPOINT ["sh", "/entrypoint.sh"]
---> Running in f6eb59759a71
Removing intermediate container f6eb59759a71
---> 6db361baa8e8
Successfully built 6db361baa8e8
Successfully tagged django-docker-compose_django_gunicorn:latest
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose/cli/main.py", line 81, in main
File "compose/cli/main.py", line 203, in perform_command
File "compose/metrics/decorator.py", line 18, in wrapper
File "compose/cli/main.py", line 1186, in up
File "compose/cli/main.py", line 1182, in up
File "compose/project.py", line 664, in up
File "compose/service.py", line 348, in ensure_image_exists
File "compose/service.py", line 1133, in build
File "compose/service.py", line 1948, in build
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp5cv0a52z'
[22049] Failed to execute script docker-compose
After that i just use
docker-compose up
and the system works as it is expected. What does this error means and how do i avoid it. I use the latest docker and compose which are:
docker:Docker version 19.03.13, build cd8016b6bc
docker-compose version 1.29.2, build 5becea4c
The issue is resolved after i change my installation from ubuntu snap to
https://docs.docker.com/engine/install/ubuntu/
https://docs.docker.com/compose/install/
./project
/site_ts
/web
Dockerfile
requirements.txt
docker-compose.yml
my docker-compose.yml:
version: '3'
services:
web:
build: ./web
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/site_ts
ports:
- '8000:8000'
my Dockerfile:
FROM python:3.8
ENV PYTHONUNBUFFERED 1
RUN mkdir /site_ts
WORKDIR /site_ts
COPY requirements.txt /site_ts/
RUN pip install --upgrade pip && pip install -r requirements.txt
ADD . /site_ts/
i write docker-compose up and take this Error:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose\cli\main.py", line 67, in main
File "compose\cli\main.py", line 123, in perform_command
File "compose\cli\command.py", line 69, in project_from_options
File "compose\cli\command.py", line 132, in get_project
File "compose\cli\docker_client.py", line 43, in get_client
File "compose\cli\docker_client.py", line 170, in docker_client
File "site-packages\docker\api\client.py", line 188, in __init__
File "site-packages\docker\api\client.py", line 213, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: (2, 'CreateFile', 'The specified file cannot be found.')
[9356] Failed to execute script docker-compose
I am trying to deploy my django app on aws but i keep getting the following error:
[Instance: i-********] Command failed on instance. Return
code: 1 Output:
(TRUNCATED)....6/site-packages/django/db/migrations/operations/fields.py",
line 285, in state_forwards "%s.%s has no field named '%s'" %
(app_label, self.model_name, self.old_name)
django.core.exceptions.FieldDoesNotExist: classroom.itembatch has no
field named 'width'. container_command 01_migrate in
.ebextensions/db-migrate.config failed. For more detail, check
/var/log/eb-activity.log using console or EB CLI.
Here's my db-migrate.config file
container_commands:
01_migrate:
command: "django-admin.py migrate --noinput"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: django_school.settings
Why am I getting this error and how can I change this ?
I'm depolying my app onto Elasticbeanstalk. When I visit the url, I get Invalid HTTP_HOST header:'mysite.com'.
I've added my url to my settings.py.
This is my settings file:
ALLOWED_HOSTS = ['mysite.com/','.mysite.com/', '127.0.0.1:8000', '127.0.0.1', 'localhost', 'localhost:8000', '13.59.177.101', '127.0.0.1']
This is my python.config file:
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate"
leader_only: true
02_collectstatic:
command: "source /opt/python/run/venv/bin/activate &&python manage.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "project.settings"
PYTHONPATH: "$PYTHONPATH"
"ALLOWED_HOSTS": ".elasticbeanstalk.com"
"aws:elasticbeanstalk:container:python":
WSGIPath: "/opt/python/current/app/project/wsgi.py"
StaticFiles: "/static/=www/static/"
packages:
yum:
postgresql95-devel: []
My code works locally without any problem. Not sure what to do. Please help!