Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Ignore Python bytecode files
**/__pycache__
**/*.pyc
**/*.pyo

# Ignore version control folders
.git
.gitignore

# Ignore virtual environments
env/
venv/
ENV/

# Ignore distribution / packaging folders
build/
dist/
.eggs/
*.egg-info/
*.whl

# Ignore documentation builds
docs/_build

# Ignore Dockerfile and Docker-compose files (optional)
Dockerfile
docker-compose.yml

# Ignore environment and secrets files


# Ignore logs and coverage reports
*.log
*.coverage
.coverage
.pytest_cache/

# Ignore Jupyter Notebook checkpoints
.ipynb_checkpoints
90 changes: 90 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
venv/
ENV/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
*.whl

# PyInstaller
# Usually these files are written by a python script from a template
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
.pytype/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# Jupyter Notebook
.ipynb_checkpoints

# Pyre type checker
.pyre/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Environment variables file
.venv

# IDE files
.vscode/
.idea/
*.sublime-project
*.sublime-workspace
File renamed without changes.
11 changes: 6 additions & 5 deletions Dockerfile → django_project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM python:3.8.5-alpine
FROM python:3.12-slim


RUN pip install --upgrade pip

COPY ./requirements.txt .
RUN pip install -r requirements.txt

COPY ./django_project /app

WORKDIR /app
COPY . .

RUN pip install --upgrade pip
RUN pip install -r requirements.txt

COPY ./entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]
Expand Down
6 changes: 5 additions & 1 deletion django_project/django_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"""

import os
from dotenv import load_dotenv

load_dotenv()

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -26,7 +29,7 @@

# SECURITY WARNING: don't run with debug turned on in production!
#DEBUG = True
DEBUG = os.getenv('DEBUG')
DEBUG = os.getenv('SECRET_KEY') == 'True'

ALLOWED_HOSTS = ['*']

Expand Down Expand Up @@ -122,3 +125,4 @@

STATIC_ROOT = '/static/'
STATIC_URL = '/static/'
CSRF_TRUSTED_ORIGINS = ['http://localhost', 'http://127.0.0.1', 'https://yourdomain.com']
2 changes: 1 addition & 1 deletion entrypoint.sh → django_project/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ python manage.py collectstatic --no-input

DJANGO_SUPERUSER_PASSWORD=$SUPER_USER_PASSWORD python manage.py createsuperuser --username $SUPER_USER_NAME --email $SUPER_USER_EMAIL --noinput

gunicorn django_project.wsgi:application --bind 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000

4 changes: 4 additions & 0 deletions django_project/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
asgiref==3.8.1
Django==5.1.3
python-dotenv==1.0.1
sqlparse==0.5.1
29 changes: 29 additions & 0 deletions docker-compose-https.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
backend:
build:
context: .
dockerfile: Dockerfile
container_name: backend_service
command: uvicorn src.sapi:app --host 0.0.0.0 --port ${BACKEND_PORT} --reload
ports:
- "${BACKEND_PORT}:${BACKEND_PORT}"
env_file:
- .env
volumes:
- .:/app
restart: always

nginx:
build: ./nginx
container_name: nginx_service
ports:
- "80:80"
- "443:443"
depends_on:
- backend
restart: always
env_file:
- .env
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt:/etc/letsencrypt # Mounting SSL certificates and configs
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
version: '3.7'

services:
django_gunicorn:
volumes:
- static:/static
env_file:
- .env
build:
context: .
context: ./django_project
command: python manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"
volumes:
- static:/app/static
env_file:
- ./django_project/.env


nginx:
build: ./nginx
volumes:
- static:/static
ports:
- "80:80"
volumes:
- static:/static
depends_on:
- django_gunicorn

volumes:
static:

4 changes: 3 additions & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM nginx:1.19.0-alpine
# Use the latest Alpine-based NGINX image or a specific version
FROM nginx:alpine

# Copy your custom configuration file into the NGINX configuration directory
COPY ./default.conf /etc/nginx/conf.d/default.conf
35 changes: 35 additions & 0 deletions nginx/default-https.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
upstream backend_ai {
server backend:8000;
}

server {
listen 80;
server_name test.serenus.one;

# Redirect HTTP to HTTPS
location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl http2; # Enable HTTP/2 for better performance
server_name test.serenus.one;

# SSL settings provided by Certbot
ssl_certificate /etc/letsencrypt/live/test.serenus.one/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/test.serenus.one/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

# Add HSTS header for additional security (enforces HTTPS)
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

location / {
proxy_pass http://backend_ai;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.