Skip to content

Commit

Permalink
Merge pull request #40 from bento-platform/git-info
Browse files Browse the repository at this point in the history
Git info in local dev mode
  • Loading branch information
davidlougheed authored Mar 6, 2023
2 parents 25f7330 + 9c0501e commit f731f18
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 160 deletions.
36 changes: 35 additions & 1 deletion bento_aggregation_service/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import bento_aggregation_service
import tornado.gen
import tornado.ioloop
Expand Down Expand Up @@ -42,9 +43,42 @@ class ServiceInfoHandler(RequestHandler):
},
}

@staticmethod
async def _git_stdout(*args) -> str:
git_proc = await asyncio.create_subprocess_exec(
"git", *args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
res, _ = await git_proc.communicate()
return res.decode().rstrip()

async def get(self):
# Spec: https://github.com/ga4gh-discovery/ga4gh-service-info
self.write(self.SERVICE_INFO)

if not CHORD_DEBUG:
# Cache production service info, since no information should change
self.set_header("Cache-Control", "private")
self.write({**self.SERVICE_INFO, "environment": "prod"})
return

service_info = {
**self.SERVICE_INFO,
"environment": "dev",
}

try:
if res_tag := await self._git_stdout("describe", "--tags", "--abbrev=0"):
# noinspection PyTypeChecker
service_info["bento"]["gitTag"] = res_tag
if res_branch := await self._git_stdout("branch", "--show-current"):
# noinspection PyTypeChecker
service_info["bento"]["gitBranch"] = res_branch
if res_commit := await self._git_stdout("rev-parse", "HEAD"):
# noinspection PyTypeChecker
service_info["bento"]["gitCommit"] = res_commit

except Exception as e:
logger.warning(f"Could not retrieve git information: {type(e).__name__}")

self.write(service_info)


class Application(tornado.web.Application):
Expand Down
Loading

0 comments on commit f731f18

Please sign in to comment.