Skip to content

Commit 981d40e

Browse files
authored
Merge pull request #10 from KnowWhereGraph/develop
Release 1.0.0
2 parents a6a2ce5 + a293219 commit 981d40e

13 files changed

Lines changed: 56 additions & 25 deletions

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
__pycache__/
22
.idea/
33
.DS_STORE
4-
docs/

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.10
22

3-
WORKDIR ./kwg-api/
3+
WORKDIR /app
44

55
RUN pip install poetry
66
RUN poetry config virtualenvs.create false
@@ -9,5 +9,6 @@ RUN poetry config virtualenvs.create false
99
COPY poetry.lock pyproject.toml README.md ./
1010
# Use no-root because the root code folder hasn't been added yet
1111
RUN poetry install --no-root --without dev
12-
COPY kwg_api/ kwg_api/
12+
COPY . .
13+
1314
CMD ["poetry", "run", "uvicorn", "kwg_api.main:app", "--host", "0.0.0.0", "--port", "8080"]

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
API service for KnowWhereGraph
44

5+
## Running
6+
7+
The API service is meant to be run under full stack operating conditions. There are several flavors of the API, which correspond to different docker-compose files.
8+
9+
1. local: Uses a local GraphDB deployment
10+
2. stage: Uses the staging GraphDB deployment
11+
3. prod: Uses the production GraphDB deployment
12+
13+
### Outside of the Stack
14+
15+
To run the API in a production setting, outside the full stack, deploy with docker using
16+
17+
```bash
18+
docker-compose -f docker-compose.dev.yaml up
19+
```
20+
21+
This avoids the inclusion of the service in the `kwg_netowrk`, which is used when doing a full stack deployment.
22+
23+
Visit the redoc page at http://localhost/redoc
24+
25+
Visit the swagger page at http://localhost/docs
26+
27+
Test the redirection with http://localhost/lod/resource/hazard.1183609.5434007
28+
29+
530
## Features
631

732
- Node de-referencing

docker-compose.dev.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ services:
44
kwg-api:
55
container_name: kwg-api
66
build:
7-
context: .
7+
context: ./kwg-api/
88
dockerfile: Dockerfile
9+
image: kwg-api
910
ports:
10-
- '8080:8080'
11+
- '80:8080'
1112
environment:
12-
- base_address_http=http://staging.knowwheregraph.org
13-
- base_address_https=https://staging.knowwheregraph.org
13+
- base_address_http=https://stko-kwg.geog.ucsb.edu
14+
- base_address_https=https://stko-kwg.geog.ucsb.edu

docker-compose.local.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ services:
66
build:
77
context: ./kwg-api/
88
dockerfile: Dockerfile
9+
image: kwg-api
910
ports:
1011
- '8080:8080'
1112
environment:
12-
- base_address_http=http://staging.knowwheregraph.org
13-
- base_address_https=https://staging.knowwheregraph.org
13+
- base_address_http=http://localhost
14+
- base_address_https=https://localhost
15+
- base_browse_address=https://staging.knowwheregraph.org/browse
1416
networks:
15-
- kwg_network
17+
- kwg_network

docker-compose.prod.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ services:
66
build:
77
context: ./kwg-api/
88
dockerfile: Dockerfile
9+
image: kwg-api
910
ports:
1011
- '8080:8080'
1112
environment:
12-
- base_address_http=http://stko-kwg.geog.ucsb.edu
13-
- base_address_https=https://stko-kwg.geog.ucsb.edu
13+
- base_address_http=http://kwg-api:8080
14+
- base_address_https=https://kwg-api:8080
15+
- base_browse_address=https://stko-kwg.geog.ucsb.edu/browse
1416
networks:
15-
- kwg_network
17+
- kwg_network

docker-compose.stage.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ services:
66
build:
77
context: ./kwg-api/
88
dockerfile: Dockerfile
9+
image: kwg-api
910
ports:
1011
- '8080:8080'
1112
environment:
12-
- base_address_http=http://staging.knowwheregraph.org
13-
- base_address_https=https://staging.knowwheregraph.org
13+
- base_address_http=http://kwg-api:8080
14+
- base_address_https=https://kwg-api:8080
15+
- base_browse_address=https://staging.knowwheregraph.org/browse
1416
networks:
15-
- kwg_network
17+
- kwg_network

docs/content-negotiation.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Content Negotiation
22
===================
3-
One of the Linked Data principles is that data should be retrievable in different formats, depending on
4-
the 'Accept' header, known as Content Negotiation.
3+
One of the Linked Data principles is that data should be retrievable in different formats, depending on the 'Accept' header, known as Content Negotiation.
54

65
KnowWhereGraphs supports content negotiation for graph nodes through the API.
76

kwg_api/api/node_negotiator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ def _redirect_browse(self) -> RedirectResponse:
7575
7676
:return: A response signaling a redirect to a URL
7777
"""
78-
browse_url = f"{self.base_address_https}/browse/"
7978
resource_id_shortened = PrefixBuilder.resolve_prefix(
8079
self.request_url, self.resource_id
8180
)
8281
if not resource_id_shortened:
8382
resource_id_shortened = self.resource_id
84-
print(self.base_address_https)
85-
return RedirectResponse(url=f"{browse_url}#{resource_id_shortened}")
83+
return RedirectResponse(url=f"{self.base_browse_address}#{resource_id_shortened}")

kwg_api/lib/content_negotiator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, request: Request, resource_id: str):
1818
"""
1919
self.base_address_http = os.getenv("base_address_http")
2020
self.base_address_https = os.getenv("base_address_https")
21+
self.base_browse_address = os.getenv("base_browse_address")
2122
accept_header = request.headers.get("accept")
2223
if not accept_header:
2324
raise ValueError("Failed to read the request headers")

0 commit comments

Comments
 (0)