Self hosted FLOSS fitness/workout, nutrition and weight tracker
Save the git commit and build date of the docker images
Roland Geiderf6cccd339adf
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.ymlindex 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 digestid: builduses: 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-tonametypetypekeyvaluediff --git a/extras/docker/production/Dockerfile b/extras/docker/production/Dockerfileindex 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 finalLABEL org.opencontainers.image.authors="wger team <[email protected]>"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/srcEXPOSE 8000diff --git a/wger/software/templates/about_us.html b/wger/software/templates/about_us.htmlindex bd59b2589..be20381df 100644--- a/wger/software/templates/about_us.html+++ b/wger/software/templates/about_us.html@@ -164,7 +164,11 @@</div><div class="alert alert-dark mt-5" role="alert">- {% translate "Current version" %} {{ version }}+ {% translate "Current version" %} <strong>{{ version }}</strong>+ {% if date %}+ <br>+ {% translate 'Date' %} <strong>{{ date }}</strong>+ {% endif %}</div>{% endblock %}diff --git a/wger/software/urls.py b/wger/software/urls.pyindex 303f841c4..77d5d2028 100644--- a/wger/software/urls.py+++ b/wger/software/urls.py@@ -23,7 +23,10 @@ from django.views.generic import (# wgerfrom 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.pyindex 0a291093b..b3079b8c1 100644--- a/wger/version.py+++ b/wger/version.py@@ -14,6 +14,7 @@# Standard Libraryimport logging+import os# Third Partyfrom packaging.version import Version@@ -43,3 +44,16 @@ def get_version(version: Version = None) -> str:version = VERSIONreturn 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')