Skip to content

Commit

Permalink
Add support for returning the current version as string
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Jan 19, 2024
1 parent f3f1b9a commit 7a3ee12
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/fastapi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python
COPY . /app
WORKDIR /app
ENV PATH=/opt/poetry/bin:$PATH
RUN echo "${TAG_VERSION:-docker}" > /app/dataapi/TAG_VERSION
RUN poetry config virtualenvs.in-project true && poetry install --no-interaction --no-ansi

### Actual image running on the host
Expand Down
15 changes: 15 additions & 0 deletions api/fastapi/dataapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@
app.include_router(measurements.router, prefix="/api")
app.include_router(aggregation.router, prefix="/api")

from importlib.metadata import version as importlib_version
from importlib.resources import files as importlib_files

pkg_name = "dataapi"

pkg_version = importlib_version(pkg_name)
try:
with importlib_files("dataapi").joinpath("TAG_VERSION").open('r') as in_file:
tag_version = in_file.read().strip()
except:
tag_version = None

@app.get("/version")
async def version():
return {"version": pkg_version, "tag_version": tag_version}

@app.get("/")
async def root():
Expand Down
2 changes: 1 addition & 1 deletion api/fastapi/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "data-api"
name = "dataapi"
version = "0.1.0"
description = ""
authors = ["OONI <[email protected]>"]
Expand Down

0 comments on commit 7a3ee12

Please sign in to comment.