feat: add initial Docker Compose infrastructure

This commit is contained in:
2026-04-28 11:08:06 +02:00
parent 18ab0a8b99
commit 04f31c5105
15 changed files with 279 additions and 14 deletions

View File

@@ -0,0 +1,22 @@
FROM python:3.13.4-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
RUN pip install --no-cache-dir \
"Django==5.2.3" \
"djangorestframework==3.16.0" \
"gunicorn==23.0.0" \
"psycopg[binary]==3.2.9"
RUN useradd --create-home --shell /usr/sbin/nologin appuser
COPY placeholder_wsgi.py /app/placeholder_wsgi.py
USER appuser
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "placeholder_wsgi:application"]

View File

@@ -0,0 +1,10 @@
def application(environ, start_response):
body = b"AzioneLab backend placeholder\n"
start_response(
"503 Service Unavailable",
[
("Content-Type", "text/plain; charset=utf-8"),
("Content-Length", str(len(body))),
],
)
return [body]

77
infra/docker/compose.yml Normal file
View File

@@ -0,0 +1,77 @@
services:
backend:
build:
context: ./backend
image: azionelab-backend:local
environment:
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY}
DJANGO_ALLOWED_HOSTS: ${DJANGO_ALLOWED_HOSTS}
DJANGO_CSRF_TRUSTED_ORIGINS: ${DJANGO_CSRF_TRUSTED_ORIGINS}
DJANGO_DEBUG: ${DJANGO_DEBUG:-false}
DATABASE_URL: ${DATABASE_URL}
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_HOST: ${POSTGRES_HOST:-postgres}
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
expose:
- "${BACKEND_PORT:-8000}"
depends_on:
postgres:
condition: service_healthy
networks:
- internal
restart: unless-stopped
frontend:
build:
context: ./frontend
image: azionelab-frontend:local
expose:
- "${FRONTEND_PORT:-8080}"
networks:
- internal
restart: unless-stopped
postgres:
image: postgres:16.3-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U \"$${POSTGRES_USER}\" -d \"$${POSTGRES_DB}\""]
interval: 10s
timeout: 5s
retries: 5
networks:
- internal
restart: unless-stopped
nginx:
image: nginx:1.27.0-alpine
ports:
- "${NGINX_HTTP_PORT:-8080}:80"
environment:
BACKEND_HOST: ${BACKEND_HOST:-backend}
BACKEND_PORT: ${BACKEND_PORT:-8000}
FRONTEND_HOST: ${FRONTEND_HOST:-frontend}
FRONTEND_PORT: ${FRONTEND_PORT:-8080}
NGINX_ENVSUBST_FILTER: "^(BACKEND_HOST|BACKEND_PORT|FRONTEND_HOST|FRONTEND_PORT)$"
volumes:
- ./nginx/templates:/etc/nginx/templates:ro
depends_on:
- backend
- frontend
networks:
- internal
restart: unless-stopped
volumes:
postgres_data:
networks:
internal:
driver: bridge

View File

@@ -0,0 +1,6 @@
FROM nginx:1.27.0-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY html/ /usr/share/nginx/html/
EXPOSE 8080

View File

@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AzioneLab</title>
</head>
<body>
<main>
<h1>AzioneLab frontend placeholder</h1>
<p>The Angular application build will replace this page.</p>
</main>
</body>
</html>

View File

@@ -0,0 +1,11 @@
server {
listen 8080;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}

View File

@@ -0,0 +1,50 @@
upstream azionelab_backend {
server ${BACKEND_HOST}:${BACKEND_PORT};
}
upstream azionelab_frontend {
server ${FRONTEND_HOST}:${FRONTEND_PORT};
}
server {
listen 80;
server_name _;
client_max_body_size 10m;
location /api/ {
proxy_pass http://azionelab_backend;
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;
}
location /admin/ {
proxy_pass http://azionelab_backend;
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;
}
location /static/ {
proxy_pass http://azionelab_backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /media/ {
proxy_pass http://azionelab_backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://azionelab_frontend;
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;
}
}