A simple web application template.
Application settings are defined as environment variables:
APPLICATION_DEBUG_ENABLED
: enables / disables application debug, valid
values are yes
or no
APPLICATION_SECRET_KEY
: sets the application's secret that will be used to
hash sensitive data like passwords (secret)DATABASE_HOST
: sets the database hostDATABASE_PORT
: sets the database portDATABASE_NAME
: sets the database nameDATABASE_USERNAME
: sets the database usernameDATABASE_PASSWORD
: sets the database password (secret)AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
)APPLICATION_SECRET_KEY
and DATABASE_PASSWORD
)This project uses Docker + Code Development Containers feature to provide a consistent and easy to use development environment.
Clone this repository:
cd ~/code/github/brunitto
git clone git@github.com:brunitto/hello-django.git
Open in VS Code:
code hello-django
This will detect the development container configuration within .devcontainer
directory and start the development environment, using the
docker-compose.yaml
and Dockerfile
files.
Run an application check:
python manage.py check
This will check if there are any configuration problem.
The output should be something like:
System check identified no issues (0 silenced).
Run the application's migrations:
python manage.py migrate
This will create the necessary database tables.
Run the tests
python manage.py test
Run the tests under coverage:
python -m coverage run --include 'main/*' manage.py test
Check the coverage report:
python -m coverage report --show-missing
This will ensure that are no code without tests.
Run the development server:
python manage.py runserver 0.0.0.0:8000
This will start a simple development server within the container, available at: http://localhost:8000.
You can also use Gunicorn, also available at http://localhost:8000:
python -m gunicorn -w 2 -b 0.0.0.0:8000 core.wsgi
This is how the application will run in production environment.
To use git within the development container, it's necessary to start a SSH agent and add your keys, so the extension will forward the agent to the development container:
ssh-agent
ssh-add
More information available at: https://code.visualstudio.com/docs/remote/containers#_using-ssh-keys
Start from branch main
:
git checkout main
git pull origin main
Create branch development
from main
:
git checkout -b development
Note: if the branch development
exists, just checkout:
git checkout development
Code, add files and commit when you have tested and working code:
git add ...
git commit ...
Push the development
branch to trigger the CI workflow!
This project uses Terraform to provision infrastructure in AWS. This provisioning should be handled by the CI/CD workflows, but here's how it works, for documentation purpose.
Initialize Terraform:
terraform init -backend-config="key=hello-django/key"
This will create the Terraform configuration and state.
Plan:
terraform plan -out tfplan
This will check the Terraform modules and AWS resources, and create a plan to provision the required resources.
Apply:
terraform apply tfplan
This will provision the required resources in AWS.
From a tested and working ref (commit or branch), create and push a new tag using semantic versioning:
git checkout development
git tag 1.0.0
git push origin 1.0.0
Create a new release in GitHub, selecting the tag, to trigger the CD workflow!
Note: the tag name will be used as container image tag.
This project's continuous integration uses GitHub Actions and is configured in
the .github/workflows/ci.yaml
file.
This project's continuous deployment uses GitHub Actions and is configured in
the .github/workflows/cd.yaml
file.