From 004eddfc84019eae21348a2d40140edfff1dccf7 Mon Sep 17 00:00:00 2001 From: LUCAS ANDRADE ZANETTI Date: Tue, 3 Jun 2025 10:05:00 -0300 Subject: [PATCH 1/2] Sistema de Docker (Ainda falta resolver uns bugs) --- auth_service/Dockerfile | 27 +++++++++++++++++++++ auth_service/__init__.py | 0 auth_service/pyproject.toml | 10 ++++++-- docker-compose.yml | 47 +++++++++++++++++++++++++++++++++++++ internal_apis/Dockerfile | 17 ++++++++++++++ poetry.lock | 7 ++++++ pyproject.toml | 16 +++++++++++++ 7 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 auth_service/Dockerfile create mode 100644 auth_service/__init__.py create mode 100644 internal_apis/Dockerfile create mode 100644 poetry.lock create mode 100644 pyproject.toml diff --git a/auth_service/Dockerfile b/auth_service/Dockerfile new file mode 100644 index 0000000..731945a --- /dev/null +++ b/auth_service/Dockerfile @@ -0,0 +1,27 @@ +FROM python:3.13.3-slim + +WORKDIR /auth_service + +COPY . . + +RUN pip install poetry + +# Adds poetry to PATH +ENV PATH="/root/.local/bin:$PATH" + +# Make poetry not run in other virtual enviroment (run in his own container) +RUN poetry config virtualenvs.create false + +RUN poetry install --no-root + +EXPOSE 5050 + +CMD ["poetry", "run", "gunicorn", "-w", "2", "-b", "0.0.0.0:5050", "main:auth_app"] +## Comando que será executado + # "poetry": Chama o Poetry + # "run": Executar os comandos dentro do ambiente virtual do poetry + # "gunicorn": servidor HTTP para aplicações Python WSGI + # "-w" e "2": Vai definir o número de processos que o Gunicorn vai usar + # "-b" e "0.0.0.0:5050": Fazer com que Gunicorn funcione em todos os endereções IP + # "main:internal_api" Qual aplicação rodar - (main-> nome do arquivo python & auth_app-> nome da variável do app) + \ No newline at end of file diff --git a/auth_service/__init__.py b/auth_service/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/auth_service/pyproject.toml b/auth_service/pyproject.toml index 0c06ba6..7f55c21 100644 --- a/auth_service/pyproject.toml +++ b/auth_service/pyproject.toml @@ -1,9 +1,13 @@ [tool.poetry] -name = "auth-service" +name = "auth_service" version = "0.1.0" description = "serviço de autenticação para o cluster do LabTech" authors = ["Danrley Pereira "] -readme = "README.md" +readme = "deployment.md" +packages = [{include = "*.py"}] +package-mode = false + + [tool.poetry.dependencies] python = "^3.12" @@ -21,3 +25,5 @@ redis = "^5.2.1" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + + diff --git a/docker-compose.yml b/docker-compose.yml index d80fb8a..d5516e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,6 +23,53 @@ services: options: max-size: "10m" max-file: "3" + + auth-service: + build: + context: ./auth_service + dockerfile: Dockerfile + container_name: auth_service + restart: unless-stopped + ports: + - "5050:5050" + depends_on: + - redis-local + environment: + - REDIS_HOST=redis-local + - REDIS_PORT=6379 + - REDIS_URL=redis://redis-local:6379/0 + + internal_apis: + build: + context: ./internal_apis + dockerfile: Dockerfile + container_name: internal_apis + restart: unless-stopped + ports: + - "5081:5081" + depends_on: + - redis-local + - mongo + environment: + - REDIS_HOST=redis-local + - REDIS_PORT=6379 + - REDIS_URL=redis://redis-local:6379/0 + - MONGO_URI=mongodb://mongo:27017/shared-resources + - MONGO_DATABASE=shared-resources + + + + mongo: + image: mongo:6.0 + container_name: mongo + restart: unless-stopped + ports: + - "27017:27017" + volumes: + - mongo-data:/data/db + volumes: redis-data: driver: local + mongo-data: + driver: local \ No newline at end of file diff --git a/internal_apis/Dockerfile b/internal_apis/Dockerfile new file mode 100644 index 0000000..f918005 --- /dev/null +++ b/internal_apis/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.13.3-slim + +WORKDIR /internal_apis + +COPY . . + +RUN pip install poetry + +ENV PATH="/root/.local/bin:$PATH" + +RUN poetry config virtualenvs.create false + +RUN poetry install --no-root + +EXPOSE 5081 + +CMD ["poetry", "run", "gunicorn", "-w", "2", "-b", "0.0.0.0:5081", "main:internal_apis"] \ No newline at end of file diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..0a68785 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. +package = [] + +[metadata] +lock-version = "2.1" +python-versions = ">=3.13" +content-hash = "43c15d4b40e26b9dc4090308565270876da3b72ef2b9fa0bddbe4b344cfe177c" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..115d206 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[project] +name = "shared-resources" +version = "0.1.0" +description = "" +authors = [ + {name = "Bappoz",email = "landradezanetti@gmail.com"} +] +readme = "README.md" +requires-python = ">=3.13" +dependencies = [ +] + + +[build-system] +requires = ["poetry-core>=2.0.0,<3.0.0"] +build-backend = "poetry.core.masonry.api" From f19ce395ebd58133e53a9be66cf554f71fcf9364 Mon Sep 17 00:00:00 2001 From: LUCAS ANDRADE ZANETTI Date: Tue, 3 Jun 2025 13:49:09 -0300 Subject: [PATCH 2/2] Shared-Resource funcionando com sucesso --- docker-compose.yml | 19 +++++++++---------- internal_apis/Dockerfile | 3 ++- internal_apis/main.py | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d5516e8..3fbb790 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,15 @@ services: - REDIS_PORT=6379 - REDIS_URL=redis://redis-local:6379/0 + mongo: + image: mongo:6.0 + container_name: mongo + restart: unless-stopped + ports: + - "27017:27017" + volumes: + - mongo-data:/data/db + internal_apis: build: context: ./internal_apis @@ -58,16 +67,6 @@ services: - MONGO_DATABASE=shared-resources - - mongo: - image: mongo:6.0 - container_name: mongo - restart: unless-stopped - ports: - - "27017:27017" - volumes: - - mongo-data:/data/db - volumes: redis-data: driver: local diff --git a/internal_apis/Dockerfile b/internal_apis/Dockerfile index f918005..9f5348a 100644 --- a/internal_apis/Dockerfile +++ b/internal_apis/Dockerfile @@ -14,4 +14,5 @@ RUN poetry install --no-root EXPOSE 5081 -CMD ["poetry", "run", "gunicorn", "-w", "2", "-b", "0.0.0.0:5081", "main:internal_apis"] \ No newline at end of file + +CMD ["sh", "-c", "PYTHONPATH=src poetry run gunicorn -w 2 -b 0.0.0.0:5081 main:internal_api"] diff --git a/internal_apis/main.py b/internal_apis/main.py index 89c8888..d3eb43a 100644 --- a/internal_apis/main.py +++ b/internal_apis/main.py @@ -2,8 +2,8 @@ from config_module import get_config # Create the app at module level so Gunicorn can import it. -internal_apis = create_app(get_config()) +internal_api = create_app(get_config()) if __name__ == "__main__": - internal_apis.run(host="0.0.0.0", port=5081, debug=True) + internal_api.run(host="0.0.0.0", port=5081, debug=True)