Skip to content

Commit f6cccd3

Browse files
committed
Save the git commit and build date of the docker images
1 parent 9140284 commit f6cccd3

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

.github/workflows/docker.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ jobs:
7171
username: ${{ secrets.DOCKERHUB_USERNAME }}
7272
password: ${{ secrets.DOCKERHUB_TOKEN }}
7373

74+
- name: Set build date
75+
run: echo "BUILD_DATE=$(date -u +'%Y-%m-%d')" >> $GITHUB_ENV
76+
7477
- name: Build and push by digest
7578
id: build
7679
uses: docker/build-push-action@v6
@@ -81,6 +84,9 @@ jobs:
8184
platforms: ${{ matrix.platform }}
8285
labels: ${{ steps.meta.outputs.labels }}
8386
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
87+
build-args: |
88+
BUILD_DATE=${{ env.BUILD_DATE }}
89+
BUILD_COMMIT=${{ github.sha }}
8490
8591
# https://github.com/moby/buildkit#--export-cache-options
8692
# https://github.com/docker/buildx#--cache-tonametypetypekeyvalue

extras/docker/production/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ RUN yarn install \
7676
FROM wger/base:latest AS final
7777
LABEL org.opencontainers.image.authors="wger team <[email protected]>"
7878
ARG DOCKER_DIR=./extras/docker/production
79+
ARG BUILD_COMMIT
80+
ARG BUILD_DATE
81+
7982
ENV PATH="/home/wger/.local/bin:$PATH"
83+
ENV APP_BUILD_COMMIT=$BUILD_COMMIT
84+
ENV APP_BUILD_DATE=$BUILD_DATE
85+
8086
WORKDIR /home/wger/src
8187
EXPOSE 8000
8288

wger/software/templates/about_us.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ <h4 class="mt-4">{% translate "Thank You!" %}</h4>
164164
</div>
165165

166166
<div class="alert alert-dark mt-5" role="alert">
167-
{% translate "Current version" %} {{ version }}
167+
{% translate "Current version" %} <strong>{{ version }}</strong>
168+
{% if date %}
169+
<br>
170+
{% translate 'Date' %} <strong>{{ date }}</strong>
171+
{% endif %}
168172
</div>
169173
{% endblock %}
170174

wger/software/urls.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
# wger
2525
from wger.software import views
26-
from wger.version import get_version
26+
from wger.version import (
27+
get_version_date,
28+
get_version_with_git,
29+
)
2730

2831

2932
urlpatterns = [
@@ -45,7 +48,8 @@
4548
path(
4649
'about-us',
4750
TemplateView.as_view(
48-
template_name='about_us.html', extra_context={'version': get_version()}
51+
template_name='about_us.html',
52+
extra_context={'version': get_version_with_git(), 'date': get_version_date()},
4953
),
5054
name='about-us',
5155
),

wger/version.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
# Standard Library
1616
import logging
17+
import os
1718

1819
# Third Party
1920
from packaging.version import Version
@@ -43,3 +44,16 @@ def get_version(version: Version = None) -> str:
4344
version = VERSION
4445

4546
return str(version)
47+
48+
49+
def get_version_with_git(version: Version = None) -> str:
50+
version = get_version(version)
51+
git_sha1 = os.environ.get('APP_BUILD_COMMIT', '')[:7]
52+
if git_sha1:
53+
version += f'+git{git_sha1}'
54+
55+
return version
56+
57+
58+
def get_version_date() -> str | None:
59+
return os.environ.get('APP_BUILD_DATE')

0 commit comments

Comments
 (0)