diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml deleted file mode 100644 index ea7d35af..00000000 --- a/.github/workflows/review.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Build & Review -on: [pull_request] - -env: - CONTAINER_REGISTRY: ghcr.io - CONTAINER_REGISTRY_USER: ${{ secrets.GHCR_CONTAINER_REGISTRY_USER }} - CONTAINER_REGISTRY_PASSWORD: ${{ secrets.GHCR_TOKEN }} - CONTAINER_REGISTRY_REPO: ghcr.io/city-of-helsinki/${{ github.event.repository.name }} - REPO_NAME: ${{ github.event.repository.name }} - KUBECONFIG_RAW: ${{ secrets.KUBECONFIG_RAW }} - BUILD_ARTIFACT_FOLDER: 'build_artifacts' - SERVICE_ARTIFACT_FOLDER: 'service_artifacts' - BASE_DOMAIN: ${{ secrets.BASE_DOMAIN_STAGING }} - DATABASE_USER: user - DATABASE_PASSWORD: testing-password - APP_MIGRATE_COMMAND: /app/.prod/on_deploy.sh - SERVICE_PORT: "8080" - K8S_REQUEST_CPU: 50m - K8S_REQUEST_RAM: 300Mi - K8S_LIMIT_CPU: 500m - K8S_LIMIT_RAM: 400Mi - -jobs: - build: - runs-on: ubuntu-latest - name: Build - steps: - - uses: actions/checkout@v4 - - name: Build - uses: andersinno/kolga-build-action@v2 - - review: - if: false - runs-on: ubuntu-latest - needs: build - name: Review - steps: - - uses: actions/checkout@v4 - - uses: andersinno/kolga-setup-action@v2 - - - name: Review-Services - uses: andersinno/kolga-deploy-service-action@v2 - with: - projects: OPEN_CITY_PROFILE - env: - POSTGRES_IMAGE: "docker.io/andersinnovations/postgis:11-bitnami" - - - name: Deploy - uses: andersinno/kolga-deploy-action@v2 - env: - ENVIRONMENT_URL: https://${{ env.K8S_NAMESPACE }}.${{ env.BASE_DOMAIN }} - K8S_SECRET_ALLOWED_HOSTS: "*" - K8S_SECRET_DEBUG: 1 - K8S_SECRET_SENTRY_DSN: ${{ secrets.GH_SENTRY_DSN }} - K8S_SECRET_SENTRY_ENVIRONMENT: "test" - K8S_SECRET_TOKEN_AUTH_ACCEPTED_AUDIENCE: "https://api.hel.fi/auth/helsinkiprofile" - K8S_SECRET_TOKEN_AUTH_ACCEPTED_SCOPE_PREFIX: "helsinkiprofile" - K8S_SECRET_TOKEN_AUTH_AUTHSERVER_URL: "https://tunnistamo.${{ env.BASE_DOMAIN }}/openid" - K8S_SECRET_TOKEN_AUTH_REQUIRE_SCOPE: 1 - K8S_SECRET_OIDC_CLIENT_ID: ${{ secrets.GH_QA_OIDC_CLIENT_ID }} - K8S_SECRET_OIDC_CLIENT_SECRET: ${{ secrets.GH_QA_OIDC_CLIENT_SECRET }} - K8S_SECRET_TUNNISTAMO_API_TOKENS_URL: "https://tunnistamo.${{ env.BASE_DOMAIN }}/api-tokens" - K8S_SECRET_GDPR_AUTH_CALLBACK_URL: "https://profiili.${{ env.BASE_DOMAIN }}/gdpr-callback" - K8S_SECRET_VERSION: ${{ github.sha }} - K8S_SECRET_MAIL_MAILGUN_KEY: ${{ secrets.GH_MAILGUN_API_KEY }} - K8S_SECRET_MAIL_MAILGUN_DOMAIN: "mail.hel.ninja" - K8S_SECRET_MAIL_MAILGUN_API: "https://api.eu.mailgun.net/v3" - K8S_SECRET_MAILER_EMAIL_BACKEND: "anymail.backends.mailgun.EmailBackend" - K8S_SECRET_DEFAULT_FROM_EMAIL: "no-reply@hel.ninja" - K8S_SECRET_FIELD_ENCRYPTION_KEYS: ${{ secrets.GH_REVIEW_FIELD_ENCRYPTION_KEYS }} - K8S_SECRET_SALT_NATIONAL_IDENTIFICATION_NUMBER: ${{ secrets.GH_REVIEW_SALT_NATIONAL_IDENTIFICATION_NUMBER }} - K8S_SECRET_ENABLE_GRAPHIQL: 1 - K8S_SECRET_SEED_DEVELOPMENT_DATA: 1 - K8S_SECRET_AUDIT_LOG_TO_LOGGER_ENABLED: 1 diff --git a/.github/workflows/stop_review.yml b/.github/workflows/stop_review.yml deleted file mode 100644 index bf26dc48..00000000 --- a/.github/workflows/stop_review.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Stop Review -on: - pull_request: - types: [closed] - -env: - KUBECONFIG_RAW: ${{ secrets.KUBECONFIG_RAW }} - -jobs: - stop_review: - runs-on: ubuntu-latest - name: Stop Review - steps: - - uses: andersinno/kolga-setup-action@v2 - - - name: Stop Review - uses: andersinno/kolga-review-cleanup-action@v2 - with: - namespace: ${{ env.K8S_NAMESPACE }} diff --git a/docs/config.adoc b/docs/config.adoc index 8a1545cc..9b8aedef 100644 --- a/docs/config.adoc +++ b/docs/config.adoc @@ -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 <>. +- `COMMIT_HASH`: Sets the https://docs.sentry.io/platforms/python/configuration/options/#release[Sentry release]. See `COMMIT_HASH` in <>. 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. diff --git a/open_city_profile/__init__.py b/open_city_profile/__init__.py index e69de29b..4b67c39d 100644 --- a/open_city_profile/__init__.py +++ b/open_city_profile/__init__.py @@ -0,0 +1 @@ +__version__ = "1.13.1" diff --git a/open_city_profile/settings.py b/open_city_profile/settings.py index 7d97e3f6..edac303f 100644 --- a/open_city_profile/settings.py +++ b/open_city_profile/settings.py @@ -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")) @@ -43,7 +45,7 @@ DEFAULT_FROM_EMAIL=(str, "no-reply@hel.fi"), 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), @@ -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()], ) @@ -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__)) diff --git a/open_city_profile/urls.py b/open_city_profile/urls.py index dbcd592c..0fa40a39 100644 --- a/open_city_profile/urls.py +++ b/open_city_profile/urls.py @@ -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 = [ @@ -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)]