mirror of
				https://github.com/ijaric/voice_assistant.git
				synced 2025-10-30 23:43:25 +00:00 
			
		
		
		
	Merge pull request #9 from ijaric/features/#6_nginx
Шаблоны nginx для сервисов #6
This commit is contained in:
		
						commit
						5ddcfe32ad
					
				|  | @ -4,6 +4,7 @@ POSTGRES_USER=user | ||||||
| POSTGRES_PASSWORD=Qwe123 | POSTGRES_PASSWORD=Qwe123 | ||||||
| POSTGRES_NAME=api_db | POSTGRES_NAME=api_db | ||||||
| 
 | 
 | ||||||
|  | NGINX_PORT=80 | ||||||
| API_HOST=0.0.0.0 | API_HOST=0.0.0.0 | ||||||
| API_PORT=8000 | API_PORT=8000 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,14 +1,23 @@ | ||||||
| FROM python:3.11 | FROM python:3.11 | ||||||
| 
 | 
 | ||||||
|  | RUN apt-get update \ | ||||||
|  |   && DEBIAN_FRONTEND=noninteractive \ | ||||||
|  |   && apt-get install -y net-tools netcat-traditional curl \ | ||||||
|  |   && apt-get clean \ | ||||||
|  |   && rm -rf /var/lib/apt/lists/* | ||||||
|  | 
 | ||||||
|  | RUN mkdir --parents /opt/app | ||||||
|  | COPY pyproject.toml /opt/app/pyproject.toml | ||||||
|  | COPY poetry.lock /opt/app/poetry.lock | ||||||
|  | COPY poetry.toml /opt/app/poetry.toml | ||||||
|  | 
 | ||||||
| WORKDIR /opt/app | WORKDIR /opt/app | ||||||
| 
 | 
 | ||||||
| ENV PYTHONPATH '/opt/app' |  | ||||||
| 
 |  | ||||||
| COPY pyproject.toml ./ |  | ||||||
| RUN pip install poetry \     | RUN pip install poetry \     | ||||||
|     && poetry install --no-dev |     && poetry install --no-dev | ||||||
| 
 | 
 | ||||||
| COPY bin bin | COPY bin /opt/app/bin | ||||||
| COPY lib lib | COPY lib /opt/app/lib | ||||||
| COPY entrypoint.sh . | COPY entrypoint.sh /opt/app/entrypoint.sh | ||||||
|  | 
 | ||||||
| RUN chmod +x /opt/app/entrypoint.sh | RUN chmod +x /opt/app/entrypoint.sh | ||||||
|  |  | ||||||
|  | @ -1,8 +1,9 @@ | ||||||
| version: "3" | version: "3" | ||||||
| 
 | 
 | ||||||
| services: | services: | ||||||
|   db: |   postgres: | ||||||
|     image: postgres:15.2 |     image: postgres:15.2 | ||||||
|  |     restart: always | ||||||
|     environment: |     environment: | ||||||
|       POSTGRES_USER: ${POSTGRES_USER} |       POSTGRES_USER: ${POSTGRES_USER} | ||||||
|       POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} |       POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} | ||||||
|  | @ -13,7 +14,6 @@ services: | ||||||
|       - "${POSTGRES_PORT}:${POSTGRES_PORT}" |       - "${POSTGRES_PORT}:${POSTGRES_PORT}" | ||||||
|     volumes: |     volumes: | ||||||
|       - postgres_data:/var/lib/postgresql/data/ |       - postgres_data:/var/lib/postgresql/data/ | ||||||
|     restart: always |  | ||||||
|     networks: |     networks: | ||||||
|       - backend_network |       - backend_network | ||||||
| 
 | 
 | ||||||
|  | @ -24,24 +24,27 @@ services: | ||||||
|     image: fastapi_app |     image: fastapi_app | ||||||
|     restart: always |     restart: always | ||||||
|     entrypoint: ["/opt/app/entrypoint.sh"] |     entrypoint: ["/opt/app/entrypoint.sh"] | ||||||
|  |     env_file: | ||||||
|  |       - .env | ||||||
|     ports: |     ports: | ||||||
|       - "${API_PORT}:${API_PORT}" |       - "${API_PORT}:${API_PORT}" | ||||||
|     depends_on: |     depends_on: | ||||||
|       - db |       - postgres | ||||||
|     env_file: |  | ||||||
|       - .env |  | ||||||
|     networks: |     networks: | ||||||
|       - backend_network |       - backend_network | ||||||
|       - api_network |       - api_network | ||||||
| 
 | 
 | ||||||
|   nginx: |   nginx: | ||||||
|     image: nginx:1.23.4 |     image: nginx:1.25.1 | ||||||
|  |     env_file: | ||||||
|  |       - .env | ||||||
|  |     ports: | ||||||
|  |       - "${NGINX_PORT}:${NGINX_PORT}" | ||||||
|     volumes: |     volumes: | ||||||
|       - ./nginx:/etc/nginx/:ro |       - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro | ||||||
|  |       - ./nginx/templates:/etc/nginx/templates | ||||||
|     depends_on: |     depends_on: | ||||||
|       - api |       - api | ||||||
|     ports: |  | ||||||
|       - "80:80" |  | ||||||
|     networks: |     networks: | ||||||
|       - api_network |       - api_network | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,19 +1,19 @@ | ||||||
| version: "3" | version: "3" | ||||||
| 
 | 
 | ||||||
| services: | services: | ||||||
|   db: |   postgres: | ||||||
|     image: postgres:15.2 |     image: postgres:15.2 | ||||||
|  |     restart: always | ||||||
|     environment: |     environment: | ||||||
|       POSTGRES_USER: ${POSTGRES_USER} |       POSTGRES_USER: ${POSTGRES_USER} | ||||||
|       POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} |       POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} | ||||||
|       POSTGRES_DB: ${POSTGRES_NAME} |       POSTGRES_DB: ${POSTGRES_NAME} | ||||||
|     env_file: |     env_file: | ||||||
|       - .env |       - .env | ||||||
|     ports: |     expose: | ||||||
|       - "127.0.0.1:${API_PORT}:${API_PORT}" |       - "${POSTGRES_PORT}" | ||||||
|     volumes: |     volumes: | ||||||
|       - postgres_data:/var/lib/postgresql/data/ |       - postgres_data:/var/lib/postgresql/data/ | ||||||
|     restart: always |  | ||||||
|     networks: |     networks: | ||||||
|       - backend_network |       - backend_network | ||||||
| 
 | 
 | ||||||
|  | @ -24,22 +24,27 @@ services: | ||||||
|     image: fastapi_app |     image: fastapi_app | ||||||
|     restart: always |     restart: always | ||||||
|     entrypoint: ["/opt/app/entrypoint.sh"] |     entrypoint: ["/opt/app/entrypoint.sh"] | ||||||
|     depends_on: |  | ||||||
|       - db |  | ||||||
|     env_file: |     env_file: | ||||||
|       - .env |       - .env | ||||||
|  |     expose: | ||||||
|  |       - "${API_PORT}" | ||||||
|  |     depends_on: | ||||||
|  |       - postgres | ||||||
|     networks: |     networks: | ||||||
|       - backend_network |       - backend_network | ||||||
|       - api_network |       - api_network | ||||||
| 
 | 
 | ||||||
|   nginx: |   nginx: | ||||||
|     image: nginx:1.23.4 |     image: nginx:1.25.1 | ||||||
|  |     env_file: | ||||||
|  |       - .env | ||||||
|  |     ports: | ||||||
|  |       - "${NGINX_PORT}:${NGINX_PORT}" | ||||||
|     volumes: |     volumes: | ||||||
|       - ./nginx:/etc/nginx/:ro |       - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro | ||||||
|  |       - ./nginx/templates:/etc/nginx/templates | ||||||
|     depends_on: |     depends_on: | ||||||
|       - api |       - api | ||||||
|     ports: |  | ||||||
|       - "80:80" |  | ||||||
|     networks: |     networks: | ||||||
|       - api_network |       - api_network | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,5 @@ | ||||||
| #!/bin/bash | #!/bin/bash | ||||||
| 
 | 
 | ||||||
| while ! (echo > /dev/tcp/db/5432) >/dev/null 2>&1; do | while ! nc -z postgres 5432; do sleep 1; done; | ||||||
|   sleep 1 |  | ||||||
| done |  | ||||||
| 
 | 
 | ||||||
| exec .venv/bin/python -m bin | exec .venv/bin/python -m bin | ||||||
|  | @ -6,7 +6,7 @@ from .project import * | ||||||
| __all__ = [ | __all__ = [ | ||||||
|     "ApiSettings", |     "ApiSettings", | ||||||
|     "LoggingSettings", |     "LoggingSettings", | ||||||
|     "get_logging_config", |  | ||||||
|     "PostgresSettings", |     "PostgresSettings", | ||||||
|     "ProjectSettings", |     "ProjectSettings", | ||||||
|  |     "get_logging_config", | ||||||
| ] | ] | ||||||
|  |  | ||||||
|  | @ -1,10 +0,0 @@ | ||||||
| server { |  | ||||||
|     listen       80 default_server; |  | ||||||
|     listen       [::]:80 default_server; |  | ||||||
|     server_name  _; |  | ||||||
| 
 |  | ||||||
|     location /api { |  | ||||||
|         proxy_pass http://api:8000/api; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
|  | @ -5,12 +5,13 @@ events { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| http { | http { | ||||||
|  |   server_tokens off; | ||||||
|   include       mime.types; |   include       mime.types; | ||||||
|   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' |   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' | ||||||
|                       '$status $body_bytes_sent "$http_referer" ' |                       '$status $body_bytes_sent "$http_referer" ' | ||||||
|                       '"$http_user_agent" "$http_x_forwarded_for"'; |                       '"$http_user_agent" "$http_x_forwarded_for" "$request_id"'; | ||||||
| 
 | 
 | ||||||
|   server_tokens off; |   access_log /dev/stdout main; | ||||||
| 
 | 
 | ||||||
|   sendfile        on; |   sendfile        on; | ||||||
|   tcp_nodelay     on; |   tcp_nodelay     on; | ||||||
|  | @ -28,10 +29,11 @@ http { | ||||||
|         text/xml |         text/xml | ||||||
|         text/javascript; |         text/javascript; | ||||||
|    |    | ||||||
|  |   add_header X-Request-Id $request_id; | ||||||
|   proxy_redirect     off; |   proxy_redirect     off; | ||||||
|   proxy_set_header   Host             $host; |   proxy_set_header   Host             $host; | ||||||
|   proxy_set_header   X-Real-IP        $remote_addr; |   proxy_set_header   X-Real-IP        $remote_addr; | ||||||
|   proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; |   proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; | ||||||
| 
 | 
 | ||||||
|     include conf.d/site.conf; |   include conf.d/api.conf; | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										11
									
								
								src/fastapi_app/nginx/templates/api.conf.template
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/fastapi_app/nginx/templates/api.conf.template
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | ||||||
|  | server { | ||||||
|  |     listen       ${NGINX_PORT} default_server; | ||||||
|  |     listen       [::]:${NGINX_PORT} default_server; | ||||||
|  |     server_name  _; | ||||||
|  | 
 | ||||||
|  |     location /api { | ||||||
|  |         proxy_pass http://api:${API_PORT}/api; | ||||||
|  |         proxy_set_header X-Request-Id $request_id; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										6
									
								
								src/fastapi_app/poetry.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								src/fastapi_app/poetry.lock
									
									
									
										generated
									
									
									
								
							|  | @ -937,13 +937,13 @@ pycryptodome = ["pyasn1", "pycryptodome (>=3.3.1,<4.0.0)"] | ||||||
| 
 | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "pyupgrade" | name = "pyupgrade" | ||||||
| version = "3.11.1" | version = "3.12.0" | ||||||
| description = "A tool to automatically upgrade syntax for newer versions." | description = "A tool to automatically upgrade syntax for newer versions." | ||||||
| optional = false | optional = false | ||||||
| python-versions = ">=3.8.1" | python-versions = ">=3.8.1" | ||||||
| files = [ | files = [ | ||||||
|     {file = "pyupgrade-3.11.1-py2.py3-none-any.whl", hash = "sha256:6e9dd362394b3068123e06ca268de5845d41e2bb29f387b38323cc1009fb3100"}, |     {file = "pyupgrade-3.12.0-py2.py3-none-any.whl", hash = "sha256:c6f9c129560b9538e75b93fb0aee20508faae454714e8373d462e408985bd96a"}, | ||||||
|     {file = "pyupgrade-3.11.1.tar.gz", hash = "sha256:3e6c7689d2f3ae418c6a60ee981477fe9130eccaed3e33dac6c21274cf7d45f4"}, |     {file = "pyupgrade-3.12.0.tar.gz", hash = "sha256:defc292ffaf402942b8fccaa97491964063e343fc1993230e44890b971dc1234"}, | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| [package.dependencies] | [package.dependencies] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user