Important information about the development architecture of this project.
Technology | Version | |
---|---|---|
Language | Python | 3.9.5 |
Framework | Django | 3.2.4 |
Database | PostgreSql | 13.2 |
IDE | PyCharm | 2021.1 |
Container | Docker | 3.4.0 |
Create the Dockerfile
file in your project's root folder with the following instructions.
FROM ubuntu:18.04
COPY . /app
WORKDIR /app
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y python3-pip build-essential manpages-dev libpq-dev postgresql-client
RUN python3 -m pip install -U pip \
&& pip3 install --upgrade setuptools \
&& pip3 install -r /app/requirements.txt
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120", "--max-requests", "600", "--log-file", "-", "<myapplication>.wsgi:application"]
<myapplication>
to the name of your application.
In the root folder of your project execute the command to create the local image of your application.
docker image build -t <myapplication>:latest .
You can change the latest
by your application version.
After the build completes, tag your image so you can push the image to this repository.
docker tag <myapplication>:latest <aws-container-register-url>.amazonaws.com/<myapplication>:latest
Run the following command to push this image to your newly created AWS repository.
docker push <aws-container-register-url>.amazonaws.com/<myapplication>:latest
On the AWS AppRunner page, select "create service", then under "source" link to AWS Elastic Container Registry.
-
Create your
environment variables
on the Configure service page; -
Modify the Port to
8000
(or the port that Gunicorn is configured); -
In additional settings, search for "Start command" and enter the
migrate
command:
python3 /app/manager.py migrate
Once the deployment is complete, you can go to the Custom domains
folder and parameterize your application's domain, following the AWS instructions.
Be sure to parameterize your application's security settings as follows.
In the settings.py
file change the settings.
ALLOWED_HOSTS = ['*', ]
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
Please feel free to contact me. 😎
🍻