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
This commit is contained in:
2025-09-10 08:54:47 -04:00
parent 6f356b1942
commit bf7fb27fdb
4 changed files with 22 additions and 47 deletions
-2
View File
@@ -93,8 +93,6 @@ jobs:
echo "Building DEV image with layer caching..." echo "Building DEV image with layer caching..."
docker build \ docker build \
$CACHE_ARGS \ $CACHE_ARGS \
--build-arg BUILD_TYPE=dev \
--build-arg IMAGE_TAG=dev \
--tag nfoguard:dev \ --tag nfoguard:dev \
--tag nfoguard:dev-${{ github.sha }} \ --tag nfoguard:dev-${{ github.sha }} \
--tag "$CACHE_IMAGE" \ --tag "$CACHE_IMAGE" \
-2
View File
@@ -94,8 +94,6 @@ jobs:
echo "Building with layer caching..." echo "Building with layer caching..."
docker build \ docker build \
$CACHE_ARGS \ $CACHE_ARGS \
--build-arg BUILD_TYPE=production \
--build-arg IMAGE_TAG=latest \
--tag nfoguard:latest \ --tag nfoguard:latest \
--tag nfoguard:${{ github.sha }} \ --tag nfoguard:${{ github.sha }} \
--tag "$CACHE_IMAGE" \ --tag "$CACHE_IMAGE" \
+5 -36
View File
@@ -1,19 +1,11 @@
FROM python:3.11-slim FROM python:3.11-slim
# Build arguments for version tagging
ARG BUILD_TYPE=production
ARG IMAGE_TAG=latest
# Set working directory # Set working directory
WORKDIR /app 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 # Single layer for all system setup to minimize image size
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
sqlite3 curl gosu \ sqlite3 curl gosu git \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& apt-get clean \ && apt-get clean \
&& groupadd -g 1000 appuser \ && groupadd -g 1000 appuser \
@@ -31,6 +23,10 @@ COPY core/ ./core/
COPY clients/ ./clients/ COPY clients/ ./clients/
COPY nfoguard.py . 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 # Final setup in single layer
RUN mkdir -p /app/data \ RUN mkdir -p /app/data \
&& chown -R appuser:appuser /app \ && chown -R appuser:appuser /app \
@@ -44,30 +40,3 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["python", "nfoguard.py"] 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"]
+16 -6
View File
@@ -781,12 +781,22 @@ try:
except: except:
version = "0.1.0" version = "0.1.0"
# Check if running in dev environment (set during Docker build) # Check if running from dev branch (detect at runtime)
build_type = os.environ.get('BUILD_TYPE', 'production') try:
image_tag = os.environ.get('IMAGE_TAG', 'latest') # Try to read git branch from .git/HEAD
git_head_path = Path(__file__).parent / ".git" / "HEAD"
if (build_type == 'dev' or 'dev' in image_tag.lower()): if git_head_path.exists():
version = f"{version}-dev" 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( app = FastAPI(
title="NFOGuard", title="NFOGuard",