diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 906a403..90f2f4a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,7 +10,8 @@ jobs: steps: - name: Check out code uses: actions/checkout@v2 - + with: + ref: ${{ github.ref }} - name: Login to Quay.io uses: docker/login-action@v2 with: @@ -21,13 +22,14 @@ jobs: - name: Build and push image run: | # Set Image tag to the branch name + RAW_BRANCH_NAME=$(echo ${GITHUB_REF#refs/*/}) BRANCH=$(echo ${GITHUB_REF#refs/*/} | tr / _) REPO=quay.io/ohsu-comp-bio/gen3-image-viewer echo "Setting image tag to $REPO:$BRANCH" # Login to Quay.io and build image docker login quay.io - docker build -t $REPO:$BRANCH . + docker build -t $REPO:$BRANCH --build-arg BRANCH=$RAW_BRANCH_NAME . # Add 'latest' tag to 'main' image if [[ $BRANCH == 'main' ]]; then diff --git a/Dockerfile b/Dockerfile index 23a3ff6..1de2a3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM python:3.12 - +ARG BRANCH=development WORKDIR /app ADD "https://api.github.com/repos/ACED-IDP/image_viewer/commits?per_page=1" latest_commit -RUN git clone https://github.com/ACED-IDP/image_viewer +# Clone the specific branch +RUN git clone --branch $BRANCH https://github.com/ACED-IDP/image_viewer.git + WORKDIR /app/image_viewer -RUN git checkout development + RUN pip install --no-cache-dir . RUN git log --oneline CMD ["uvicorn", "image_viewer.app:app", "--reload"] diff --git a/image_viewer/__init__.py b/image_viewer/__init__.py index e69de29..0e19899 100644 --- a/image_viewer/__init__.py +++ b/image_viewer/__init__.py @@ -0,0 +1,18 @@ +import indexclient.client + + +def monkey_patch_indexclient__get(): + """Monkey patch IndexClient._get to ensure 'auth' is set and log calls.""" + original__get = indexclient.client.IndexClient._get + + def patched__get(self, *args, **kwargs): + """Patch to ensure 'auth' is set and log the call.""" + if 'auth' not in kwargs: + kwargs['auth'] = self.auth + return original__get(self, *args, **kwargs) + + indexclient.client.IndexClient._get = patched__get + + +# main +monkey_patch_indexclient__get() diff --git a/image_viewer/app.py b/image_viewer/app.py index 4f05940..6c8fb89 100644 --- a/image_viewer/app.py +++ b/image_viewer/app.py @@ -48,22 +48,17 @@ async def view_object(object_id: str, authorization: str = Header(None), access_ token = None - logger.error("in view object") - if authorization and authorization.startswith("Bearer "): token = authorization.split(" ")[1] # Extract token from "Bearer " elif access_token: token = access_token - logger.error(f"in view object token {token}") # If no token is found, raise a 404 Not Found error if not token: raise HTTPException(status_code=404, detail="Token not found") try: - logger.error(f"in view object {object_id} {settings.base_url}") redirect_url = aviator_url(object_id, token, settings.base_url) - logger.error(f"in view object {redirect_url}") return RedirectResponse(url=redirect_url) except HTTPException as e: