From 944831b6b83509944fb1fa8f1bde47f77c2e52af Mon Sep 17 00:00:00 2001 From: Dimas Date: Mon, 23 Sep 2024 14:34:27 +0100 Subject: [PATCH 1/4] Add swagger --- Makefile | 20 ++++++++++---------- django_project/cloud_native_gis/urls.py | 22 +++++++++++++++++++++- django_project/core/settings/contrib.py | 1 + requirements.txt | 1 + 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index f9cde75..2227c90 100644 --- a/Makefile +++ b/Makefile @@ -6,42 +6,42 @@ build: @echo "------------------------------------------------------------------" @echo "Building in production mode" @echo "------------------------------------------------------------------" - @docker-compose build + @docker compose build up: @echo @echo "------------------------------------------------------------------" @echo "Running in production mode" @echo "------------------------------------------------------------------" - @docker-compose ${ARGS} up -d nginx django + @docker compose ${ARGS} up -d nginx django dev: @echo @echo "------------------------------------------------------------------" @echo "Running in dev mode" @echo "------------------------------------------------------------------" - @docker-compose ${ARGS} up -d dev + @docker compose ${ARGS} up -d dev shell: @echo @echo "------------------------------------------------------------------" @echo "Shelling in in production mode" @echo "------------------------------------------------------------------" - @docker-compose exec django /bin/bash + @docker compose exec django /bin/bash dev-entrypoint: @echo @echo "------------------------------------------------------------------" @echo "Running in DEVELOPMENT mode" @echo "------------------------------------------------------------------" - @docker-compose ${ARGS} exec -T dev "/home/web/django_project/entrypoint.sh" + @docker compose ${ARGS} exec -T dev "/home/web/django_project/entrypoint.sh" dev-runserver: @echo @echo "------------------------------------------------------------------" @echo "Start django runserver in dev container" @echo "------------------------------------------------------------------" - @docker-compose $(ARGS) exec -T dev bash -c "nohup python manage.py runserver 0.0.0.0:5000 &" + @docker compose $(ARGS) exec -T dev bash -c "nohup python manage.py runserver 0.0.0.0:5000 &" dev-load-demo-data: @echo @@ -54,8 +54,8 @@ dev-test: @echo "------------------------------------------------------------------" @echo "Run tests" @echo "------------------------------------------------------------------" - @docker-compose exec -T dev python manage.py collectstatic --noinput - @docker-compose exec -T dev python manage.py test cloud_native_gis.tests --keepdb --noinput + @docker compose exec -T dev python manage.py collectstatic --noinput + @docker compose exec -T dev python manage.py test cloud_native_gis.tests --keepdb --noinput # TODO: Remove cloud_native_gis.tests by fixing issue https://github.com/kartoza/CloudNativeGIS/issues/7 serve: @@ -86,7 +86,7 @@ down: @echo "------------------------------------------------------------------" @echo "Removing production instance!!! " @echo "------------------------------------------------------------------" - @docker-compose down + @docker compose down test-flake: @echo @@ -102,7 +102,7 @@ wait-db: @echo "------------------------------------------------------------------" @echo "Check database is ready or not" @echo "------------------------------------------------------------------" - @docker-compose ${ARGS} exec -T db su - postgres -c "until pg_isready; do sleep 5; done" + @docker compose ${ARGS} exec -T db su - postgres -c "until pg_isready; do sleep 5; done" sleep: @echo diff --git a/django_project/cloud_native_gis/urls.py b/django_project/cloud_native_gis/urls.py index 3c89f08..e0ae722 100644 --- a/django_project/cloud_native_gis/urls.py +++ b/django_project/cloud_native_gis/urls.py @@ -6,11 +6,29 @@ from rest_framework.routers import DefaultRouter from rest_framework_nested.routers import NestedSimpleRouter +from rest_framework import permissions +from drf_yasg.views import get_schema_view +from drf_yasg import openapi + from cloud_native_gis.api.layer import ( LayerViewSet, LayerStyleViewSet ) from cloud_native_gis.api.vector_tile import (VectorTileLayer) +schema_view = get_schema_view( + openapi.Info( + title="Cloud Native GIS API", + default_version='v1', + description="API documentation for the Cloud Native GIS project", + terms_of_service="https://www.example.com/terms/", + contact=openapi.Contact(email="contact@example.com"), + license=openapi.License(name="BSD License"), + ), + public=True, + permission_classes=(permissions.AllowAny,), +) + + router = DefaultRouter() router.register( r'layer', LayerViewSet, basename='cloud-native-gis-layer' @@ -35,5 +53,7 @@ 'maputnik/', TemplateView.as_view(template_name='cloud_native_gis/maputnik.html'), name='cloud-native-gis-maputnik' - ) + ), + path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), + path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc-ui'), ] diff --git a/django_project/core/settings/contrib.py b/django_project/core/settings/contrib.py index 24b8efc..a4a6a16 100644 --- a/django_project/core/settings/contrib.py +++ b/django_project/core/settings/contrib.py @@ -17,6 +17,7 @@ 'django_cleanup.apps.CleanupConfig', 'django_celery_beat', 'django_celery_results', + 'drf_yasg', ) WEBPACK_LOADER = { diff --git a/requirements.txt b/requirements.txt index 5b1c45a..8a6b029 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ black cffi # Needed for PDF back page QR Code qrcode +drf-yasg==1.21.7 From 6902ffe377324e931ee16cf7bfd71b20951b3ea9 Mon Sep 17 00:00:00 2001 From: Dimas Date: Mon, 23 Sep 2024 14:36:57 +0100 Subject: [PATCH 2/4] Update urls --- django_project/cloud_native_gis/urls.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/django_project/cloud_native_gis/urls.py b/django_project/cloud_native_gis/urls.py index e0ae722..38c7a14 100644 --- a/django_project/cloud_native_gis/urls.py +++ b/django_project/cloud_native_gis/urls.py @@ -54,6 +54,10 @@ TemplateView.as_view(template_name='cloud_native_gis/maputnik.html'), name='cloud-native-gis-maputnik' ), - path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), - path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc-ui'), + path('swagger/', + schema_view.with_ui('swagger', cache_timeout=0), + name='schema-swagger-ui'), + path('redoc/', + schema_view.with_ui('redoc', cache_timeout=0), + name='schema-redoc-ui'), ] From 4cff8361927d8b6a73db64fa4e1caf74308550f5 Mon Sep 17 00:00:00 2001 From: Dimas Date: Mon, 23 Sep 2024 14:49:06 +0100 Subject: [PATCH 3/4] Add drf-yasg in requirement --- deployment/docker/requirements.txt | 3 ++- requirements.txt | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/docker/requirements.txt b/deployment/docker/requirements.txt index ece63fe..983cf77 100644 --- a/deployment/docker/requirements.txt +++ b/deployment/docker/requirements.txt @@ -40,4 +40,5 @@ redis==4.3.4 # Library to handle geospatial functions GeoAlchemy2==0.15.1 -geopandas==0.13.2 \ No newline at end of file +geopandas==0.13.2 +drf-yasg==1.21.7 diff --git a/requirements.txt b/requirements.txt index 8a6b029..5b1c45a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,3 @@ black cffi # Needed for PDF back page QR Code qrcode -drf-yasg==1.21.7 From 385e805257a81c85b19daacff93e837705f70280 Mon Sep 17 00:00:00 2001 From: Dimas Date: Mon, 23 Sep 2024 16:37:52 +0100 Subject: [PATCH 4/4] Update geopandas to fix fiona error --- deployment/docker/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/docker/requirements.txt b/deployment/docker/requirements.txt index 983cf77..72b2ef7 100644 --- a/deployment/docker/requirements.txt +++ b/deployment/docker/requirements.txt @@ -40,5 +40,5 @@ redis==4.3.4 # Library to handle geospatial functions GeoAlchemy2==0.15.1 -geopandas==0.13.2 +geopandas==0.14.4 drf-yasg==1.21.7