Skip to content

Commit 37a72c5

Browse files
committed
display dynamic git version on homepage and openapi docs
1 parent 85f7d5e commit 37a72c5

6 files changed

Lines changed: 12 additions & 3 deletions

File tree

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ build-push-image:
8484
- !reference [.image_version, script]
8585
- test "$DOCKER_USER" -a "$DOCKER_PASS" ||
8686
( echo "no docker credentials provided"; exit 1 )
87+
- echo "__version == '$(git describe --tags)'" > app/__init__.py
8788
- $BUILDAH_COMMAND build
8889
--format=docker
8990
--build-arg VCS_REF="${CI_COMMIT_SHA}"

app/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This will be replaced at build time by `git describe --tags`
2+
__version__ = "UNDEFINED"

app/routers/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from starlette.responses import HTMLResponse
33
from starlette.templating import Jinja2Templates
44

5+
from app import __version__
56
from app.config.network_configuration import get_node_logs_link, get_network
67
from app.lib.kubernetes_client import list_validator_stateful_sets, list_parachain_collator_stateful_sets
78
from app.lib.network_utils import list_substrate_nodes, list_validators, get_session_queued_keys, list_parachains, \
@@ -18,7 +19,7 @@
1819
@router.get("/", response_class=HTMLResponse, include_in_schema=False)
1920
@router.get("/index.html", response_class=HTMLResponse, include_in_schema=False)
2021
async def homepage(request: Request):
21-
return templates.TemplateResponse('index.html', {'request': request, 'network': network})
22+
return templates.TemplateResponse('index.html', {'request': request, 'network': network, 'version': __version__})
2223

2324

2425
@router.get("/nodes", response_class=HTMLResponse, include_in_schema=False)

app/templates/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515
<a href="/docs">API Docs</a>
1616
</p>
1717
</body>
18+
<footer>
19+
Version: {{ version }}
20+
</footer>
1821
</html>

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from fastapi.staticfiles import StaticFiles
66
from starlette.responses import PlainTextResponse
77

8+
from app import __version__
89
from app.routers import views, apis
910
from app.config import log_config
1011
from app.config.settings import settings
@@ -16,7 +17,7 @@ class EndpointFilter(logging.Filter):
1617
def filter(self, record: logging.LogRecord) -> bool:
1718
return record.args and len(record.args) >= 3 and record.args[2] != "/health"
1819

19-
app = FastAPI(title=settings.APP_NAME)
20+
app = FastAPI(title=settings.APP_NAME, version=__version__)
2021
app.include_router(apis.router)
2122
app.include_router(views.router)
2223
app.mount("/static", StaticFiles(directory="app/static"), name="static")

task-scheduler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from fastapi.staticfiles import StaticFiles
66
from starlette.responses import PlainTextResponse
77

8+
from app import __version__
89
from app.lib.cron_tasks import load_cron_tasks
910
from app.tasks import views, apis
1011
from app.config import log_config
@@ -18,7 +19,7 @@ def filter(self, record: logging.LogRecord) -> bool:
1819
return record.args and len(record.args) >= 3 and record.args[2] != "/health"
1920

2021

21-
app = FastAPI(title=settings.SCHEDULER_APP_NAME, on_startup=[load_cron_tasks])
22+
app = FastAPI(title=settings.SCHEDULER_APP_NAME, on_startup=[load_cron_tasks], version=__version__)
2223
app.include_router(apis.router)
2324
app.include_router(views.router)
2425
app.mount("/static", StaticFiles(directory="app/static"), name="static")

0 commit comments

Comments
 (0)