Skip to content

Commit

Permalink
feat: add deployed_version endpoint (#588)
Browse files Browse the repository at this point in the history
* feat: add deployed_version endpoint
  • Loading branch information
ebezzi authored May 16, 2023
1 parent 2540fd9 commit 64b4979
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/deploy-happy-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ jobs:
else
echo "DEPLOYMENT_STAGE=dev" >> $GITHUB_ENV
fi
- name: Setup envfile
run: |
echo "HAPPY_COMMIT=$(git rev-parse --verify HEAD)" >> envfile
- name: Update deployment
uses: chanzuckerberg/github-actions/.github/actions/[email protected]
with:
tfe-token: ${{ secrets.TFE_TOKEN }}
stack-name: explorer-${{ env.DEPLOYMENT_STAGE }}stack
create-tag: "true"
env: ${{ env.DEPLOYMENT_STAGE }}
env-file: envfile
happy_version: "0.59.0"
4 changes: 4 additions & 0 deletions hosted/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ ADD hosted/start.sh start.sh
RUN chmod +x /start.sh
ENV CXG_CONFIG_FILE=/config.yaml

ARG HAPPY_COMMIT=""
LABEL commit=${HAPPY_COMMIT}
ENV COMMIT_SHA=${HAPPY_COMMIT}

CMD ["/start.sh"]
7 changes: 7 additions & 0 deletions server/app/api/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def get(self, data_adaptor):
return common_rest.gene_info_get(request)


class VersionAPI(Resource):
def get(self):
return common_rest.get_deployed_version(request)


def rest_get_dataset_explorer_location_data_adaptor(func):
@wraps(func)
def wrapped_function(self, dataset=None):
Expand Down Expand Up @@ -229,6 +234,8 @@ def register_api_v3(app, app_config, api_url_prefix):
s3uri_resources = get_api_s3uri_resources(bp_s3uri, s3uri_api_path)
app.register_blueprint(s3uri_resources.blueprint)

Api(app).add_resource(VersionAPI, "/deployed_version")

# NOTE: These routes only allow the dataset to be in the directory
# of the dataroot, and not a subdirectory. We may want to change
# the route format at some point
Expand Down
9 changes: 9 additions & 0 deletions server/common/rest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import hashlib
import logging
import os
import struct
import sys
import zlib
Expand Down Expand Up @@ -256,6 +257,14 @@ def gene_info_get(request):
return abort_and_log(HTTPStatus.BAD_REQUEST, str(e), include_exc_info=True)


def get_deployed_version(request):
"""
Returns the deployed version
"""
version_info = {"Explorer": os.getenv("COMMIT_SHA")}
return make_response(jsonify(version_info), 200)


def diffexp_obs_post(request, data_adaptor):
if not data_adaptor.app_config.default_dataset__diffexp__enable:
return abort(HTTPStatus.NOT_IMPLEMENTED)
Expand Down
37 changes: 37 additions & 0 deletions server/tests/unit/common/apis/test_api_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from http import HTTPStatus
from unittest.mock import patch
from urllib.parse import quote
import os


import numpy as np
import requests
Expand Down Expand Up @@ -993,6 +995,41 @@ def test_tombstoned_datasets_redirect_to_data_portal(self, mock_get):
) # noqa E501


class TestDeployedVersion(BaseTest):
@classmethod
def setUpClass(cls):
cls.data_locator_api_base = "api.cellxgene.staging.single-cell.czi.technology/dp/v1"
cls.app__web_base_url = "https://cellxgene.staging.single-cell.czi.technology/"
cls.config = AppConfig()
cls.config.update_server_config(
data_locator__api_base=cls.data_locator_api_base,
app__web_base_url=cls.app__web_base_url,
multi_dataset__dataroots={"e": {"base_url": "e", "dataroot": FIXTURES_ROOT}},
app__flask_secret_key="testing",
app__debug=True,
data_locator__s3_region_name="us-east-1",
)
super().setUpClass(cls.config)

cls.app.testing = True
cls.client = cls.app.test_client()

endpoint = "s3_uri"
test_dataset_url_base = "/e/pbmc3k_v0.cxg"
test_url_base = f"{test_dataset_url_base}/api/v0.3/"

cls.url = f"{test_url_base}{endpoint}"

def test_get_deployed_version(self):
os.environ["COMMIT_SHA"] = "123"
endpoint = "deployed_version"
url = f"/{endpoint}"
result = self.client.get(url)
self.assertEqual(result.status_code, 200)
self.assertEqual(json.loads(result.data), {"Explorer": "123"})
del os.environ["COMMIT_SHA"]


class MockResponse:
def __init__(self, body, status_code, ok=True):
self.content = body
Expand Down

0 comments on commit 64b4979

Please sign in to comment.