diff --git a/src/fastapi_example/.dockerignore b/src/fastapi_example/.dockerignore new file mode 100644 index 0000000..c2eabec --- /dev/null +++ b/src/fastapi_example/.dockerignore @@ -0,0 +1,2 @@ +.venv +.env \ No newline at end of file diff --git a/src/fastapi_example/.env.example b/src/fastapi_example/.env.example new file mode 100644 index 0000000..24af6c4 --- /dev/null +++ b/src/fastapi_example/.env.example @@ -0,0 +1,11 @@ +LOG_LEVEL_HANDLERS=INFO +LOG_LEVEL_LOGGERS=INFO +LOG_LEVEL_ROOT=INFO +API_PORT=8000 + +NGINX_PORT=80 + +PROJET_NAME="FastAPI Template" +PROJECT_DESCRIPTION="FastAPI Template Project using DDD" +PROJECT_VERSION=0.0.1 + diff --git a/src/fastapi_example/Dockerfile b/src/fastapi_example/Dockerfile new file mode 100644 index 0000000..60d5464 --- /dev/null +++ b/src/fastapi_example/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.11 + +RUN apt-get update + +WORKDIR /opt/app + +ENV PYTHONPATH '/opt/app' + +COPY pyproject.toml ./ +COPY poetry.lock ./ +RUN apt-get update \ + && pip install poetry \ + && poetry config virtualenvs.create false \ + && poetry install --no-dev + +COPY backend . + +# CMD ["python", "-m", "bin"] \ No newline at end of file diff --git a/src/fastapi_example/docker-compose.yaml b/src/fastapi_example/docker-compose.yaml new file mode 100644 index 0000000..2a46722 --- /dev/null +++ b/src/fastapi_example/docker-compose.yaml @@ -0,0 +1,30 @@ +version: '3' + +services: + api: + build: + context: . + ports: + - "${API_PORT}:${API_PORT}" + expose: + - ${API_PORT} + env_file: + - .env + + nginx: + image: nginx:1.25.1 + restart: always + env_file: + - .env + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + - ./nginx/templates:/etc/nginx/templates + ports: + - "${NGINX_PORT}:${NGINX_PORT}" + depends_on: + - api + +networks: + default: + driver: bridge + diff --git a/src/fastapi_example/nginx/nginx.conf b/src/fastapi_example/nginx/nginx.conf new file mode 100644 index 0000000..5da662d --- /dev/null +++ b/src/fastapi_example/nginx/nginx.conf @@ -0,0 +1,38 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + include mime.types; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + server_tokens off; + + sendfile on; + tcp_nodelay on; + tcp_nopush on; + client_max_body_size 200m; + + gzip on; + gzip_comp_level 3; + gzip_min_length 1000; + gzip_types + text/plain + text/css + application/json + application/x-javascript + text/xml + text/javascript; + + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + include conf.d/api.conf; + include conf.d/rabbitmq.conf; +} \ No newline at end of file diff --git a/src/fastapi_example/nginx/templates/api.conf.template b/src/fastapi_example/nginx/templates/api.conf.template new file mode 100644 index 0000000..847d018 --- /dev/null +++ b/src/fastapi_example/nginx/templates/api.conf.template @@ -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; + } + +} \ No newline at end of file diff --git a/src/fastapi_example/pyproject.toml b/src/fastapi_example/pyproject.toml index b0e7c2f..9d63757 100644 --- a/src/fastapi_example/pyproject.toml +++ b/src/fastapi_example/pyproject.toml @@ -14,8 +14,8 @@ profile = "black" [tool.poetry] authors = ["name "] description = "FastAPI Template Project using DDD" -name = "FastAPI Exmaple" -version = "0.1.0" +name = "FastAPI Template" +version = "0.0.1" [tool.poetry.dependencies] black = "^23.9.1"