From 1bb08e7bfd2b74ada273294e4f1f410f63984263 Mon Sep 17 00:00:00 2001 From: Xiao Gui Date: Thu, 6 Jun 2024 12:33:37 +0200 Subject: [PATCH] add redirect debug --- .github/workflows/dockerimgs.yml | 22 +++------------------- .gitignore | 1 + http_wrapper/conf/siibra_jugex_conf.py | 9 +++++++++ http_wrapper/routes/git.py | 22 ++++++++++++++++++++++ http_wrapper/routes/notebook.py | 14 ++++++++------ http_wrapper/scheduling/worker.py | 3 +-- http_wrapper/server.py | 8 +++++--- 7 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 http_wrapper/conf/siibra_jugex_conf.py create mode 100644 http_wrapper/routes/git.py diff --git a/.github/workflows/dockerimgs.yml b/.github/workflows/dockerimgs.yml index 289d70b..c9332f9 100644 --- a/.github/workflows/dockerimgs.yml +++ b/.github/workflows/dockerimgs.yml @@ -82,25 +82,9 @@ jobs: echo "Done" - deploy-on-okd: + deploy-on-ebrains: runs-on: ubuntu-latest needs: build-docker-img steps: - - name: 'Trigger deploy' - run: | - if [ ! -z "${{ secrets.EBRAINS_OKD_PRODCSCS_ENDPOINT }}" ] - then - if [ ! -z "${{ secrets.EBRAINS_OKD_PRODCSCS_SIIBRATOOLBOX_TOKEN }}" ] - then - oc login ${{ secrets.EBRAINS_OKD_PRODCSCS_ENDPOINT }} --token=${{ secrets.EBRAINS_OKD_PRODCSCS_SIIBRATOOLBOX_TOKEN }} - oc project ${{ secrets.EBRAINS_OKD_PRODCSCS_SIIBRATOOLBOX_NSP }} - for dc in $(oc get dc -l app=siibra-toolbox-deploy-siibra-toolbox-jugex | awk '{print $1}' | tail -n +2) - do - oc rollout latest dc/$dc - done - else - echo "secrets.EBRAINS_OKD_PRODCSCS_SIIBRATOOLBOX_TOKEN not set, skipping ..." - fi - else - echo "secrets.EBRAINS_OKD_PRODCSCS_ENDPOINT not set, skipping..." - fi \ No newline at end of file + - name: "skip for now" + run: "echo skip for now" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0fa9d0d..ef8c7be 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ upload_to_pypi.sh venv .vscode .env +secret* diff --git a/http_wrapper/conf/siibra_jugex_conf.py b/http_wrapper/conf/siibra_jugex_conf.py new file mode 100644 index 0000000..523870e --- /dev/null +++ b/http_wrapper/conf/siibra_jugex_conf.py @@ -0,0 +1,9 @@ +import os + +SIIBRA_TOOLBOX_VIEWER_PLUGIN_STATIC_DIR = os.getenv("SIIBRA_TOOLBOX_VIEWER_PLUGIN_STATIC_DIR") + +HBP_GITLAB_HOST = os.getenv("HBP_GITLAB_HOST") +HBP_GITLAB_TOKEN = os.getenv("HBP_GITLAB_TOKEN") +HBP_GITLAB_PROJECT_ID = os.getenv("HBP_GITLAB_PROJECT_ID") + +CHANNEL = os.getenv("SIIBRA_JURGEX_CELERY_CHANNEL", "siibra_jugex_http") \ No newline at end of file diff --git a/http_wrapper/routes/git.py b/http_wrapper/routes/git.py new file mode 100644 index 0000000..c44a8bb --- /dev/null +++ b/http_wrapper/routes/git.py @@ -0,0 +1,22 @@ +from fastapi import APIRouter, Request +from fastapi.responses import PlainTextResponse +from fastapi.exceptions import HTTPException + +router = APIRouter() + +# @router.get("/{repo}.git/info/refs") +# def info_refs(): +# return PlainTextResponse( +# """db53a06240ccf01b51eefa3ee348a12e360db2bd\trefs/heads/master""" +# ) + +# @router.get("/{repo}.git/HEAD") +# def head(): +# return PlainTextResponse( +# """ref: refs/heads/master\n""" +# ) + +# @router.get("/objects/{head}/{rest}") +# def get_obj(): +# print("foo") +# raise HTTPException(404) \ No newline at end of file diff --git a/http_wrapper/routes/notebook.py b/http_wrapper/routes/notebook.py index f6b9307..af5f4a3 100644 --- a/http_wrapper/routes/notebook.py +++ b/http_wrapper/routes/notebook.py @@ -9,12 +9,11 @@ from uuid import uuid4 from urllib.parse import quote, quote_plus from http_wrapper.routes.common import PostReqModel, common_params, reverse_param +from http_wrapper.conf.siibra_jugex_conf import HBP_GITLAB_HOST, HBP_GITLAB_TOKEN, HBP_GITLAB_PROJECT_ID -HBP_GITLAB_HOST = os.getenv("HBP_GITLAB_HOST") -HBP_GITLAB_TOKEN = os.getenv("HBP_GITLAB_TOKEN") -HBP_GITLAB_PROJECT_ID = os.getenv("HBP_GITLAB_PROJECT_ID") - -run_now_enabled = HBP_GITLAB_HOST is not None and HBP_GITLAB_TOKEN is not None and HBP_GITLAB_PROJECT_ID is not None +run_now_enabled = (HBP_GITLAB_HOST is not None + and HBP_GITLAB_TOKEN is not None + and HBP_GITLAB_PROJECT_ID is not None) class NotebookExecutionSite(Enum): EBRAINS_LAB="EBRAINS_LAB" @@ -144,7 +143,10 @@ def delete_branch(branch: str): gl = Gitlab(url=HBP_GITLAB_HOST, private_token=HBP_GITLAB_TOKEN) project = gl.projects.get(HBP_GITLAB_PROJECT_ID) project.branches.delete(branch) - + + @router.get("/redirect") + def redirect(): + return RedirectResponse("https://lab.ebrains.eu/") @router.get("/run", tags=TAGS) def run_notebook(background_tasks: BackgroundTasks, site: NotebookExecutionSite, post_req:PostReqModel = Depends(common_params)): diff --git a/http_wrapper/scheduling/worker.py b/http_wrapper/scheduling/worker.py index 38d151b..38d645f 100644 --- a/http_wrapper/scheduling/worker.py +++ b/http_wrapper/scheduling/worker.py @@ -1,8 +1,7 @@ from typing import List import os import logging - -CHANNEL = os.getenv("SIIBRA_JURGEX_CELERY_CHANNEL", "siibra_jugex_http") +from http_wrapper.conf.siibra_jugex_conf import CHANNEL logger = logging.getLogger(__name__) diff --git a/http_wrapper/server.py b/http_wrapper/server.py index 8147b2f..eb47ae7 100644 --- a/http_wrapper/server.py +++ b/http_wrapper/server.py @@ -1,11 +1,12 @@ from http_wrapper.routes.analysis import router as analysis_router from http_wrapper.routes.notebook import router as notebook_router +from http_wrapper.routes.git import router as git_router from http_wrapper.jugex_logger import access_logger +from http_wrapper.conf.siibra_jugex_conf import SIIBRA_TOOLBOX_VIEWER_PLUGIN_STATIC_DIR from fastapi import FastAPI, Request from fastapi.staticfiles import StaticFiles from fastapi.middleware.cors import CORSMiddleware -from os import getenv import time app = FastAPI() @@ -39,9 +40,10 @@ async def access_log(request: Request, call_next): app.include_router(analysis_router, prefix="/analysis") app.include_router(notebook_router, prefix="/notebook") +app.include_router(git_router, prefix="/git") -if getenv("SIIBRA_TOOLBOX_VIEWER_PLUGIN_STATIC_DIR"): - path_to_viewer_plugin = getenv("SIIBRA_TOOLBOX_VIEWER_PLUGIN_STATIC_DIR") +if SIIBRA_TOOLBOX_VIEWER_PLUGIN_STATIC_DIR: + path_to_viewer_plugin = SIIBRA_TOOLBOX_VIEWER_PLUGIN_STATIC_DIR app.mount('/viewer_plugin', StaticFiles(directory=path_to_viewer_plugin)) from threading import Event