fix: settings && update readme
This commit is contained in:
parent
a9ca912ffe
commit
91f1cfde1a
11
Makefile
11
Makefile
@ -1,6 +1,9 @@
|
||||
PROJECTNAME := project_name
|
||||
include .env
|
||||
export $(shell sed 's/=.*//' .env)
|
||||
|
||||
SHELL := /bin/sh
|
||||
APP_NAME := project_name
|
||||
PROJECTNAME ?= default_app_name
|
||||
APP_NAME := $(PROJECTNAME)
|
||||
BACKEND_APP_NAME := $(APP_NAME)-backend
|
||||
|
||||
define HELP
|
||||
@ -48,10 +51,10 @@ migrate:
|
||||
"python manage.py migrate"
|
||||
|
||||
build-dev:
|
||||
docker-compose -f docker-compose.yml up --build -d
|
||||
DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f docker-compose.yml up --build -d
|
||||
|
||||
build-prod:
|
||||
docker-compose -f docker-compose.prod.yml up --build -d
|
||||
DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f docker-compose.prod.yml up --build -d
|
||||
|
||||
stop-dev:
|
||||
@docker-compose -f docker-compose.yml down
|
||||
|
165
README.md
165
README.md
@ -1,153 +1,160 @@
|
||||
# Django Docker Quickstart
|
||||
|
||||
This quickstart provides an easy way to initiate a Django project using Docker. It comes with pre-configured services including PostgreSQL, Redis, Celery (worker and beat), Nginx, and Traefik, ready to run a Django web application. Additionally, it provides a few handy shortcuts for easier development.
|
||||
|
||||
---
|
||||
Provides a quick and easy way to get started with a Django project using Docker.
|
||||
It comes with pre-configured services,
|
||||
including PostgreSQL, Redis, Celery (worker and beat),
|
||||
Nginx, and Traefik, that can be used to run a Django web application.
|
||||
It also comes with a few shortcuts to make development easier.
|
||||
|
||||
## Features 🚀
|
||||
|
||||
## Features
|
||||
- **Django** web application framework
|
||||
- **PostgreSQL** database
|
||||
- **Redis** in-memory data structure store
|
||||
- **Celery** worker and beat services for running background tasks asynchronously
|
||||
- **Nginx** web server for serving static and media files, and proxying requests to the Django application
|
||||
- **Traefik** reverse proxy for routing requests to the appropriate service and providing SSL termination
|
||||
|
||||
- Django web application framework
|
||||
- PostgreSQL database
|
||||
- Redis
|
||||
- Celery worker and beat services: Celery is a task queue that is used to run background tasks asynchronously.
|
||||
- Nginx web server: Used to serve static files and media files, and to proxy requests to the Django application.
|
||||
- Traefik reverse proxy: Used to route requests to the appropriate service. It also provides SSL termination.
|
||||
## Included Packages and Tools 🛠️
|
||||
|
||||
## Included Packages and Tools
|
||||
- **Pytest**: Testing framework
|
||||
- **Pytest Sugar**: A pytest plugin for a better look
|
||||
- **Pytest Django**: A pytest plugin providing useful tools for testing Django applications
|
||||
- **Coverage**: Test coverage tool
|
||||
- **Ruff**: Linter
|
||||
- **Black**: Code formatter
|
||||
|
||||
- Pytest: Testing framework
|
||||
- Pytest Sugar: Plugin for pytest that changes the default look
|
||||
- Pytest Django: Plugin for pytest that provides useful tools for testing Django applications
|
||||
- Coverage: Test coverage
|
||||
- Ruff: Linter
|
||||
- Black: Code formatter
|
||||
## Requirements 📋
|
||||
|
||||
## Requirements
|
||||
|
||||
- Docker & Docker Compose [Install and Use Docker](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04)
|
||||
- Docker & Docker Compose - [Install and Use Docker](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04)
|
||||
- Python 3.10 or higher
|
||||
- Make (optional for shortcuts)
|
||||
|
||||
---
|
||||
|
||||
## Getting Started
|
||||
## Getting Started 🏁
|
||||
|
||||
To get started, follow these steps:
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```
|
||||
1. **Clone the repository:**
|
||||
```bash
|
||||
git clone https://github.com/godd0t/django-docker-quickstart.git
|
||||
```
|
||||
|
||||
2. Change directory into the project:
|
||||
```
|
||||
2. **Change directory into the project:**
|
||||
```bash
|
||||
cd django-docker-quickstart
|
||||
```
|
||||
|
||||
3. Copy the `env.example` file to `.env` and update the values as needed:
|
||||
```
|
||||
3. **Copy the `env.example` file to `.env` and update the values as needed:**
|
||||
<br>
|
||||
**For Linux/macOS:**
|
||||
```bash
|
||||
cp env.example .env
|
||||
```
|
||||
**For Windows (Command Prompt):**
|
||||
```powershell
|
||||
Copy-Item -Path env.example -Destination .env
|
||||
```
|
||||
|
||||
## Initial Setup
|
||||
---
|
||||
|
||||
## Initial Setup ⚙️
|
||||
|
||||
### Development Prerequisites
|
||||
|
||||
To set up the project for development, follow these steps:
|
||||
|
||||
1. Create a virtual environment:
|
||||
```
|
||||
1. **Create a virtual environment:**
|
||||
```bash
|
||||
python -m venv venv
|
||||
```
|
||||
|
||||
2. Activate the virtual environment:
|
||||
```
|
||||
2. **Activate the virtual environment:**
|
||||
```bash
|
||||
source venv/bin/activate
|
||||
```
|
||||
|
||||
3. (Optional) Install the development requirements specific to your IDE for enhanced functionality and support.
|
||||
```
|
||||
3. **(Optional) Install the development requirements specific to your IDE for enhanced functionality and support.**
|
||||
```bash
|
||||
pip install -r src/requirements-dev.txt
|
||||
```
|
||||
4. Build the image and run the container:
|
||||
|
||||
4. **Build the image and run the container:**
|
||||
<br>
|
||||
- If buildkit is not enabled, enable it and build the image:
|
||||
```bash
|
||||
DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f docker-compose.yml up --build -d
|
||||
```
|
||||
|
||||
- If buildkit is enabled, build the image:
|
||||
```bash
|
||||
docker-compose -f docker-compose.yml up --build -d
|
||||
```
|
||||
Or you can use the shortcut:
|
||||
```
|
||||
|
||||
- Or, use the shortcut:
|
||||
```bash
|
||||
make build-dev
|
||||
```
|
||||
|
||||
Now you can access the application at http://localhost:8000.
|
||||
With the development environment, you can make changes to the code and the changes will be reflected immediately.
|
||||
You can now access the application at http://localhost:8000. The development environment allows for immediate reflection of code changes.
|
||||
|
||||
### Production Setup
|
||||
|
||||
### Production
|
||||
|
||||
To set up the project for production, follow these steps:
|
||||
|
||||
1. Build the image and run the container:
|
||||
1. **Build the image and run the container:**
|
||||
<br>
|
||||
- If buildkit is not enabled, enable it and build the image:
|
||||
```bash
|
||||
DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f docker-compose.prod.yml up --build -d
|
||||
```
|
||||
|
||||
- If buildkit is enabled,
|
||||
build the image:
|
||||
```bash
|
||||
docker-compose -f docker-compose.prod.yml up --build -d
|
||||
```
|
||||
Or you can use the shortcut:
|
||||
```
|
||||
- Or, use the shortcut:
|
||||
```bash
|
||||
make build-prod
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Shortcuts
|
||||
## Shortcuts 🔑
|
||||
|
||||
To make development easier, there are a few shortcuts available:
|
||||
This project includes several shortcuts to streamline the development process:
|
||||
|
||||
Create migrations:
|
||||
|
||||
```
|
||||
- **Create migrations:**
|
||||
```bash
|
||||
make make-migrations
|
||||
```
|
||||
|
||||
Run migrations:
|
||||
|
||||
```
|
||||
- **Run migrations:**
|
||||
```bash
|
||||
make migrate
|
||||
```
|
||||
|
||||
Run the linter:
|
||||
|
||||
```
|
||||
- **Run the linter:**
|
||||
```bash
|
||||
make lint
|
||||
```
|
||||
|
||||
Run the formatter:
|
||||
|
||||
```
|
||||
- **Run the formatter:**
|
||||
```bash
|
||||
make format
|
||||
```
|
||||
|
||||
Run the tests:
|
||||
|
||||
```
|
||||
- **Run the tests:**
|
||||
```bash
|
||||
make test
|
||||
```
|
||||
|
||||
Create a super user:
|
||||
|
||||
```
|
||||
- **Create a super user:**
|
||||
```bash
|
||||
make super-user
|
||||
```
|
||||
|
||||
Build and run dev environment:
|
||||
|
||||
```
|
||||
- **Build and run dev environment:**
|
||||
```bash
|
||||
make build-dev
|
||||
```
|
||||
|
||||
Build and run prod environment:
|
||||
|
||||
```
|
||||
- **Build and run prod environment:**
|
||||
```bash
|
||||
make build-prod
|
||||
```
|
||||
---
|
||||
|
@ -112,15 +112,6 @@ services:
|
||||
- "--log.level=DEBUG"
|
||||
- "--accesslog=true"
|
||||
- "--tracing=true"
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.dashboard.rule=Host(`${TRAEFIK_DOMAIN}`) && (PathPrefix(`/`))"
|
||||
- "traefik.http.routers.dashboard.tls=true"
|
||||
- "traefik.http.routers.dashboard.tls.certresolver=myresolver"
|
||||
- "traefik.http.routers.dashboard.entrypoints=websecure"
|
||||
- "traefik.http.routers.dashboard.service=api@internal"
|
||||
- "traefik.http.routers.dashboard.middlewares=auth"
|
||||
- "traefik.http.middlewares.auth.basicauth.users=user:$$2y$$05$$22TlNvU.X30m4rVd3aIA3.jF/XXkh6eayHg5UYwDNgF8MVFwJgPrS"
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
|
@ -3,9 +3,8 @@ APP_NAME=project_name
|
||||
APP_HOST=0.0.0.0
|
||||
APP_PORT=8000
|
||||
SECRET_KEY='ur secret key'
|
||||
APP_ENV=dev
|
||||
APP_ENV='dev' # Could be dev, prod or test
|
||||
DEBUG=True
|
||||
DJANGO_SETTINGS_MODULE=project_name.settings.dev
|
||||
ALLOWED_HOSTS='app.backend.dev'
|
||||
CSRF_TRUSTED_ORIGINS='https://*.backend.dev'
|
||||
CORS_ALLOWED_ORIGINS=http://app.backend.dev,http://localhost:3000
|
||||
|
@ -6,7 +6,8 @@ import sys
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")
|
||||
APP_ENV = os.getenv("APP_ENV", "dev")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", f"project_name.settings.{APP_ENV}")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
|
@ -11,6 +11,7 @@ import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")
|
||||
APP_ENV = os.getenv("APP_ENV", "dev")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", f"project_name.settings.{APP_ENV}")
|
||||
|
||||
application = get_asgi_application()
|
||||
|
@ -4,7 +4,8 @@ from celery import Celery
|
||||
from celery.schedules import crontab
|
||||
|
||||
# Set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings.dev")
|
||||
APP_ENV = os.getenv("APP_ENV", "dev")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", f"project_name.settings.{APP_ENV}")
|
||||
|
||||
app = Celery("project_name")
|
||||
|
||||
|
@ -11,6 +11,7 @@ import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings.dev")
|
||||
APP_ENV = os.getenv("APP_ENV", "dev")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", f"project_name.settings.{APP_ENV}")
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
Loading…
Reference in New Issue
Block a user