From a5bcd54dbf67728df74f320929a0bb236e513440 Mon Sep 17 00:00:00 2001 From: Brian Brondel Date: Tue, 14 Jan 2025 18:58:20 -0300 Subject: [PATCH] Add metadata to the root endpoints --- .github/workflows/build.yaml | 11 +++++++++++ Dockerfile.pqserver | 4 ++++ python/lsst/consdb/config.py | 14 +++++++++++++- python/lsst/consdb/handlers/external.py | 3 +++ python/lsst/consdb/handlers/internal.py | 8 ++++---- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b82490ff..7daad27b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -18,6 +18,15 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Extract Git Tag or Branch + id: git_info + run: | + if [[ "${{ github.ref_type }}" == "tag" ]]; then + echo "GIT_TAG=${{ github.ref_name }}" >> $GITHUB_TAG + else + echo "GIT_TAG=noversion" >> $GITHUB_TAG + fi + - name: Build hinfo uses: lsst-sqre/build-and-push-to-ghcr@v1 with: @@ -31,3 +40,5 @@ jobs: image: ${{ github.repository }}-pq github_token: ${{ secrets.GITHUB_TOKEN }} dockerfile: Dockerfile.pqserver + build-args: | + GITHUB_TAG=${{ env.GITHUB_TAG }} diff --git a/Dockerfile.pqserver b/Dockerfile.pqserver index e85b257f..eec35521 100644 --- a/Dockerfile.pqserver +++ b/Dockerfile.pqserver @@ -1,4 +1,8 @@ FROM python:3.11 + +ARG GITHUB_TAG +ENV VERSION=${GITHUB_TAG} + RUN pip install fastapi safir astropy uvicorn gunicorn sqlalchemy psycopg2 WORKDIR / COPY \ diff --git a/python/lsst/consdb/config.py b/python/lsst/consdb/config.py index 1722292c..2aa00d36 100644 --- a/python/lsst/consdb/config.py +++ b/python/lsst/consdb/config.py @@ -15,7 +15,7 @@ class Configuration(BaseSettings): name: str = Field("pqserver", title="Application name") - version: str = Field("noversion", title="Application version number") + version: str | None = Field(None, title="Application version number") url_prefix: str = Field("/consdb", title="URL prefix") @@ -46,6 +46,18 @@ class Configuration(BaseSettings): consdb_url: str | None = Field(None, title="Database URL set by CONSDB_URL") + description: str | None = Field( + "A web interface to the Rubin Observatory Consolidated Database.", title="Application description." + ) + + repository_url: str | None = Field( + "https://github.com/lsst-dm/consdb", title="Source repository for this code." + ) + + documentation_url: str | None = Field( + "https://consdb.lsst.io/index.html", title="URL for documentation of this project." + ) + @property def database_url(self) -> str: """Infers the database URL based on the provided configuration. diff --git a/python/lsst/consdb/handlers/external.py b/python/lsst/consdb/handlers/external.py index 95a94a13..266ad0ac 100644 --- a/python/lsst/consdb/handlers/external.py +++ b/python/lsst/consdb/handlers/external.py @@ -70,6 +70,9 @@ def external_root( return IndexResponseModel( name=config.name, version=config.version, + description=config.description, + repository_url=config.repository_url, + documentation_url=config.documentation_url, instruments=instrument_list, obs_types=[o.value for o in ObsTypeEnum], dtypes=[d.value for d in AllowedFlexTypeEnum], diff --git a/python/lsst/consdb/handlers/internal.py b/python/lsst/consdb/handlers/internal.py index 8f8897a8..0016cc46 100644 --- a/python/lsst/consdb/handlers/internal.py +++ b/python/lsst/consdb/handlers/internal.py @@ -52,10 +52,10 @@ def internal_root( return IndexResponseModel.model_validate( { "name": config.name, - "version": "0.0.0", # TODO: insert an actual version number - "description": "A web interface to the Rubin Observatory Consolidated Database.", - "repository_url": "https://github.com/lsst-db/consdb", - "documentation_url": "https://consdb.lsst.io/index.html", + "version": config.version, + "description": config.description, + "repository_url": config.repository_url, + "documentation_url": config.documentation_url, "instruments": instrument_list, "obs_types": [o.value for o in ObsTypeEnum], "dtypes": [d.value for d in AllowedFlexTypeEnum],