Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: readiness return version info, sentry get git commit hash #479

Merged
merged 10 commits into from
Mar 28, 2024
74 changes: 0 additions & 74 deletions .github/workflows/review.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/stop_review.yml

This file was deleted.

4 changes: 2 additions & 2 deletions docs/config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ It's possible to report errors to Sentry.

- `SENTRY_DSN`: Sets the https://docs.sentry.io/platforms/python/configuration/options/#dsn[Sentry DSN]. If this is not set, nothing is sent to Sentry.
- `SENTRY_ENVIRONMENT`: Sets the https://docs.sentry.io/platforms/python/configuration/options/#environment[Sentry environment]. Default is "development".
- `VERSION`: Sets the https://docs.sentry.io/platforms/python/configuration/options/#release[Sentry release]. See `VERSION` in <<Miscellaneous>>.
- `COMMIT_HASH`: Sets the https://docs.sentry.io/platforms/python/configuration/options/#release[Sentry release]. See `COMMIT_HASH` in <<Miscellaneous>>. If `COMMIT_HASH` is not set, set module version instead.

== Miscellaneous

- `VERSION`: Sets a version for the installation. Default is the output of `git describe --always` command, if it succeeds, otherwise `None`.
- `COMMIT_HASH`: Sets a commit hash of the installation. Default is empty string.
- `TEMPORARY_PROFILE_READ_ACCESS_TOKEN_VALIDITY_MINUTES`: For how long a temporary profile read access token is valid after creation. Value is in minutes. Default is 48 hours.
1 change: 1 addition & 0 deletions open_city_profile/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.13.1"
terovirtanen marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 10 additions & 12 deletions open_city_profile/settings.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import subprocess
from datetime import datetime
from sys import stdout

import environ
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

from open_city_profile import __version__

checkout_dir = environ.Path(__file__) - 2
assert os.path.exists(checkout_dir("manage.py"))

Expand Down Expand Up @@ -43,7 +45,7 @@
DEFAULT_FROM_EMAIL=(str, "[email protected]"),
FIELD_ENCRYPTION_KEYS=(list, []),
SALT_NATIONAL_IDENTIFICATION_NUMBER=(str, None),
VERSION=(str, None),
OPENSHIFT_BUILD_COMMIT=(str, ""),
AUDIT_LOG_TO_LOGGER_ENABLED=(bool, False),
AUDIT_LOG_LOGGER_FILENAME=(str, ""),
AUDIT_LOG_TO_DB_ENABLED=(bool, False),
Expand Down Expand Up @@ -72,18 +74,11 @@
if os.path.exists(env_file):
env.read_env(env_file)

VERSION = env.str("VERSION")
if VERSION is None:
try:
VERSION = subprocess.check_output(
["git", "describe", "--always"], text=True
).strip()
except (FileNotFoundError, subprocess.CalledProcessError):
VERSION = None

COMMIT_HASH = env.str("OPENSHIFT_BUILD_COMMIT", "")
VERSION = __version__
sentry_sdk.init(
dsn=env.str("SENTRY_DSN", ""),
release=VERSION,
release=env.str("OPENSHIFT_BUILD_COMMIT", VERSION),
environment=env.str("SENTRY_ENVIRONMENT", "development"),
integrations=[DjangoIntegration()],
)
Expand Down Expand Up @@ -390,3 +385,6 @@
KEYCLOAK_CLIENT_SECRET = env("KEYCLOAK_CLIENT_SECRET")
KEYCLOAK_GDPR_CLIENT_ID = env("KEYCLOAK_GDPR_CLIENT_ID")
KEYCLOAK_GDPR_CLIENT_SECRET = env("KEYCLOAK_GDPR_CLIENT_SECRET")

# get build time from a file in docker image
APP_BUILD_TIME = datetime.fromtimestamp(os.path.getmtime(__file__))
11 changes: 9 additions & 2 deletions open_city_profile/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.urls import include, path
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView
from graphql_sync_dataloaders import DeferredExecutionContext

from open_city_profile import __version__
from open_city_profile.views import GraphQLView

urlpatterns = [
Expand Down Expand Up @@ -48,7 +49,13 @@ def healthz(*args, **kwargs):


def readiness(*args, **kwargs):
return HttpResponse(status=200)
response_json = {
"status": "ok",
"packageVersion": __version__,
"commitHash": settings.COMMIT_HASH,
"buildTime": settings.APP_BUILD_TIME.strftime("%Y-%m-%dT%H:%M:%S.000Z"),
}
return JsonResponse(response_json, status=200)


urlpatterns += [path("healthz", healthz), path("readiness", readiness)]