diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..504c15f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,23 @@ +# Ignore compiled python files +*.pyc +*.pyo +*.pyd +__pycache__ + +# Ignore environment related files +# .env +.venv +*.log +env/ + +# Ignore all git files +.git/ +.gitignore + +# Ignore OS generated files +.DS_Store +Thumbs.db + +db.sqlite3 + +poetry.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5b06cf0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.11-slim-buster + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Install system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + libpq-dev \ + curl \ + && rm -rf /var/lib/apt/lists/* + +RUN mkdir /app +WORKDIR /app + +RUN pip install poetry +COPY pyproject.toml /app + +COPY . /app +RUN poetry install + +CMD ["./start_app.sh"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..6c6c787 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,60 @@ +version: '3.8' + +services: + ifsguid_nginx: + build: ./nginx + image: nginx:alpine + restart: unless-stopped + container_name: ifsguid_nginx + ports: + - "80:80" + volumes: + - "./nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf:ro" + - "./nginx/static:/static:ro" + depends_on: + - ifsguid_app + logging: + driver: "json-file" + options: + max-size: "50m" + + ifsguid_db: + image: postgres:15-alpine + restart: unless-stopped + expose: + - "5432" + ports: + - "5432:5432" + container_name: ifsguid_db + volumes: + - ifsguid-postgres-data:/var/lib/postgresql/data + logging: + driver: "json-file" + options: + max-size: "50m" + env_file: + - .env + + ifsguid_app: + build: . + image: ifsguid:1.0.0 + container_name: ifsguid_app + restart: unless-stopped + volumes: + - "/etc/timezone:/etc/timezone:ro" + - "/etc/localtime:/etc/localtime:ro" + - "./nginx:/opt/nginx:rw" + env_file: + - ./.docker.env + expose: + - "8000" + depends_on: + - ifsguid_db + logging: + driver: "json-file" + options: + max-size: "50m" + +volumes: + ifsguid-postgres-data: + driver: local diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..8e5916e --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx:1.19.0-alpine + +RUN rm /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..fbf7834 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,37 @@ +upstream ifsguid { + server ifsguid_app:8000; +} + +limit_req_zone $binary_remote_addr zone=one:10m rate=50r/s; + +server { + client_max_body_size 20m; + + listen 80; + + location / { + proxy_pass http://ifsguid; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + proxy_intercept_errors on; + proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; + error_page 404 /custom_404.html; + error_page 502 503 504 /custom_404.html; + } + + location /static/ { + alias /static/; + } + + error_page 404 /custom_404.html; + error_page 502 /custom_502.html; + location = /custom_404.html { + root /static/error_pages; + internal; + } + location = /custom_502.html { + root /static/error_pages; + internal; + } +} diff --git a/nginx/static/error_pages/custom_404.html b/nginx/static/error_pages/custom_404.html new file mode 100755 index 0000000..e70be5a --- /dev/null +++ b/nginx/static/error_pages/custom_404.html @@ -0,0 +1,59 @@ + + +
+ +