Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

228 redeploy api #255

Merged
merged 26 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d696e7a
rename initial configs
lukehare May 4, 2023
4114c62
Merge branch 'dev' into 228-redeploy-api
lukehare May 16, 2023
0cc2deb
Add script to run app locally
lukehare May 16, 2023
92b4fa4
Add new configuration and update script to run app locally
lukehare May 16, 2023
32b6eec
Remove v1 API config files
lukehare May 23, 2023
aab9123
Add new docker-compose configuration for deployment of API v2
lukehare May 23, 2023
94d5dc1
Set traefik Host via env variable
lukehare May 23, 2023
1d9b02d
Add initial API tests
lukehare May 23, 2023
40b8c71
Add ner endpoint and test
lukehare May 23, 2023
9b17bb9
Specify torch version
lukehare May 23, 2023
9d9921e
Skip app integration tests
lukehare May 25, 2023
52aff88
Add patch version to torch
lukehare May 30, 2023
99897a6
Add initial continuous deployment workflow
lukehare May 30, 2023
372edd4
Merge pull request #250 from Living-with-machines/lh/test_cd
lukehare May 30, 2023
4b78cc7
Test run workflow on merge
lukehare May 30, 2023
711242d
Merge pull request #251 from Living-with-machines/lh/test_cd
lukehare May 30, 2023
35f04e2
Fix typo
lukehare May 30, 2023
cf44487
Update NER endpoint
lukehare Jun 6, 2023
820c2db
Add resolve_full_text endpoint
lukehare Jun 6, 2023
dbcbe19
Add candidate selection endpoint
lukehare Jun 6, 2023
969baa9
Add CandidatesAPIQuery model
lukehare Jun 9, 2023
8d6d2d4
Fix NER typo. Use NER utils.
lukehare Jun 9, 2023
59642ca
Merge branch 'dev' into 228-redeploy-api
lukehare Jul 27, 2023
495d00f
Use latest pipeline methods in API. Add disambiguation endpoint.
lukehare Jul 27, 2023
a55dff2
Change endpoint names. Update deployed config.
lukehare Jul 28, 2023
cb77a7e
Minor clean-up of pipeline config
lukehare Jul 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Continuous deployment

on:
pull_request:
types:
- closed
branches:
- 228-redeploy-api

jobs:

docker-deploy-api:
name: build and deploy api docker container
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: execute build and deploy commands on azure vm via ssh
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
key: ${{ secrets.DEPLOY_PK }}
username: ${{ secrets.USER }}
script: |
cd toponym-resolution
export CONTAINER_NAME=t-res_deezy_reldisamb-wpubl-wmtops
sudo -E docker-compose down --remove-orphans
sudo -E docker rmi $(sudo docker images --filter=reference='*:latest' --format {{.ID}})
sudo -E docker build -f app/template.Dockerfile --no-cache --build-arg APP_NAME=${CONTAINER_NAME} -t ${CONTAINER_NAME}_image .
HOST_URL=${{ secrets.HOST }} sudo -E docker-compose up -d
74 changes: 58 additions & 16 deletions app/app_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import time
from pathlib import Path
from typing import Union
from typing import Union, Optional, List

import uvicorn
from fastapi import FastAPI, Request
Expand All @@ -25,9 +25,20 @@


class APIQuery(BaseModel):
sentence: str
place: Union[str, None] = None
place_wqid: Union[str, None] = None
text: str
place: Optional[Union[str, None]] = None
place_wqid: Optional[Union[str, None]] = None


class CandidatesAPIQuery(BaseModel):
toponyms: List[dict]


class DisambiguationAPIQuery(BaseModel):
dataset: List[dict]
wk_cands: dict
place: Optional[Union[str, None]] = None
place_wqid: Optional[Union[str, None]] = None


app_config_name = os.environ["APP_CONFIG_NAME"]
Expand All @@ -36,15 +47,7 @@ class APIQuery(BaseModel):

@app.get("/")
async def read_root(request: Request):
return {
"Title": request.app.title,
"request.url": request.url,
"request.query_params": request.query_params,
"root_path": request.scope.get("root_path"),
"request.client": request.client,
"hostname": os.uname()[1],
"worker_id": os.getpid(),
}
return {"Welcome to T-Res!": request.app.title}


@app.get("/test")
Expand All @@ -58,17 +61,56 @@ async def test_pipeline():
return resolved


@app.get("/toponym_resolution")
async def run_pipeline(api_query: APIQuery, request_id: Union[str, None] = None):
@app.get("/resolve_sentence")
async def run_sentence(api_query: APIQuery, request_id: Union[str, None] = None):
place = "" if api_query.place is None else api_query.place
place_wqid = "" if api_query.place_wqid is None else api_query.place_wqid
resolved = geoparser.run_sentence(
api_query.sentence, place=api_query.place, place_wqid=api_query.place_wqid
api_query.text, place=place, place_wqid=place_wqid
)

return resolved


@app.get("/resolve_full_text")
async def run_text(api_query: APIQuery):

place = "" if api_query.place is None else api_query.place
place_wqid = "" if api_query.place_wqid is None else api_query.place_wqid
resolved = geoparser.run_text(api_query.text, place=place, place_wqid=place_wqid)

return resolved


@app.get("/run_ner")
async def run_ner(api_query: APIQuery):

place = "" if api_query.place is None else api_query.place
place_wqid = "" if api_query.place_wqid is None else api_query.place_wqid
ner_output = geoparser.run_text_recognition(
api_query.text, place=place, place_wqid=place_wqid
)

return ner_output


@app.get("/run_candidate_selection")
async def run_candidate_selection(cand_api_query: CandidatesAPIQuery):

wk_cands = geoparser.run_candidate_selection(cand_api_query.toponyms)
return wk_cands


@app.get("/run_disambiguation")
async def run_disambiguation(api_query: DisambiguationAPIQuery):
place = "" if api_query.place is None else api_query.place
place_wqid = "" if api_query.place_wqid is None else api_query.place_wqid
disamb_output = geoparser.run_disambiguation(
api_query.dataset, api_query.wk_cands, place, place_wqid
)
return disamb_output


@app.get("/health")
async def healthcheck():
return {"status": "ok"}
Expand Down
54 changes: 0 additions & 54 deletions app/configs/deezy_mostpopular.py

This file was deleted.

58 changes: 0 additions & 58 deletions app/configs/deezy_relwithoutpubl.py

This file was deleted.

58 changes: 0 additions & 58 deletions app/configs/deezy_relwithpubl.py

This file was deleted.

23 changes: 0 additions & 23 deletions app/configs/perfect_mostpopular.py

This file was deleted.

Loading
Loading