diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 97bc195..738ac1f 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -60,6 +60,10 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Set build timestamp + id: build_time + run: echo "value=$(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_OUTPUT + # Build and push main application image - name: Build and push Docker image uses: docker/build-push-action@v6 @@ -72,6 +76,9 @@ jobs: ghcr.io/wahyd4/links:1.0.${{ github.run_number }} labels: |- ${{ steps.meta.outputs.labels }} + build-args: |- + BUILD_TIME=${{ steps.build_time.outputs.value }} + BUILD_VERSION=1.0.${{ github.run_number }} - name: Deploy to Kubernetes uses: wahyd4/kubectl-helm-action@master diff --git a/Dockerfile b/Dockerfile index 9ffbc46..d156831 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,6 +73,10 @@ RUN rm -rf /tmp/.cache/uv ~/.npm ~/.cache \ # Production stage - use Python 3.12 slim FROM python:3.12-slim AS production +# Build-time metadata +ARG BUILD_TIME="" +ARG BUILD_VERSION="" + # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 @@ -81,6 +85,8 @@ ENV VIRTUAL_ENV=/app/.venv ENV PATH="/app/.venv/bin:$PATH" ENV DEBIAN_FRONTEND=noninteractive ENV PLAYWRIGHT_BROWSERS_PATH=/app/.playwright +ENV BUILD_TIME=${BUILD_TIME} +ENV BUILD_VERSION=${BUILD_VERSION} # Set work directory WORKDIR /app diff --git a/core/context_processors.py b/core/context_processors.py new file mode 100644 index 0000000..d9287ef --- /dev/null +++ b/core/context_processors.py @@ -0,0 +1,8 @@ +from django.conf import settings + + +def build_info(request): + return { + 'BUILD_TIME': getattr(settings, 'BUILD_TIME', ''), + 'BUILD_VERSION': getattr(settings, 'BUILD_VERSION', ''), + } diff --git a/core/settings.py b/core/settings.py index 8a7dc44..54281b7 100644 --- a/core/settings.py +++ b/core/settings.py @@ -36,6 +36,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'core.context_processors.build_info', ], }, }, @@ -207,6 +208,10 @@ R2_CUSTOM_DOMAIN = os.environ.get('R2_CUSTOM_DOMAIN') CRAWL4AI_API_URL = os.environ.get('CRAWL4AI_API_URL', 'https://crawl-api.junv.cc') CRAWL4AI_ENABLED = os.environ.get('CRAWL4AI_ENABLED', 'True').lower() in ('true', '1', 'yes') +# Build metadata (injected at Docker image build time) +BUILD_TIME = os.environ.get('BUILD_TIME', '') +BUILD_VERSION = os.environ.get('BUILD_VERSION', '') + # For debugging LOGGING = { 'version': 1, diff --git a/templates/base.html b/templates/base.html index 3b6fc21..f42ad21 100644 --- a/templates/base.html +++ b/templates/base.html @@ -252,5 +252,10 @@ }); {% block extra_js %}{% endblock %} + {% if BUILD_TIME %} + + {% endif %}