Skip to content

Commit

Permalink
Extract OAK RPC as a fully standalone service (#371)
Browse files Browse the repository at this point in the history
### Related issues

- Closes #368 

### Summary

- adds Dockerfile for the OAK RPC service image. It's based on the API
image, but changes the startup script (i.e., to just run the OAK RPC
server, not the Monarch API server) and includes a healthcheck script
for testing the service within the container
- adds a step to the `build-and-deploy-images` GH workflow to build the
new image
- removes launching and waiting on the OAK RPC server to start from the
API's startup script

### Checks

- [ ] All tests have passed (or issues created for failing tests)
  • Loading branch information
falquaddoomi authored Oct 4, 2023
1 parent 4467911 commit cf34405
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 189 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build-and-deploy-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ jobs:
image_tag: latest, ${{ steps.get-tag.outputs.IMAGE_TAG }}, ${{ github.sha }}
dockerfile: ./backend/Dockerfile

- name: Build and Push OAK RPC Server Image
uses: RafikFarhad/push-to-gcr-github-action@v5-beta
with:
gcloud_service_key: ${{ secrets.JSON_GCLOUD_SERVICE_ACCOUNT_JSON }}
registry: us-central1-docker.pkg.dev
project_id: monarch-initiative
image_name: monarch-api/monarch-oak-server
image_tag: latest, ${{ steps.get-tag.outputs.IMAGE_TAG }}, ${{ github.sha }}
dockerfile: ./services/oak_rpc_server/Dockerfile
build_args: FROM_IMAGE=monarch-api/monarch-api:${{ github.sha }}

build-and-push-frontend-image:
runs-on: ubuntu-latest
defaults:
Expand Down
6 changes: 0 additions & 6 deletions backend/start_api.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/usr/bin/bash

# before we start, run the oak server in the background...
poetry run python -m src.monarch_py.api.oak_server &

# ...but block while we wait for it to start serving request
./wait-for-it.sh -t 0 ${OAK_SERVER_HOST:-localhost}:${OAK_SERVER_PORT:-18811}

# check for uvicorn workers env var, default to 8
UVICORN_WORKERS=${UVICORN_WORKERS:-8}

Expand Down
183 changes: 0 additions & 183 deletions backend/wait-for-it.sh

This file was deleted.

23 changes: 23 additions & 0 deletions services/oak_rpc_server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This Dockerfile is used to build a supplementary image, based on
# the Monarch API image, that runs the OAK RPC server.
# Note that it takes a build argument, FROM_IMAGE, which should be the
# API image and tag that's associated with the current build.
# It assumes that the build context is the root of the repository.
# The image is built using the following command structure:
# (from the root of the repository, i.e. .../monarch-app)
# docker build \
# --build-arg="FROM_IMAGE=<API image:tag>" \
# -f services/oak_lib/Dockerfile .

ARG FROM_IMAGE
FROM ${FROM_IMAGE}

COPY ./services/oak_rpc_server/start_rpc_service.sh /var/oak_server/start_rpc_service.sh
COPY ./services/oak_rpc_server/rpc_healthcheck.py /var/oak_server/rpc_healthcheck.py

HEALTHCHECK \
--interval=30s --timeout=15s --retries=3 \
--start-period=120s \
CMD poetry run python /var/oak_server/rpc_healthcheck.py || exit 1

CMD /var/oak_server/start_rpc_service.sh
19 changes: 19 additions & 0 deletions services/oak_rpc_server/rpc_healthcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python

from monarch_py.api.config import OakRPCMarshaller

def main():
try:
oak = OakRPCMarshaller()

# run the 'warmup' query from init_semsim()
# note, this is roughly equivalent to
# /v3/api/semsim/compare/MP%3A0010771/HP%3A0004325
oak.compare( subjects=["MP:0010771"], objects=["HP:0004325"])

except Exception as ex:
print(ex)
exit(1)

if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions services/oak_rpc_server/start_rpc_service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

poetry run python -m src.monarch_py.api.oak_server

0 comments on commit cf34405

Please sign in to comment.