fix: readme && add healthcheck on db

This commit is contained in:
godd0t 2023-05-10 21:48:56 +02:00
parent 388c224fc8
commit 5bab2c11b2
4 changed files with 80 additions and 17 deletions

View File

@ -13,6 +13,10 @@ make test Run tests
make super-user Create super user
make make-migrations Make migrations
make migrate Migrate
make build-dev Build and run dev environment
make stop-dev Stop dev environment
make stop-prod Stop prod environment
make build-prod Build and run prod environment
make all Show help
endef
@ -43,6 +47,18 @@ migrate:
docker exec -it $(BACKEND_APP_NAME) $(SHELL) "-c" \
"python manage.py migrate"
build-dev:
docker-compose -f docker-compose.yml up --build -d
build-prod:
docker-compose -f docker-compose.prod.yml up --build -d
stop-dev:
@docker-compose -f docker-compose.yml down
stop-prod:
@docker-compose -f docker-compose.prod.yml down
all: help
.PHONY: help lint format test super-user make-migrations migrate all
.PHONY: help lint format test super-user make-migrations migrate build-dev build-prod stop-dev stop-prod all

View File

@ -1,15 +1,30 @@
# Django Docker Quickstart
# Django Docker Boilerplate
This is a quickstart for Django with Docker.
---
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
- Django
- PostgreSQL
- Django web application framework
- PostgreSQL database
- Redis
- Celery(worker and beat)
- Nginx
- Traefik
- 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
- 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
@ -41,7 +56,7 @@ To get started, follow these steps:
## Initial Setup
### Development
### Development Prerequisites
To set up the project for development, follow these steps:
@ -59,11 +74,17 @@ To set up the project for development, follow these steps:
```
pip install -r requirements/requirements-dev.txt
```
4. Build the image and run the container:
```
docker-compose -f docker-compose.dev.yml up --build -d
```
Or you can use the shortcut:
```
make build-dev
```
4. Build and run the project:
```
docker-compose up --build -d
```
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.
### Production
@ -74,6 +95,10 @@ To set up the project for production, follow these steps:
```
docker-compose -f docker-compose.prod.yml up --build -d
```
Or you can use the shortcut:
```
make build-prod
```
## Shortcuts
@ -115,3 +140,15 @@ Create a super user:
```
make super-user
```
Build and run dev environment:
```
make build-dev
```
Build and run prod environment:
```
make build-prod
```

View File

@ -24,8 +24,8 @@ services:
expose:
- "${APP_PORT:-8000}"
depends_on:
- db
- redis
db:
condition: service_healthy
command: [ "/bin/sh", "/app/deployment/scripts/backend/start.sh" ]
db:
@ -38,6 +38,11 @@ services:
expose:
- "${POSTGRES_PORT:-5432}"
shm_size: 1g
healthcheck:
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}", "-d", "${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
redis:

View File

@ -17,8 +17,8 @@ services:
ports:
- "${APP_PORT}:${APP_PORT}"
depends_on:
- db
- redis
db:
condition: service_healthy
command: [ "/bin/sh", "/app/deployment/scripts/backend/start.sh" ]
db:
@ -31,6 +31,11 @@ services:
expose:
- "${POSTGRES_PORT:-5432}"
shm_size: 1g
healthcheck:
test: [ "CMD", "pg_isready", "-U", "${POSTGRES_USER}", "-d", "${POSTGRES_DB}" ]
interval: 10s
timeout: 5s
retries: 5
redis: