diff --git a/.gitea/workflows/build-local.yaml b/.gitea/workflows/build-local.yaml index b9f1ad8..8d23894 100644 --- a/.gitea/workflows/build-local.yaml +++ b/.gitea/workflows/build-local.yaml @@ -35,7 +35,9 @@ jobs: - name: Build and Push Docker Image run: | - docker build -t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} . + docker build \ + --build-arg COMMIT_ID=$(echo "${{ github.sha }}" | cut -c1-7) \ + -t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} . docker push ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} - name: Clone ops-deployment repo diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 03b085b..9e4485d 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -35,7 +35,9 @@ jobs: - name: Build and Push Docker Image run: | - docker build -t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} . + docker build \ + --build-arg COMMIT_ID=$(echo "${{ github.sha }}" | cut -c1-7) \ + -t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} . docker push ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} - name: Clone ops-deployment repo diff --git a/Dockerfile b/Dockerfile index 1f08d14..1394b96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,4 +11,8 @@ FROM nvcr.io/nvidia/distroless/python:3.12-v4.1.6 COPY --from=builder /install /usr/local COPY --from=builder /app /app WORKDIR /app + +ARG COMMIT_ID=unknown +ENV COMMIT_ID=$COMMIT_ID + ENTRYPOINT ["python", "main.py"] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 9f8f13d..3cb97ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ ignore = ["E501"] [tool.ruff.lint.isort] known-first-party = ["db_module", "metrics_server", "rabbitmq_handler", "secret_manager", - "simple_logger_handler", "uvicorn_logger_config", "validator"] + "simple_logger_handler", "send_notifications"] [tool.ruff.format] indent-style = "tab" diff --git a/src/main.py b/src/main.py index f8292ce..8c010ab 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ import asyncio +import os from contextlib import asynccontextmanager from datetime import UTC, datetime @@ -6,7 +7,6 @@ import uvicorn from fastapi import Depends, FastAPI, HTTPException, Request from pydantic import BaseModel, Field from seadex import EntryNotFoundError, SeaDexEntry -from send_notifications import NotificationClient from anilist_query import AniListError, AnimeNotFoundError, MissingAnimeName, get_anime_name from db_module import ( @@ -17,6 +17,7 @@ from db_module import ( ) from metrics_server import REQUEST_COUNTER, metrics_api from secret_manager import cleanup_secret_files +from send_notifications import NotificationClient from simple_logger_handler import LOG_LEVEL, setup_logger logger = setup_logger(__name__) @@ -163,7 +164,7 @@ def add_anime(anime: AnimeCreate, db=Depends(get_db)): ) if cursor.fetchone(): - logger.debug(f"[FastAPI] Found existing entry, updating name and setting to active") + logger.debug("[FastAPI] Found existing entry, updating name and setting to active") cursor.execute( "UPDATE seadex_state SET anime_name = %s, active = 1 " "WHERE anilist_id = %s", @@ -236,6 +237,7 @@ def remove_anime(anime: AnimeCreate, db=Depends(get_db)): async def start_servers(): logger.info("[Server] Starting main API (port 5000) and metrics server (port 9000)...") + logger.info(f"[Server] Build commit id={os.getenv("COMMIT_ID","unknown")}") config_main = uvicorn.Config(api, host="0.0.0.0", port=5000, log_level=LOG_LEVEL.lower(),log_config=None) config_metrics = uvicorn.Config(metrics_api, host="0.0.0.0", port=9000, log_level=LOG_LEVEL.lower(),log_config=None)