diff --git a/Dockerfile b/Dockerfile index cd88cc9..4930b33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" diff --git a/articles/context_processors.py b/articles/context_processors.py index 7d0ff3d..343d245 100644 --- a/articles/context_processors.py +++ b/articles/context_processors.py @@ -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} diff --git a/articles/templates/articles/base.html b/articles/templates/articles/base.html index 72ec1c1..66339a5 100644 --- a/articles/templates/articles/base.html +++ b/articles/templates/articles/base.html @@ -49,7 +49,8 @@ This blog and all articles by Gabriel Augendre are licensed under the CC BY-SA 4.0 International License. Code blocks by Gabriel Augendre are licensed under the - GNU GENERAL PUBLIC LICENSE version 3. + GNU GENERAL PUBLIC LICENSE version 3.
+ Currently deployed version: {{ git_version }}

diff --git a/blog/settings.py b/blog/settings.py index 3bf4d19..efbdfde 100644 --- a/blog/settings.py +++ b/blog/settings.py @@ -99,6 +99,7 @@ TEMPLATES = [ "articles.context_processors.pages", "articles.context_processors.drafts_count", "articles.context_processors.date_format", + "articles.context_processors.git_version", ], }, },