Skip to content

Commit

Permalink
Added Nginx.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuhoi committed Jul 31, 2023
1 parent f405f82 commit 79c2150
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
которые могут быть полезны при оценке благоустройства определенной местности.

## Архитектура
Сервис состоит из трех основных частей:
Сервис состоит из четырех основных частей:
- База данных для хранения геоданных (PostGis)
- [Backend](#backend)
- [Frontend](#frontend)
Expand Down
13 changes: 13 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Git
.git
.gitignore

# Byte-compiled / optimized / DLL files
**/__pycache__/
**/*.py[cod]

# Python
.env
.venv/
venv/
env/
6 changes: 1 addition & 5 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 9 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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:
Expand All @@ -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
13 changes: 13 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Git
.git
.gitignore

# Byte-compiled / optimized / DLL files
**/__pycache__/
**/*.py[cod]

# Python
.env
.venv/
venv/
env/
3 changes: 1 addition & 2 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 2 additions & 1 deletion frontend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
38 changes: 38 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 79c2150

Please sign in to comment.