A simple devops-inspired template for Django applications setup with compose.
If you need a quick start with Django and Compose, you're in the right place. DjangOps is a dev-ops-inspired template for perfectionists with deadlines, who also happen to love Django and compose! Spin up a local dev environment with modular custom settings in a few steps and focus on the value you want to build. All comments, feedback, and contributions are highly encouraged. I always love to hear and learn from the community❤
Learn more about the Django framework from the official documentation.
This is an overview of the minimal setup needed to get started.
- Git
- Docker Desktop (latest version)
- IDE/Code/Text editor (PyCharm, VScode, Vim, etc)
Follow these tutorials to set up Docker and Compose on either Mac
or Linux.
I'd recommend Microsoft's documentation to set up Docker on WSL2 if you're on Windows.
The following setup was run on Ubuntu focal (20.04.6 LTS)
You can clone this repo with the following command.
- Clone repository
# cd your/desired/target/dir
git clone [email protected]:apexDev37/DjangOps.git my-project
cd my-project
🛈 This will clone the repository to a target dir on your host machine with a custom name
my-project/
and navigate into its root dir.
The following commands assume execution occurs at the project root.
Before running your application with Compose, configure environment variables
and secrets expected by the Compose app model. Sample env
and secret
files are provided to configure the following services: web
and db
. You can
create the required config files with the following make
target commands.
After the config files are created, replace the placeholders and empty txt
files with your custom values.
🛈
secret
files should store sensitive or confidential data, whereasenv
files can contain other environment-related config.
- Create required config files
make envs && make secrets # idempotent operations.
🛈 This will create and output all config files generated from available sample files in their target directory (ie.
django.env.example
->django.env
).
- Update placeholder config values
💡
secret
files intended to store keys or passwords are auto-populated with a random, cryptographic, base64-encoded value.
You're all set to run your Django application. Spin up your Django and Postgres instances with the following command.
- Spin up containers
docker compose down
docker compose up -d
🛈 This will create and start the Django and Postgres instances in the same network defined in the base
compose
file.
Once the containers have been created and started, you can access the application at http://localhost:8000
This is an overview to prepare working with this repo locally.
You can use any tool of your choice to create a PEP 405 compliant virtual
environment. The following example uses virtualenvwrapper
to create and
manage virtual environments.
- Create a virtual environment
mkvirtualenv -p python3.12 djangops-py312
🛈 This will create a fully managed venv and activate the virtual environment by default.
If your environment is not activated from the above command or you encounter any issue, manually activate it with the following command.
- Activate the virtual environment
workon djangops-py312
⚠ All following commands assume execution occurs with an active virtual env at the project root.
- Install requirements for development.
make requirements
🛈 This will install and sync the active environment with the pinned versions for your development dependencies,
requirements/dev.txt
.
- Set up
pre-commit
hooks
pre-commit install --install-hooks
🛈 This one time setup installs the
pre-commit
script in your hiddengit/hooks
directory and installs all hook environments defined in the config file.
Run the process for the Django development server in the web
service. You can
use the following make
target command to run the develop
compose override
model, which supports hot-reload by watching and syncing your local files
into the container.
- Run Compose services in watch (develop) mode.
make -f compose.Makefile watch.dev
You can also choose to spin up a more light-weight web
service to handle only
test-related concerns.
- Run Compose services in watch (testing) mode.
make -f compose.Makefile watch.test
To make a repository open source, you must license it so that others may freely use, modify, and distribute the software. Using the MIT license, this project ensures this. The full original text version of the license may be seen here.