Skip to content

Commit 3bb5cad

Browse files
committed
[FEATURE] Add version on github generated docker
1 parent 7cda046 commit 3bb5cad

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ RUN pip install waitress
1919

2020
COPY collectives /app/collectives/
2121
COPY deployment/docker/logging.cfg /app/
22+
COPY metadata.jso[n] /app/
2223

2324
WORKDIR /app
2425

config.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# All configuration parameters defined in
1010
# this file can be overriden in instance/config.py
1111

12+
import json
1213
import os
1314
from os import environ
1415
import subprocess
@@ -136,14 +137,33 @@
136137
:type: string
137138
"""
138139

139-
# Page information
140-
run = subprocess.run(
141-
["git", "describe", "--tags"],
142-
stdout=subprocess.PIPE,
143-
check=False,
144-
cwd=os.path.dirname(__file__),
145-
)
146-
VERSION = run.stdout.decode("utf-8")
140+
141+
if os.path.exists(".git"):
142+
# If git is here, version is extracted from git tags
143+
run = subprocess.run(
144+
["git", "describe", "--tags"],
145+
stdout=subprocess.PIPE,
146+
check=False,
147+
cwd=os.path.dirname(__file__),
148+
)
149+
VERSION = run.stdout.decode("utf-8")
150+
elif os.path.exists("metadata.json"):
151+
# If metadata is here, version is extracted from docker metadata
152+
try:
153+
with open("metadata.json", "r", encoding="utf-8") as file:
154+
VERSION = json.load(file)["labels"]["org.opencontainers.image.version"]
155+
except json.JSONDecodeError:
156+
print("Erreur : Le fichier 'metadata.json' est mal formé.")
157+
VERSION = ""
158+
except KeyError as e:
159+
print(f"Erreur : La clé {e} est manquante dans le fichier 'metadata.json'.")
160+
VERSION = ""
161+
except TypeError:
162+
print("Erreur : Le format du fichier JSON n'est pas valide.")
163+
VERSION = ""
164+
else:
165+
VERSION = ""
166+
147167
# FAVICON= "img/icon/favicon.ico"
148168
FAVICON = "caf/favicon.ico"
149169
"""URL to the site favicon

0 commit comments

Comments
 (0)