added version information to sentry and the about page

This commit is contained in:
Jenny Danzmayr 2023-12-11 18:31:11 +01:00
parent 97c9c7ecb7
commit 4fb1230163
7 changed files with 42 additions and 2 deletions

View file

@ -71,6 +71,7 @@ RUN --mount=type=cache,target=/pip-cache \
pip install --cache-dir /pip-cache uwsgi pip install --cache-dir /pip-cache uwsgi
FROM base as final FROM base as final
ARG COMMIT
RUN groupadd -r -g 500 c3nav && useradd -r -u 500 -g 500 -G www-data c3nav RUN groupadd -r -g 500 c3nav && useradd -r -u 500 -g 500 -G www-data c3nav
RUN mkdir /data /etc/c3nav && chown -R c3nav:c3nav /data /etc/c3nav RUN mkdir /data /etc/c3nav && chown -R c3nav:c3nav /data /etc/c3nav
VOLUME /data VOLUME /data
@ -83,6 +84,7 @@ ENV C3NAV_DEBUG="" \
C3NAV_LOGLEVEL="INFO" \ C3NAV_LOGLEVEL="INFO" \
C3NAV_DATA_DIR="/data" \ C3NAV_DATA_DIR="/data" \
C3NAV_AUTOMIGRATE="yes" \ C3NAV_AUTOMIGRATE="yes" \
C3NAV_VERSION="${COMMIT}" \
MPLBACKEND="agg" \ MPLBACKEND="agg" \
UWSGI_WORKERS="4" \ UWSGI_WORKERS="4" \
PATH="/app/env/bin/:$PATH" PATH="/app/env/bin/:$PATH"

View file

@ -14,24 +14,26 @@ fi
docker buildx build -f docker/Dockerfile \ docker buildx build -f docker/Dockerfile \
--platform linux/arm64,linux/amd64 \ --platform linux/arm64,linux/amd64 \
--build-arg "COMMIT=${COMMIT}" \
--label "org.opencontainers.image.version=${COMMIT}" \ --label "org.opencontainers.image.version=${COMMIT}" \
-t "ghcr.io/c3nav/c3nav:${COMMIT}" \
--annotation org.opencontainers.image.source="https://github.com/c3nav/c3nav" \ --annotation org.opencontainers.image.source="https://github.com/c3nav/c3nav" \
--annotation org.opencontainers.image.url="https://c3nav.de" \ --annotation org.opencontainers.image.url="https://c3nav.de" \
--annotation org.opencontainers.image.authors="c3nav team" \ --annotation org.opencontainers.image.authors="c3nav team" \
--annotation org.opencontainers.image.description="Indoor navigation for the Chaos Communication Congress and other events. - Core" \ --annotation org.opencontainers.image.description="Indoor navigation for the Chaos Communication Congress and other events. - Core" \
--tag "ghcr.io/c3nav/c3nav:${COMMIT}" \
--cache-from "type=registry,ref=ghcr.io/c3nav/c3nav_cache:main" \ --cache-from "type=registry,ref=ghcr.io/c3nav/c3nav_cache:main" \
--cache-to "type=registry,ref=ghcr.io/c3nav/c3nav_cache:main,mode=max" \ --cache-to "type=registry,ref=ghcr.io/c3nav/c3nav_cache:main,mode=max" \
--push "${CONTEXT}" --push "${CONTEXT}"
docker buildx build -f docker/tileserver.dockerfile \ docker buildx build -f docker/tileserver.dockerfile \
--platform linux/arm64,linux/amd64 \ --platform linux/arm64,linux/amd64 \
--build-arg "COMMIT=${COMMIT}" \
--label "org.opencontainers.image.version=${COMMIT}" \ --label "org.opencontainers.image.version=${COMMIT}" \
-t "ghcr.io/c3nav/c3nav-tileserver:${COMMIT}" \
--annotation org.opencontainers.image.source="https://github.com/c3nav/c3nav" \ --annotation org.opencontainers.image.source="https://github.com/c3nav/c3nav" \
--annotation org.opencontainers.image.url="https://c3nav.de" \ --annotation org.opencontainers.image.url="https://c3nav.de" \
--annotation org.opencontainers.image.authors="c3nav team" \ --annotation org.opencontainers.image.authors="c3nav team" \
--annotation org.opencontainers.image.description="Indoor navigation for the Chaos Communication Congress and other events. - Tileserver" \ --annotation org.opencontainers.image.description="Indoor navigation for the Chaos Communication Congress and other events. - Tileserver" \
--tag "ghcr.io/c3nav/c3nav-tileserver:${COMMIT}" \
--cache-from "type=registry,ref=ghcr.io/c3nav/c3nav_cache:tileserver_main" \ --cache-from "type=registry,ref=ghcr.io/c3nav/c3nav_cache:tileserver_main" \
--cache-to "type=registry,ref=ghcr.io/c3nav/c3nav_cache:tileserver_main,mode=max" \ --cache-to "type=registry,ref=ghcr.io/c3nav/c3nav_cache:tileserver_main,mode=max" \
--push "${CONTEXT}" --push "${CONTEXT}"

