Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ jobs:
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/hub-converter:${{ steps.extract_info.outputs.version }}
context: ./converter
build-args: CONVERTER_VERSION=${{ steps.extract_info.outputs.version }}
4 changes: 4 additions & 0 deletions converter/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Use Python 3.11 slim as base image
FROM python:3.11-slim

ARG CONVERTER_VERSION

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
Expand Down Expand Up @@ -47,5 +49,7 @@ EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1

ENV CONVERTER_VERSION=${CONVERTER_VERSION}

# Use Gunicorn for production deployment
CMD ["uv", "run", "--no-dev", "gunicorn", "-w", "4", "-b", "0.0.0.0:8080", "converter.converter:app"]
12 changes: 11 additions & 1 deletion converter/converter/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from flask import has_request_context, g
from enum import Enum

CONVERTER_VERSION = os.getenv("CONVERTER_VERSION")


class LoggingKeys(Enum):
DISTRIBUTION_ID = "distributionId"
Expand All @@ -14,13 +16,20 @@ class LoggingKeys(Enum):

# Using filter to add context variable: https://docs.python.org/3/howto/logging-cookbook.html#using-filters-to-impart-contextual-information
class DistributionContextFilter(logging.Filter):
def filter(self, record):
def filter(self, record: logging.LogRecord) -> bool:
if has_request_context():
for key in LoggingKeys:
setattr(record, key.value, getattr(g, key.value, None))
return True


class VersionFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
if CONVERTER_VERSION:
record.version = CONVERTER_VERSION
return True


def configure_logging():
root = logging.getLogger()
for h in root.handlers[:]:
Expand All @@ -37,6 +46,7 @@ def configure_logging():
)
handler.setFormatter(formatter)
handler.addFilter(DistributionContextFilter())
handler.addFilter(VersionFilter())

root.addHandler(handler)

Expand Down
Loading