Containerize backend api and add erd generator via django-extensions

This commit is contained in:
Keannu Bernasol 2024-11-24 12:25:57 +08:00
parent cf981c3c08
commit 9b78fdd9ae
7 changed files with 72 additions and 1 deletions

1
.gitignore vendored
View file

@ -165,3 +165,4 @@ cython_debug/
**/__pycache__/ **/__pycache__/
.vscode/ .vscode/
schema.yml

19
Dockerfile Normal file
View file

@ -0,0 +1,19 @@
FROM python:3.13.0-bullseye
ENV PYTHONBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /app
COPY . /app/
ADD . /app/
COPY scripts/ /app/scripts/
RUN chmod +x /app/scripts/start.sh
# Install packages
RUN apt update && apt install -y graphviz libgraphviz-dev graphviz-dev
RUN pip3 install --upgrade pip && pip3 install --no-cache-dir -r requirements.txt
# Expose port 8000 for the web server
EXPOSE 8000
ENTRYPOINT [ "/app/scripts/start.sh" ]

30
docker-compose.dev.yml Normal file
View file

@ -0,0 +1,30 @@
services:
django:
env_file: .env
build:
context: .
dockerfile: Dockerfile
image: git.06222001.xyz/keannu125/docmanager_backend:dev
ports:
- "${BACKEND_PORT}:8000"
environment:
- PYTHONBUFFERED=1
volumes:
- .:/app
# SMTP Server
inbucket:
image: inbucket/inbucket:latest
ports:
- "8025:8025"
environment:
- INBUCKET_LOGLEVEL=error
- INBUCKET_MAILBOXNAMING=domain
- INBUCKET_SMTP_ADDR=0.0.0.0:1025
- INBUCKET_SMTP_MAXRECIPIENTS=1000
- INBUCKET_WEB_ADDR=0.0.0.0:8025
- INBUCKET_STORAGE_TYPE=memory
- INBUCKET_STORAGE_MAILBOXMSGCAP=2000
volumes:
db-data:

View file

@ -82,6 +82,7 @@ INSTALLED_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"django_extensions",
"rest_framework", "rest_framework",
"rest_framework_simplejwt", "rest_framework_simplejwt",
"djoser", "djoser",
@ -260,3 +261,6 @@ DEFAULT_FROM_EMAIL = EMAIL_ADDRESS
AUTH_USER_MODEL = "accounts.CustomUser" AUTH_USER_MODEL = "accounts.CustomUser"
DATA_UPLOAD_MAX_NUMBER_FIELDS = 20480 DATA_UPLOAD_MAX_NUMBER_FIELDS = 20480
GRAPH_MODELS = {"app_labels": [
"accounts", "documents", "document_requests", "questionnaires"]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

View file

@ -44,3 +44,5 @@ tzdata==2024.2
uritemplate==4.1.1 uritemplate==4.1.1
urllib3==2.2.3 urllib3==2.2.3
whitenoise==6.8.2 whitenoise==6.8.2
django-extensions==3.2.3
pygraphviz==1.14; platform_system == 'Linux'

15
scripts/start.sh Normal file
View file

@ -0,0 +1,15 @@
#!/bin/bash
cd docmanager_backend/
python manage.py graph_models -o ../documentation/erd/app_models.png
python manage.py spectacular --color --file schema.yml
python manage.py migrate
if [ ! -d "static" ]; then
echo "Generating static files"
python manage.py collectstatic --noinput
fi
if [ "$DEBUG" = 'True' ]; then
python manage.py runserver "0.0.0.0:8000"
else
gunicorn --workers 8 --bind 0.0.0.0:8000 config.wsgi:application
fi