From 79c21507dfabe4311f183b25da41c83cc7051940 Mon Sep 17 00:00:00 2001 From: dsuhoi Date: Mon, 31 Jul 2023 09:37:36 +0300 Subject: [PATCH] Added Nginx. --- README.md | 2 +- backend/.dockerignore | 13 ++++++++ backend/Dockerfile | 6 +--- docker-compose.yml | 21 +++++------- frontend/.dockerignore | 13 ++++++++ frontend/Dockerfile | 3 +- frontend/main.py | 3 +- nginx/nginx.conf | 38 ++++++++++++++++++++++ {Pipeline => pipeline}/README.md | 0 {Pipeline => pipeline}/collect_metric.py | 0 {Pipeline => pipeline}/data/districts.json | 0 {Pipeline => pipeline}/main.py | 0 {Pipeline => pipeline}/poetry.lock | 0 {Pipeline => pipeline}/pyproject.toml | 0 14 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 backend/.dockerignore create mode 100644 frontend/.dockerignore create mode 100644 nginx/nginx.conf rename {Pipeline => pipeline}/README.md (100%) rename {Pipeline => pipeline}/collect_metric.py (100%) rename {Pipeline => pipeline}/data/districts.json (100%) rename {Pipeline => pipeline}/main.py (100%) rename {Pipeline => pipeline}/poetry.lock (100%) rename {Pipeline => pipeline}/pyproject.toml (100%) diff --git a/README.md b/README.md index bbc4708..beca43c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ которые могут быть полезны при оценке благоустройства определенной местности. ## Архитектура -Сервис состоит из трех основных частей: +Сервис состоит из четырех основных частей: - База данных для хранения геоданных (PostGis) - [Backend](#backend) - [Frontend](#frontend) diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..3f2dc2c --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,13 @@ +# Git +.git +.gitignore + +# Byte-compiled / optimized / DLL files +**/__pycache__/ +**/*.py[cod] + +# Python +.env +.venv/ +venv/ +env/ diff --git a/backend/Dockerfile b/backend/Dockerfile index dab0e14..d619602 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -5,11 +5,7 @@ WORKDIR /backend_app RUN apt-get update && apt-get install -y libpq-dev netcat RUN pip3 install poetry -COPY *.py pytest.ini poetry.lock pyproject.toml ./ -COPY core/ ./core/ -COPY routers/ ./routers/ -COPY data/ ./data/ -COPY tests/ ./tests/ +COPY . . RUN poetry config virtualenvs.create false \ && poetry install --no-root --no-interaction --no-ansi diff --git a/docker-compose.yml b/docker-compose.yml index da1a039..b208ef9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,6 @@ services: - postgres_data:/var/lib/postgresql/data/ expose: - ${DB_HOST} - # networks: - # - default environment: - POSTGRES_DB=${DB_DATABASE} - POSTGRES_USER=${DB_USERNAME} @@ -21,8 +19,6 @@ services: - ./backend:/backend_app ports: - 8001:8000 - # networks: - # - default environment: - DATABASE_URL=postgresql+asyncpg://${DB_USERNAME}:${DB_PASSWORD}@db:${DB_HOST}/${DB_DATABASE} env_file: @@ -33,17 +29,18 @@ services: build: ./frontend ports: - 8051:8051 - # networks: - # - default - # network_mode: host env_file: - ./.env depends_on: - backend - + nginx: + image: nginx:alpine + ports: + - 8081:8080 + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + depends_on: + - backend + - frontend volumes: postgres_data: -networks: - default: - # outside: - # external: true diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..3f2dc2c --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,13 @@ +# Git +.git +.gitignore + +# Byte-compiled / optimized / DLL files +**/__pycache__/ +**/*.py[cod] + +# Python +.env +.venv/ +venv/ +env/ diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 4848abd..9ee2a48 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -3,9 +3,8 @@ FROM python:3.10-slim WORKDIR /frontend_app RUN pip3 install poetry -COPY *.py *.geojson poetry.lock pyproject.toml ./ +COPY . . RUN poetry config virtualenvs.create false \ && poetry install --no-root --no-interaction --no-ansi CMD ["streamlit", "run", "main.py"] -#, "--server.address=0.0.0.0"] diff --git a/frontend/main.py b/frontend/main.py index 778fea9..6b0dcc5 100644 --- a/frontend/main.py +++ b/frontend/main.py @@ -4,9 +4,10 @@ import streamlit as st from streamlit_folium import folium_static -URL = "http://backend:8000/geo" +URL = "http://nginx:8080/api/geo" all_cities = requests.get(f"{URL}/cities").json() +print(all_cities) select_city_vars = {"Все города": "all"} | { city["title"]: city["id"] for city in all_cities } diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..39eb9b0 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,38 @@ +worker_processes 1; + +events { worker_connections 1024; } + +http { + sendfile on; + + gzip on; + gzip_http_version 1.1; + gzip_disable "MSIE [1-6]\."; + + upstream frontend { + server frontend:8501; + } + + upstream backend { + server backend:8000; + } + + server { + listen 8080; + + location / { + proxy_pass http://frontend; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + location /api { + rewrite /api/(.*) /$1 break; + proxy_pass http://backend; + } + } +} diff --git a/Pipeline/README.md b/pipeline/README.md similarity index 100% rename from Pipeline/README.md rename to pipeline/README.md diff --git a/Pipeline/collect_metric.py b/pipeline/collect_metric.py similarity index 100% rename from Pipeline/collect_metric.py rename to pipeline/collect_metric.py diff --git a/Pipeline/data/districts.json b/pipeline/data/districts.json similarity index 100% rename from Pipeline/data/districts.json rename to pipeline/data/districts.json diff --git a/Pipeline/main.py b/pipeline/main.py similarity index 100% rename from Pipeline/main.py rename to pipeline/main.py diff --git a/Pipeline/poetry.lock b/pipeline/poetry.lock similarity index 100% rename from Pipeline/poetry.lock rename to pipeline/poetry.lock diff --git a/Pipeline/pyproject.toml b/pipeline/pyproject.toml similarity index 100% rename from Pipeline/pyproject.toml rename to pipeline/pyproject.toml