From 0feb43dd57fd482fb07c3f26c1206dd5969e9e58 Mon Sep 17 00:00:00 2001 From: Carmen Tawalika Date: Thu, 9 Dec 2021 19:13:02 +0200 Subject: [PATCH] Local dev setup with vscode & some tiny fixes (#128) * some tiny fixes * add local dev setup --- .gitignore | 2 - .vscode/launch.json | 24 ++++++++++ .vscode/tasks.json | 48 +++++++++++++++++++ docker/dev/Dockerfile | 23 +++++++++ setup.cfg | 2 +- .../actinia_processing/actinia_interface.py | 6 ++- .../actinia_processing/config.py | 3 ++ src/openeo_grass_gis_driver/collections.py | 45 +++++++++-------- 8 files changed, 127 insertions(+), 26 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 docker/dev/Dockerfile diff --git a/.gitignore b/.gitignore index fc61b4e4..950c7590 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,4 @@ docs/_build/* cover/* MANIFEST -.vscode venv - diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..0e1e7396 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "configurations": [ + { + "name": "Docker: Python - Flask", + "type": "docker", + "request": "launch", + "preLaunchTask": "docker-run: debug", + "python": { + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/src/openeo_grass_gis_driver" + } + ], + "projectType": "flask" + }, + "dockerServerReadyAction": { + "action": "openExternally", + "pattern": "Running on (https?://\\S+|[0-9]+)", + "uriFormat": "%s://localhost:%s/api/v1.0/collections" + } + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..41b444ce --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,48 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "docker-build", + "label": "docker-build", + "platform": "python", + "dockerBuild": { + "tag": "openeograssgisdriver:latest", + "dockerfile": "${workspaceFolder}/docker/dev/Dockerfile", + "context": "${workspaceFolder}" + // "pull": true + } + }, + { + "type": "docker-run", + "label": "docker-run: debug", + "dependsOn": [ + "docker-build" + ], + "python": { + "args": [ + "run", + "--no-debugger", + // "--no-reload", + "--host", + "0.0.0.0", + "--port", + "5000" + ], + "module": "flask" + // "file": "dev.py" + }, + "dockerRun": { + "remove": true, + // network host is needed when connecting to a local actinia + // while not using docker-compose network + "network": "host", + "volumes": [{ + "localPath": "${workspaceFolder}", + "containerPath": "/src/openeo_grass_gis_driver", + "permissions": "rw" + }] + }, + + } + ] +} diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile new file mode 100644 index 00000000..08fe99c0 --- /dev/null +++ b/docker/dev/Dockerfile @@ -0,0 +1,23 @@ +FROM mundialis/openeo-grassgis-driver:latest as base + +# Keeps Python from generating .pyc files in the container +ENV PYTHONDONTWRITEBYTECODE=1 +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED=1 +ENV FLASK_APP=openeo_grass_gis_driver.main +ENV FLASK_ENV=development +ENV FLASK_DEBUG=1 +ENV DEFAULT_CONFIG_PATH=/src/openeo_grass_gis_driver/config + +RUN apk add make git + +RUN pip3 uninstall openeo-grass-gis-driver -y + +COPY . /src/openeo_grass_gis_driver/ +COPY config/sample.ini /src/openeo_grass_gis_driver/config/config.ini + +WORKDIR /src/openeo_grass_gis_driver/ +RUN pip3 install -e . + +# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug +CMD ["gunicorn", "--bind", "0.0.0.0:5000", "openeo_grass_gis_driver.main"] diff --git a/setup.cfg b/setup.cfg index 2a513622..d276e2ac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,7 +26,7 @@ package_dir = =src # Add here dependencies of your project (semicolon-separated), e.g. # install_requires = numpy; scipy -install_requires = +install_requires = colorlog; python-json-logger; # Add here test requirements (semicolon-separated) tests_require = pytest; pytest-cov diff --git a/src/openeo_grass_gis_driver/actinia_processing/actinia_interface.py b/src/openeo_grass_gis_driver/actinia_processing/actinia_interface.py index d1232735..3d0d8763 100644 --- a/src/openeo_grass_gis_driver/actinia_processing/actinia_interface.py +++ b/src/openeo_grass_gis_driver/actinia_processing/actinia_interface.py @@ -25,8 +25,10 @@ def __init__(self, config: ActiniaConfig = None): self.host = config.HOST self.port = config.PORT - self.base_url = "%(host)s:%(port)s/api/v1" % { - "host": self.host, "port": self.port} + self.version = config.VERSION + self.base_url = "%(host)s:%(port)s/api/%(version)s" % { + "host": self.host, "port": self.port, + "version": self.version} self.auth = (config.USER, config.PASSWORD) self.user = config.USER diff --git a/src/openeo_grass_gis_driver/actinia_processing/config.py b/src/openeo_grass_gis_driver/actinia_processing/config.py index c751c998..4b83de6b 100644 --- a/src/openeo_grass_gis_driver/actinia_processing/config.py +++ b/src/openeo_grass_gis_driver/actinia_processing/config.py @@ -28,6 +28,7 @@ class ACTINIA: LOCATIONS = ["nc_spm_08", "utm32n", "latlong_wgs84"] USER = "openeo" PASSWORD = "EeMob0la" + VERSION = "v2" # The database file that stores the graphs GRAPH_DB = "%s/.graph_db_file.sqlite" % os.environ["HOME"] # The database file that stores the jobs @@ -77,6 +78,8 @@ def __init__(self): ACTINIA.USER = config.get("ACTINIA", "USER") if config.has_option("ACTINIA", "PASSWORD"): ACTINIA.PASSWORD = config.get("ACTINIA", "PASSWORD") + if config.has_option("ACTINIA", "VERSION"): + ACTINIA.VERSION = config.get("ACTINIA", "VERSION") if config.has_option("ACTINIA", "GRAPH_DB"): ACTINIA.GRAPH_DB = config.get("ACTINIA", "GRAPH_DB") if config.has_option("ACTINIA", "TOKEN_DB"): diff --git a/src/openeo_grass_gis_driver/collections.py b/src/openeo_grass_gis_driver/collections.py index d90159f7..3d2b19b0 100644 --- a/src/openeo_grass_gis_driver/collections.py +++ b/src/openeo_grass_gis_driver/collections.py @@ -97,27 +97,30 @@ def get(self): log.warning("Couldn't get STAC collections from actinia") stac_collections = [] - for i in stac_collections['collections']: - try: - title = i['title'] - except Exception: - title = i['id'] - try: - license = i['license'] - except Exception: - license = "proprietary" - try: - description = i['description'] - except Exception: - description = "STAC collection registered in actinia" - - ds = CollectionEntry( - id=i['id'], - title=title, - license=license, - description=description - ) - COLLECTIONS_LIST.append(ds) + if (type(stac_collections) is list and + len(stac_collections) > 0): + + for i in stac_collections['collections']: + try: + title = i['title'] + except Exception: + title = i['id'] + try: + license = i['license'] + except Exception: + license = "proprietary" + try: + description = i['description'] + except Exception: + description = "STAC collection registered in actinia" + + ds = CollectionEntry( + id=i['id'], + title=title, + license=license, + description=description + ) + COLLECTIONS_LIST.append(ds) c = Collection(collections=COLLECTIONS_LIST) return c.as_response(http_status=200)