View file

@ -50,6 +50,7 @@ RUN --mount=type=cache,target=/pip-cache \
pip install --cache-dir /pip-cache uwsgi pip install --cache-dir /pip-cache uwsgi
FROM base as final FROM base as final
ARG COMMIT
RUN groupadd -r -g 500 c3nav && useradd -r -u 500 -g 500 -G www-data c3nav RUN groupadd -r -g 500 c3nav && useradd -r -u 500 -g 500 -G www-data c3nav
RUN mkdir /data && chown -R c3nav:c3nav /data RUN mkdir /data && chown -R c3nav:c3nav /data
VOLUME /data VOLUME /data
@ -61,6 +62,7 @@ ENV C3NAV_DEBUG="" \
C3NAV_LOGLEVEL="INFO" \ C3NAV_LOGLEVEL="INFO" \
C3NAV_DATA_DIR="/data" \ C3NAV_DATA_DIR="/data" \
C3NAV_RELOAD_INTERVAL="60" \ C3NAV_RELOAD_INTERVAL="60" \
C3NAV_VERSION="${COMMIT}"
UWSGI_WORKERS="4" UWSGI_WORKERS="4"
# The following environment variables need to be set to start the tileserver # The following environment variables need to be set to start the tileserver

View file

@ -0,0 +1,29 @@
import os
import subprocess
from contextlib import suppress
from pathlib import Path
def _get_version():
# first check for the environment variable that is set inside docker containers we build
if version := os.environ.get('C3NAV_VERSION', None):
return version.strip()
# alternatively check if there is a `.version` file at the root of the c3nav module
version_file = Path(__file__).resolve().parent / '.version'
with suppress(FileNotFoundError):
if version := version_file.read_text().strip():
return version
# last check if this a checkout of c3nav git repo and get the current HEAD
if (Path(__file__).resolve().parent.parent.parent / '.git').exists():
with suppress(FileNotFoundError, subprocess.SubprocessError):
run = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True, encoding='utf-8')
if run.returncode == 0:
return run.stdout.strip()
# if everything fails return None
return None
__version__ = _get_version()

View file

@ -13,6 +13,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from c3nav import __version__ as c3nav_version
from c3nav.utils.config import C3navConfigParser from c3nav.utils.config import C3navConfigParser
from c3nav.utils.environ import Env from c3nav.utils.environ import Env
@ -61,6 +62,7 @@ with suppress(ImportError):
denylist = DEFAULT_DENYLIST + sensitive_env_vars + sensitive_vars denylist = DEFAULT_DENYLIST + sensitive_env_vars + sensitive_vars
sentry_sdk.init( sentry_sdk.init(
dsn=SENTRY_DSN, dsn=SENTRY_DSN,
release=c3nav_version,
integrations=[CeleryIntegration(), DjangoIntegration()], integrations=[CeleryIntegration(), DjangoIntegration()],
event_scrubber=EventScrubber(denylist=denylist), event_scrubber=EventScrubber(denylist=denylist),
enable_tracing=bool(config.getfloat('sentry', 'traces_sample_rate', fallback=0.0)), enable_tracing=bool(config.getfloat('sentry', 'traces_sample_rate', fallback=0.0)),

View file

@ -19,6 +19,7 @@
{% if patrons %} {% if patrons %}
<p>{% blocktrans %}Development of the software was supported by the following patrons on <a href="https://patreon.com/c3nav" rel="external" target="_blank">Patreon</a>:{% endblocktrans %} {{ patrons }}</p> <p>{% blocktrans %}Development of the software was supported by the following patrons on <a href="https://patreon.com/c3nav" rel="external" target="_blank">Patreon</a>:{% endblocktrans %} {{ patrons }}</p>
{% endif %} {% endif %}
<p>Version: {{ version }}</p>
{% if address %} {% if address %}
<h4>{% trans 'Responsible for this website:' %}</h4> <h4>{% trans 'Responsible for this website:' %}</h4>

View file

@ -25,6 +25,7 @@ from django.views.decorators.cache import cache_control, never_cache
from django.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.decorators.http import etag from django.views.decorators.http import etag
from c3nav import __version__ as c3nav_version
from c3nav.api.models import Secret from c3nav.api.models import Secret
from c3nav.control.forms import AccessPermissionForm, SignedPermissionDataError from c3nav.control.forms import AccessPermissionForm, SignedPermissionDataError
from c3nav.mapdata.grid import grid from c3nav.mapdata.grid import grid
@ -362,6 +363,7 @@ def about_view(request):
'patrons': settings.IMPRINT_PATRONS, 'patrons': settings.IMPRINT_PATRONS,
'team': settings.IMPRINT_TEAM, 'team': settings.IMPRINT_TEAM,
'hosting': settings.IMPRINT_HOSTING, 'hosting': settings.IMPRINT_HOSTING,
'version': c3nav_version,
}) })