From f6cccd339adf2bac965827bab26c8cda1d90b4f0 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 11 Oct 2025 16:28:18 +0200 Subject: [PATCH] Save the git commit and build date of the docker images --- .github/workflows/docker.yml | 6 ++++++ extras/docker/production/Dockerfile | 6 ++++++ wger/software/templates/about_us.html | 6 +++++- wger/software/urls.py | 8 ++++++-- wger/version.py | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0cc955f5e..f83089da6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -71,6 +71,9 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set build date + run: echo "BUILD_DATE=$(date -u +'%Y-%m-%d')" >> $GITHUB_ENV + - name: Build and push by digest id: build uses: docker/build-push-action@v6 @@ -81,6 +84,9 @@ jobs: platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + build-args: | + BUILD_DATE=${{ env.BUILD_DATE }} + BUILD_COMMIT=${{ github.sha }} # https://github.com/moby/buildkit#--export-cache-options # https://github.com/docker/buildx#--cache-tonametypetypekeyvalue diff --git a/extras/docker/production/Dockerfile b/extras/docker/production/Dockerfile index af228ae78..4b0d0b5bb 100644 --- a/extras/docker/production/Dockerfile +++ b/extras/docker/production/Dockerfile @@ -76,7 +76,13 @@ RUN yarn install \ FROM wger/base:latest AS final LABEL org.opencontainers.image.authors="wger team " ARG DOCKER_DIR=./extras/docker/production +ARG BUILD_COMMIT +ARG BUILD_DATE + ENV PATH="/home/wger/.local/bin:$PATH" +ENV APP_BUILD_COMMIT=$BUILD_COMMIT +ENV APP_BUILD_DATE=$BUILD_DATE + WORKDIR /home/wger/src EXPOSE 8000 diff --git a/wger/software/templates/about_us.html b/wger/software/templates/about_us.html index bd59b2589..be20381df 100644 --- a/wger/software/templates/about_us.html +++ b/wger/software/templates/about_us.html @@ -164,7 +164,11 @@ {% endblock %} diff --git a/wger/software/urls.py b/wger/software/urls.py index 303f841c4..77d5d2028 100644 --- a/wger/software/urls.py +++ b/wger/software/urls.py @@ -23,7 +23,10 @@ from django.views.generic import ( # wger from wger.software import views -from wger.version import get_version +from wger.version import ( + get_version_date, + get_version_with_git, +) urlpatterns = [ @@ -45,7 +48,8 @@ urlpatterns = [ path( 'about-us', TemplateView.as_view( - template_name='about_us.html', extra_context={'version': get_version()} + template_name='about_us.html', + extra_context={'version': get_version_with_git(), 'date': get_version_date()}, ), name='about-us', ), diff --git a/wger/version.py b/wger/version.py index 0a291093b..b3079b8c1 100644 --- a/wger/version.py +++ b/wger/version.py @@ -14,6 +14,7 @@ # Standard Library import logging +import os # Third Party from packaging.version import Version @@ -43,3 +44,16 @@ def get_version(version: Version = None) -> str: version = VERSION return str(version) + + +def get_version_with_git(version: Version = None) -> str: + version = get_version(version) + git_sha1 = os.environ.get('APP_BUILD_COMMIT', '')[:7] + if git_sha1: + version += f'+git{git_sha1}' + + return version + + +def get_version_date() -> str | None: + return os.environ.get('APP_BUILD_DATE')