Skip to content

Commit e473ece

Browse files
committed
chore: don't use git to determine the commit hash
Get the commit hash from the openshift's environment.
1 parent f181db2 commit e473ece

4 files changed

Lines changed: 8 additions & 13 deletions

File tree

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ RUN yum update -y && yum install -y \
2222
&& uwsgi --build-plugin https://github.com/City-of-Helsinki/uwsgi-sentry \
2323
&& yum clean all
2424

25-
# fatal: detected dubious ownership in repository at '/app'
26-
RUN git config --system --add safe.directory /app
27-
2825
COPY --chown=root:root --chmod=755 docker-entrypoint.sh /entrypoint/docker-entrypoint.sh
2926
ENTRYPOINT ["/entrypoint/docker-entrypoint.sh"]
3027

@@ -46,4 +43,4 @@ FROM appbase AS production
4643
RUN SECRET_KEY="only-used-for-collectstatic" python manage.py collectstatic
4744

4845
USER default
49-
EXPOSE 8000/tcp
46+
EXPOSE 8000/tcp

common/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def update_object_with_translations(model, model_data):
8686

8787

8888
def get_api_version():
89-
return " | ".join((__version__, settings.COMMIT_HASH.decode("utf-8")))
89+
return " | ".join((__version__, settings.COMMIT_HASH))
9090

9191

9292
def get_node_id_from_global_id(global_id, node_name):

palvelutarjotin/settings.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import subprocess
32
import tempfile
43
from datetime import datetime
54
from pathlib import Path
@@ -10,6 +9,7 @@
109
from django.utils.translation import gettext_lazy as _
1110
from sentry_sdk.integrations.django import DjangoIntegration
1211

12+
from palvelutarjotin import __version__
1313
from palvelutarjotin.consts import CSP
1414

1515
checkout_dir = environ.Path(__file__) - 2
@@ -94,6 +94,7 @@
9494
SOCIAL_AUTH_TUNNISTAMO_SECRET=(str, ""), # empty to ignore it's being unset.
9595
LOGIN_REDIRECT_URL=(str, "/admin/"),
9696
LOGOUT_REDIRECT_URL=(str, "/admin/"),
97+
OPENSHIFT_BUILD_COMMIT=(str, ""),
9798
)
9899

99100
if os.path.exists(env_file):
@@ -158,14 +159,11 @@
158159
ILMOITIN_QUEUE_NOTIFICATIONS = env("ILMOITIN_QUEUE_NOTIFICATIONS")
159160
TRANSLATED_SMS_SENDER = env("TRANSLATED_SMS_SENDER")
160161

161-
try:
162-
COMMIT_HASH = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip()
163-
except Exception:
164-
COMMIT_HASH = b"n/a"
165-
162+
COMMIT_HASH = env("OPENSHIFT_BUILD_COMMIT")
163+
VERSION = __version__
166164
sentry_sdk.init(
167165
dsn=env.str("SENTRY_DSN"),
168-
release=COMMIT_HASH,
166+
release=env.str("OPENSHIFT_BUILD_COMMIT", VERSION),
169167
environment=env("SENTRY_ENVIRONMENT"),
170168
integrations=[DjangoIntegration()],
171169
)

palvelutarjotin/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def readiness(*args, **kwargs):
6464
"status": "ok",
6565
"release": settings.APP_RELEASE,
6666
"packageVersion": __version__,
67-
"commitHash": settings.COMMIT_HASH.decode("utf-8"),
67+
"commitHash": settings.COMMIT_HASH,
6868
"buildTime": settings.APP_BUILD_TIME.strftime("%Y-%m-%dT%H:%M:%S.000Z"),
6969
}
7070
return JsonResponse(response_json, status=200)

0 commit comments

Comments
 (0)