Skip to content

Commit

Permalink
Merge pull request #53 from bento-platform/chore/updates
Browse files Browse the repository at this point in the history
chore: update dependencies, base img, actions
  • Loading branch information
davidlougheed authored Feb 12, 2024
2 parents 1fceab4 + ae534e1 commit 62a8b8c
Show file tree
Hide file tree
Showing 10 changed files with 941 additions and 956 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.12"]

steps:

Expand All @@ -23,7 +23,7 @@ jobs:
submodules: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.12"]

steps:

Expand All @@ -23,7 +23,7 @@ jobs:
submodules: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -34,7 +34,9 @@ jobs:
run: python -m poetry install

- name: Test
run: poetry run coverage run -m unittest -v
run: poetry run pytest -svv --cov=bento_aggregation_service --cov-branch

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.10.20
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2024.02.01

# Run as root in the Dockerfile until we drop down to the service user in the entrypoint
USER root

# Use uvicorn (instead of hypercorn) in production since I've found
# multiple benchmarks showing it to be faster - David L
RUN pip install --no-cache-dir "uvicorn[standard]==0.23.2"
RUN pip install --no-cache-dir "uvicorn[standard]==0.27.1"

WORKDIR /aggregation

Expand Down
53 changes: 11 additions & 42 deletions bento_aggregation_service/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from __future__ import annotations

import asyncio
import bento_aggregation_service

from bento_lib.types import GA4GHServiceInfo
from bento_lib.service_info.helpers import build_service_info_from_pydantic_config
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from . import __version__
from .config import ConfigDependency, get_config
from .constants import (
BENTO_SERVICE_KIND,
SERVICE_TYPE,
SERVICE_NAME,
)
from .constants import BENTO_SERVICE_KIND, SERVICE_TYPE
from .logger import LoggerDependency
from .search.handlers.datasets import dataset_search_router

Expand Down Expand Up @@ -42,40 +38,13 @@ async def _git_stdout(*args) -> str:

@application.get("/service-info")
async def service_info(config: ConfigDependency, logger: LoggerDependency):
info: GA4GHServiceInfo = {
"id": config.service_id,
"name": SERVICE_NAME, # TODO: Should be globally unique?
"type": SERVICE_TYPE,
"description": "Aggregation service for a Bento platform node.",
"organization": {
"name": "C3G",
"url": "https://www.computationalgenomics.ca"
},
"contactUrl": "mailto:[email protected]",
"version": bento_aggregation_service.__version__,
"bento": {
return await build_service_info_from_pydantic_config(
config,
logger,
{
"serviceKind": BENTO_SERVICE_KIND,
"gitRepository": "https://github.com/bento-platform/bento_aggregation_service",
},
"environment": "prod",
}

if not config.bento_debug:
return info

info["environment"] = "dev"

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

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

return info
SERVICE_TYPE,
__version__,
)
42 changes: 5 additions & 37 deletions bento_aggregation_service/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import json

from bento_lib.config.pydantic import BentoBaseConfig
from fastapi import Depends
from functools import lru_cache
from pydantic.fields import FieldInfo
from pydantic_settings import BaseSettings, EnvSettingsSource, PydanticBaseSettingsSource, SettingsConfigDict
from typing import Annotated, Any, Literal
from typing import Annotated

from .constants import SERVICE_TYPE
from .constants import SERVICE_NAME, SERVICE_TYPE

__all__ = [
"Config",
Expand All @@ -15,46 +12,17 @@
]


class CorsOriginsParsingSource(EnvSettingsSource):
def prepare_field_value(self, field_name: str, field: FieldInfo, value: Any, value_is_complex: bool) -> Any:
if field_name == "cors_origins":
return tuple(x.strip() for x in value.split(";")) if value is not None else ()
return json.loads(value) if value_is_complex else value


class Config(BaseSettings):
bento_debug: bool = False

class Config(BentoBaseConfig):
service_id: str = str(":".join(list(SERVICE_TYPE.values())[:2]))
service_name: str = SERVICE_NAME

request_timeout: int = 180 # seconds

bento_authz_service_url: str # Bento authorization service base URL
authz_enabled: bool = True

# Other services - settings and flags
use_gohan: bool = False
katsu_url: str
service_registry_url: str # used for fetching list of data services, so we can get data type providers

cors_origins: tuple[str, ...] = ("*",)

log_level: Literal["debug", "info", "warning", "error"] = "debug"

# Make Config instances hashable + immutable
model_config = SettingsConfigDict(frozen=True)

@classmethod
def settings_customise_sources(
cls,
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]:
return (CorsOriginsParsingSource(settings_cls),)


@lru_cache()
def get_config() -> Config:
Expand Down
2 changes: 1 addition & 1 deletion bento_aggregation_service/service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import contextlib
import logging

from bento_lib.types import GA4GHServiceInfo
from bento_lib.service_info.types import GA4GHServiceInfo
from fastapi import Depends
from functools import lru_cache
from typing import Annotated, AsyncIterator
Expand Down
4 changes: 2 additions & 2 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.10.20
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2024.02.01

LABEL org.opencontainers.image.description="Local development image the Bento aggregation service."
LABEL devcontainer.metadata='[{ \
Expand All @@ -14,7 +14,7 @@ LABEL devcontainer.metadata='[{ \
# Run as root in the Dockerfile until we drop down to the service user in the entrypoint
USER root

RUN pip install --no-cache-dir "uvicorn[standard]==0.23.2"
RUN pip install --no-cache-dir "uvicorn[standard]==0.27.1"

WORKDIR /aggregation

Expand Down
Loading

0 comments on commit 62a8b8c

Please sign in to comment.