From b529fee86ef4f25491029b7324a7c70d5e098167 Mon Sep 17 00:00:00 2001 From: Lewis John McGibbney Date: Mon, 4 Sep 2023 18:08:24 -0700 Subject: [PATCH] ISSUE-287 Replace connexion[swagger-ui] dependency with dedicated swagger-ui container --- docker-compose.yml | 44 ++++++++++------------- services/nginx/config/nginx.conf | 10 ++++-- tagbase_server/requirements.txt | 2 +- tagbase_server/tagbase_server/__main__.py | 6 ++-- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b8e1574..feb5473 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -68,6 +68,7 @@ services: "docker_compose_diagram.icon": "nginx" links: - pgadmin4 + - swagger_ui - tagbase_server networks: - internal-network @@ -100,31 +101,6 @@ services: networks: - internal-network restart: unless-stopped - # postgres: - # build: - # context: ./services/postgres - # environment: - # - PGDATA=/var/lib/postgresql/data/pgdata - # - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - # expose: - # - ${POSTGRES_PORT} - # healthcheck: - # test: ["CMD-SHELL", "pg_isready -d tagbase -h postgres -U tagbase"] - # interval: 15s - # timeout: 5s - # retries: 5 - # start_period: 15s - # hostname: postgres - # labels: - # "docker_compose_diagram.cluster": "Internal Network" - # "docker_compose_diagram.description": "Tagbase PostgreSQL server" - # networks: - # - internal-network - # ports: - # - ${POSTGRES_PORT}:${POSTGRES_PORT} - # restart: unless-stopped - # volumes: - # - ./postgres-data:/var/lib/postgresql/data postgis: environment: - ALLOW_IP_RANGE=0.0.0.0/0 @@ -167,6 +143,24 @@ services: "docker_compose_diagram.icon": "docker" volumes: - /var/run/docker.sock:/var/run/docker.sock + swagger_ui: + environment: + - BASE_URL=/docs + - SWAGGER_JSON_URL=http://tagbase_server:5433/tagbase/api/v0.14.0/openapi.yaml + # expose: + # - 5431 + image: swaggerapi/swagger-ui:v5.4.2 + labels: + "docker_compose_diagram.cluster": "Internal Network" + "docker_compose_diagram.description": "REST API Docs" + "docker_compose_diagram.icon": "docker" + links: + - tagbase_server + networks: + - internal-network + ports: + - 5431:8080 + restart: unless-stopped tagbase_server: build: context: ./tagbase_server diff --git a/services/nginx/config/nginx.conf b/services/nginx/config/nginx.conf index 7b51af9..a7454e7 100644 --- a/services/nginx/config/nginx.conf +++ b/services/nginx/config/nginx.conf @@ -18,6 +18,10 @@ http { server tagbase_server:5433; } + upstream swagger_ui { + server swagger_ui:5431; + } + # always redirect to https server { listen 81 default_server; @@ -28,8 +32,9 @@ http { } server { - listen 443 ssl http2; + listen 443 ssl; listen [::]:443 ssl; + http2 on; ssl_certificate /etc/nginx/certs/cert.pem; ssl_certificate_key /etc/nginx/certs/key.pem; @@ -49,8 +54,9 @@ http { } location /docs { - proxy_pass http://tagbase_server/tagbase/api/v0.14.0/ui; + proxy_pass http://swagger_ui; proxy_set_header Origin http://127.0.0.1; + proxy_set_header X-Forwarded-Path /docs; proxy_hide_header Access-Control-Allow-Origin; add_header Access-Control-Allow-Origin $http_origin; } diff --git a/tagbase_server/requirements.txt b/tagbase_server/requirements.txt index 0bb3253..f06fc2f 100644 --- a/tagbase_server/requirements.txt +++ b/tagbase_server/requirements.txt @@ -1,4 +1,4 @@ -connexion[swagger-ui]==2.14.2 +connexion==2.14.2 flask[async]==2.2.5 flask-cors==4.0.0 gunicorn==21.2.0 diff --git a/tagbase_server/tagbase_server/__main__.py b/tagbase_server/tagbase_server/__main__.py index 88d19e3..cf5884d 100644 --- a/tagbase_server/tagbase_server/__main__.py +++ b/tagbase_server/tagbase_server/__main__.py @@ -30,15 +30,13 @@ logger.addHandler(rf_handler) options = { - "swagger_ui_config": { - "url": "https://raw.githubusercontent.com/tagbase/tagbase-server/main/openapi.yaml" - } + "swagger_ui": False } app = connexion.App(__name__, specification_dir="./openapi/", options=options) app.app.json_encoder = encoder.JSONEncoder app.add_api( "openapi.yaml", - arguments={"title": "tagbase-server API"}, + arguments={"title": "tagbase-server REST API"}, pythonic_params=True, strict_validation=True, )