From cc078f1c6c69f412d85dfda5960c306de0cc79ef Mon Sep 17 00:00:00 2001 From: "Akihiko (Aki) Kuroda" <16141898+akihikokuroda@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:09:15 -0400 Subject: [PATCH] add version api endpoint to gateway (#1279) * add version api endpoint to gateway Signed-off-by: Akihiko Kuroda --- .github/workflows/update-component-versions.yaml | 1 + .../charts/gateway/templates/deployment.yaml | 2 ++ charts/quantum-serverless/values.yaml | 6 ++++++ gateway/main/settings.py | 1 + gateway/main/urls.py | 2 ++ gateway/tests/version/test_version.py | 14 ++++++++++++++ gateway/version/views.py | 10 ++++++++++ 7 files changed, 36 insertions(+) create mode 100644 gateway/tests/version/test_version.py create mode 100644 gateway/version/views.py diff --git a/.github/workflows/update-component-versions.yaml b/.github/workflows/update-component-versions.yaml index 0f39b28e9..459a9ce6b 100644 --- a/.github/workflows/update-component-versions.yaml +++ b/.github/workflows/update-component-versions.yaml @@ -43,6 +43,7 @@ jobs: sed -i "s/tag: \"${OLDNUM}\"/tag: \"${NEWNUM}\"/" charts/quantum-serverless/values.yaml sed -i "s/tag: \"${OLDNUM}-py39\"/tag: \"${NEWNUM}-py39\"/" charts/quantum-serverless/values.yaml sed -i "s/ray-node:${OLDNUM}/ray-node:${NEWNUM}/" charts/quantum-serverless/values.yaml + sed -i "s/version: ${OLDNUM}/version: ${NEWNUM}/" charts/quantum-serverless/values.yaml cd charts/quantum-serverless helm dependency update cd - diff --git a/charts/quantum-serverless/charts/gateway/templates/deployment.yaml b/charts/quantum-serverless/charts/gateway/templates/deployment.yaml index 161db2cac..c3a34379a 100644 --- a/charts/quantum-serverless/charts/gateway/templates/deployment.yaml +++ b/charts/quantum-serverless/charts/gateway/templates/deployment.yaml @@ -84,6 +84,8 @@ spec: resources: {{- toYaml .Values.resources | nindent 12 }} env: + - name: VERSION + value: {{ .Values.global.version | quote }} - name: DEBUG value: {{ .Values.application.debug | quote }} - name: DJANGO_SECRET_KEY diff --git a/charts/quantum-serverless/values.yaml b/charts/quantum-serverless/values.yaml index 35d0aa915..fdf77885f 100644 --- a/charts/quantum-serverless/values.yaml +++ b/charts/quantum-serverless/values.yaml @@ -1,3 +1,9 @@ +# =================== +# Quantum Serverless Info +# =================== +global: + version: 0.9.0 + # =================== # Quantum Serverless configs # =================== diff --git a/gateway/main/settings.py b/gateway/main/settings.py index a8968345e..cf823a343 100644 --- a/gateway/main/settings.py +++ b/gateway/main/settings.py @@ -17,6 +17,7 @@ from pathlib import Path from utils import sanitize_file_path +RELEASE_VERSION = os.environ.get("VERSION", "UNKNOWN") # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent diff --git a/gateway/main/urls.py b/gateway/main/urls.py index 3180e81b4..1b9199c6f 100644 --- a/gateway/main/urls.py +++ b/gateway/main/urls.py @@ -22,6 +22,7 @@ from drf_yasg.views import get_schema_view from drf_yasg import openapi import probes.views +import version.views schema = get_schema_view( # pylint: disable=invalid-name openapi.Info( @@ -45,6 +46,7 @@ path("accounts/", include("allauth.urls")), path("readiness/", probes.views.readiness, name="readiness"), path("liveness/", probes.views.liveness, name="liveness"), + path("version/", version.views.version, name="version"), path("", include("django_prometheus.urls")), re_path(r"^api/v1/", include(("api.v1.urls", "api"), namespace="v1")), # docs diff --git a/gateway/tests/version/test_version.py b/gateway/tests/version/test_version.py new file mode 100644 index 000000000..25e791d42 --- /dev/null +++ b/gateway/tests/version/test_version.py @@ -0,0 +1,14 @@ +"""Test version.""" + +from django.urls import reverse +from rest_framework import status +from rest_framework.test import APITestCase + + +class TestProbes(APITestCase): + """TestVersion.""" + + def test_version(self): + """Tests version.""" + jobs_response = self.client.get(reverse("version")) + self.assertEqual(jobs_response.status_code, status.HTTP_200_OK) diff --git a/gateway/version/views.py b/gateway/version/views.py new file mode 100644 index 000000000..219ed1fa5 --- /dev/null +++ b/gateway/version/views.py @@ -0,0 +1,10 @@ +from django.http import HttpResponse +import json +import os +import requests +import main.settings + + +def version(request): + info = {"version": main.settings.RELEASE_VERSION} + return HttpResponse(json.dumps(info))