Display git commit sha in footer

This commit is contained in:
Gabriel Augendre 2020-09-09 18:32:46 +02:00
parent 88f3c455ff
commit 11ceec343d
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
4 changed files with 24 additions and 1 deletions

View file

@ -1,3 +1,12 @@
FROM ubuntu:latest as git
RUN apt-get update \
&& apt-get install -y git \
&& mkdir /app
ADD . /app
WORKDIR /app
RUN git rev-parse HEAD | tee /version
FROM python:3.8.5-slim
RUN apt-get update \
@ -13,6 +22,7 @@ COPY docker ./docker/
COPY blog ./blog/
COPY attachments ./attachments/
COPY articles ./articles/
COPY --from=git /version /app/.version
ENV SECRET_KEY "changeme"
ENV DEBUG "false"

View file

@ -21,3 +21,14 @@ def date_format(request):
if request.path in IGNORED_PATHS:
return {}
return {"CUSTOM_ISO": r"Y-m-d\TH:i:sO"}
def git_version(request):
if request.path in IGNORED_PATHS:
return {}
try:
with open("/app/.version") as f:
version = f.read().strip()[:8]
except FileNotFoundError:
version = "latest"
return {"git_version": version}

View file

@ -49,7 +49,8 @@
This blog and all articles by Gabriel Augendre are licensed under the
<a href="http://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0 International License</a>.
Code blocks by Gabriel Augendre are licensed under the
<a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GENERAL PUBLIC LICENSE version 3</a>.
<a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GENERAL PUBLIC LICENSE version 3</a>.<br>
Currently deployed version: {{ git_version }}
</p>
</footer>
</body>

View file

@ -99,6 +99,7 @@ TEMPLATES = [
"articles.context_processors.pages",
"articles.context_processors.drafts_count",
"articles.context_processors.date_format",
"articles.context_processors.git_version",
],
},
},