From a697b3a6f15148a01fdcc1c6d6e87ed4d7939f81 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 25 Mar 2023 21:06:04 +0100 Subject: [PATCH] Add a ping page with the commit sha --- .github/workflows/publish.yaml | 2 +- src/checkout/settings.py | 24 ++++++++++++++++++++++++ src/common/context_processors.py | 5 +++++ src/common/templates/common/ping.html | 10 ++++++++++ src/common/urls.py | 3 ++- src/common/views.py | 6 +++++- 6 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/common/context_processors.py create mode 100644 src/common/templates/common/ping.html diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 5a9d65d..621cfe8 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -50,4 +50,4 @@ jobs: max_attempts: 5 retry_wait_seconds: 2 warning_on_retry: false - command: curl -sSL --fail -m 10 https://checkout.augendre.info | grep ${GITHUB_SHA::7} > /dev/null + command: curl -sSL --fail -m 10 https://checkout.augendre.info/ping/ | grep ${GITHUB_SHA::7} > /dev/null diff --git a/src/checkout/settings.py b/src/checkout/settings.py index 1566242..e344397 100644 --- a/src/checkout/settings.py +++ b/src/checkout/settings.py @@ -129,6 +129,7 @@ TEMPLATES = [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "common.context_processors.app", ], }, }, @@ -228,3 +229,26 @@ CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" CRISPY_TEMPLATE_PACK = "bootstrap5" MESSAGE_TAGS = {messages.ERROR: "danger"} + +APP = { + "build": { + "date": "latest-date", + "commit": "latest-commit", + "describe": "latest-describe", + }, +} +try: + with Path("/app/git/build-date").open() as f: + APP["build"]["date"] = f.read().strip() +except Exception: # noqa: S110 + pass +try: + with Path("/app/git/git-commit").open() as f: + APP["build"]["commit"] = f.read().strip() +except Exception: # noqa: S110 + pass +try: + with Path("/app/git/git-describe").open() as f: + APP["build"]["describe"] = f.read().strip() +except Exception: # noqa: S110 + pass diff --git a/src/common/context_processors.py b/src/common/context_processors.py new file mode 100644 index 0000000..956ba17 --- /dev/null +++ b/src/common/context_processors.py @@ -0,0 +1,5 @@ +from django.conf import settings + + +def app(_): + return settings.APP diff --git a/src/common/templates/common/ping.html b/src/common/templates/common/ping.html new file mode 100644 index 0000000..1288535 --- /dev/null +++ b/src/common/templates/common/ping.html @@ -0,0 +1,10 @@ +{% extends "common/base.html" %} +{% block content %} +

Ping

+

Versions

+ +{% endblock %} diff --git a/src/common/urls.py b/src/common/urls.py index d33a0c7..da64f49 100644 --- a/src/common/urls.py +++ b/src/common/urls.py @@ -1,8 +1,9 @@ from django.urls import path -from common.views import home +from common.views import home, ping app_name = "common" urlpatterns = [ + path("ping/", ping, name="ping"), path("", home, name="home"), ] diff --git a/src/common/views.py b/src/common/views.py index 5174e1c..6343d26 100644 --- a/src/common/views.py +++ b/src/common/views.py @@ -1,5 +1,9 @@ -from django.shortcuts import redirect +from django.shortcuts import redirect, render def home(_request): return redirect("purchase:new") + + +def ping(request): + return render(request, "common/ping.html", {})