From bf7fb27fdb223348a3b97b4d17a440048ae60d48 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Wed, 10 Sep 2025 08:54:47 -0400 Subject: [PATCH] Fix dev workflow hanging and implement runtime branch detection - Fix duplicate Dockerfile sections that were causing build hangs - Replace complex build args with simple runtime git branch detection - Revert CI workflows to working state (remove build args and debug code) - Add automatic version tagging: dev branch shows "0.2.15-dev" - Enhanced movie fallback logic for rename-first scenarios - Improved logging to trace movie date decision process --- .gitea/workflows/ci-dev.yml | 2 -- .gitea/workflows/ci.yml | 2 -- Dockerfile | 43 ++++++------------------------------- nfoguard.py | 22 +++++++++++++------ 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/.gitea/workflows/ci-dev.yml b/.gitea/workflows/ci-dev.yml index 08e8f9b..78ce218 100644 --- a/.gitea/workflows/ci-dev.yml +++ b/.gitea/workflows/ci-dev.yml @@ -93,8 +93,6 @@ jobs: echo "Building DEV image with layer caching..." docker build \ $CACHE_ARGS \ - --build-arg BUILD_TYPE=dev \ - --build-arg IMAGE_TAG=dev \ --tag nfoguard:dev \ --tag nfoguard:dev-${{ github.sha }} \ --tag "$CACHE_IMAGE" \ diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index d268e89..8a08aee 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -94,8 +94,6 @@ jobs: echo "Building with layer caching..." docker build \ $CACHE_ARGS \ - --build-arg BUILD_TYPE=production \ - --build-arg IMAGE_TAG=latest \ --tag nfoguard:latest \ --tag nfoguard:${{ github.sha }} \ --tag "$CACHE_IMAGE" \ diff --git a/Dockerfile b/Dockerfile index 41176ff..fd50ece 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,11 @@ FROM python:3.11-slim -# Build arguments for version tagging -ARG BUILD_TYPE=production -ARG IMAGE_TAG=latest - # Set working directory WORKDIR /app -# Set environment variables for version detection -ENV BUILD_TYPE=${BUILD_TYPE} -ENV IMAGE_TAG=${IMAGE_TAG} - # Single layer for all system setup to minimize image size RUN apt-get update && apt-get install -y --no-install-recommends \ - sqlite3 curl gosu \ + sqlite3 curl gosu git \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean \ && groupadd -g 1000 appuser \ @@ -31,6 +23,10 @@ COPY core/ ./core/ COPY clients/ ./clients/ COPY nfoguard.py . +# Copy git info to detect branch at runtime +COPY .git/HEAD .git/ +COPY .git/refs/ .git/refs/ + # Final setup in single layer RUN mkdir -p /app/data \ && chown -R appuser:appuser /app \ @@ -43,31 +39,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ EXPOSE 8080 ENTRYPOINT ["/entrypoint.sh"] -CMD ["python", "nfoguard.py"] - -# Root-aware entrypoint -RUN echo '#!/bin/bash' > /entrypoint.sh && \ - echo 'set -euo pipefail' >> /entrypoint.sh && \ - echo '' >> /entrypoint.sh && \ - echo 'PUID=${PUID:-1000}' >> /entrypoint.sh && \ - echo 'PGID=${PGID:-1000}' >> /entrypoint.sh && \ - echo '' >> /entrypoint.sh && \ - echo 'if [ "$(id -u)" -eq 0 ]; then' >> /entrypoint.sh && \ - echo ' # running as root: we can adjust IDs and drop privileges' >> /entrypoint.sh && \ - echo ' groupmod -o -g "$PGID" appuser 2>/dev/null || groupadd -o -g "$PGID" appuser' >> /entrypoint.sh && \ - echo ' id appuser &>/dev/null || useradd -o -u "$PUID" -g "$PGID" -m appuser' >> /entrypoint.sh && \ - echo ' usermod -o -u "$PUID" -g "$PGID" appuser 2>/dev/null || true' >> /entrypoint.sh && \ - echo ' chown -R "$PUID:$PGID" /app || true' >> /entrypoint.sh && \ - echo ' exec gosu appuser "$@"' >> /entrypoint.sh && \ - echo 'else' >> /entrypoint.sh && \ - echo ' # not root (e.g., compose set user: 1000:1000) — just run' >> /entrypoint.sh && \ - echo ' exec "$@"' >> /entrypoint.sh && \ - echo 'fi' >> /entrypoint.sh -RUN chmod +x /entrypoint.sh - -HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD curl -f http://localhost:8080/health || exit 1 - -EXPOSE 8080 -ENTRYPOINT ["/entrypoint.sh"] -CMD ["python", "nfoguard.py"] +CMD ["python", "nfoguard.py"] \ No newline at end of file diff --git a/nfoguard.py b/nfoguard.py index 75bd874..a21798f 100644 --- a/nfoguard.py +++ b/nfoguard.py @@ -781,12 +781,22 @@ try: except: version = "0.1.0" -# Check if running in dev environment (set during Docker build) -build_type = os.environ.get('BUILD_TYPE', 'production') -image_tag = os.environ.get('IMAGE_TAG', 'latest') - -if (build_type == 'dev' or 'dev' in image_tag.lower()): - version = f"{version}-dev" +# Check if running from dev branch (detect at runtime) +try: + # Try to read git branch from .git/HEAD + git_head_path = Path(__file__).parent / ".git" / "HEAD" + if git_head_path.exists(): + head_content = git_head_path.read_text().strip() + if "ref: refs/heads/dev" in head_content: + version = f"{version}-dev" + elif head_content.startswith("ref: refs/heads/"): + # Extract branch name for other branches + branch = head_content.split("refs/heads/")[-1] + if branch != "main": + version = f"{version}-{branch}" +except Exception: + # If git detection fails, that's fine - use base version + pass app = FastAPI( title="NFOGuard",