Skip to content

Commit fea189c

Browse files
committed
fix hardcoded localhost:5000
1 parent 181efda commit fea189c

File tree

4 files changed

+110
-6
lines changed

4 files changed

+110
-6
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,65 @@ This repository contains a minimal Docker Compose setup for running
55
[MapLibre](https://maplibre.org/) and [Chart.js](https://www.chartjs.org/).
66

77
## Prerequisites
8+
89
- Docker Desktop with Docker Compose v2+
910
- (Optional) GDAL >= 3.0 for converting data to other formats
1011

1112
## Usage
13+
1214
1. Build and start the services:
1315
```bash
1416
docker compose up --build
1517
```
1618
2. Access pygeoapi at [http://localhost:5000](http://localhost:5000)
1719
3. Access the frontend at [http://localhost:8080](http://localhost:8080)
1820

21+
## Deployment
22+
23+
### Environment Variables
24+
25+
When deploying pygeoapi in different environments (local, Kubernetes, etc.), the following environment variables should be set:
26+
27+
- `PYGEOAPI_SERVER_URL`: The external URL where pygeoapi will be accessible. This is used to generate correct links in the API responses.
28+
- For local development: `http://localhost:5000`
29+
- For Kubernetes/production: Your domain, e.g., `https://your-domain.com`
30+
31+
### Kubernetes Deployment
32+
33+
To deploy to Kubernetes:
34+
35+
1. Edit the `k8s-pygeoapi.yaml` file to set the correct `PYGEOAPI_SERVER_URL` for your environment
36+
2. Apply the Kubernetes configuration:
37+
```bash
38+
kubectl apply -f k8s-pygeoapi.yaml
39+
```
40+
41+
The Kubernetes deployment includes:
42+
43+
- A Deployment for pygeoapi
44+
- A Service to expose pygeoapi within the cluster
45+
- An Ingress resource (optional) to expose pygeoapi externally
46+
1947
The backend Docker image now generates the OpenAPI document at build
2048
time and exposes it via the `PYGEOAPI_OPENAPI` environment variable.
2149

2250
The frontend fetches features from pygeoapi and displays them on a
2351
MapLibre map and Chart.js chart.
2452

2553
## Data
54+
2655
The sample dataset resides in `data/norway/norway-hazard-points.geojson`. You can replace
2756
this file with your own dataset. Update `pygeoapi-config.yml`
2857
if you change the path or dataset name.
2958

3059
## Development
60+
3161
This repository uses **Black**, **isort**, and **Ruff** for Python code. The frontend is formatted with **Prettier**. Recommended VS Code settings are provided in the `.vscode` folder.
3262
Run `pip install -r requirements-dev.txt` to install Python tooling. Frontend formatting tools can be installed by running `npm install` inside the `frontend` directory.
3363
Use `npm run format` to format frontend code.
3464

3565
## CI/CD
66+
3667
A GitHub Actions workflow builds and publishes the frontend Docker image whenever
3768
changes are pushed to the `frontend/` directory on the `main` branch. The image
3869
is pushed to the GitHub Container Registry under the tag

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
- CONTAINER_NAME=pygeoapi
1414
- CONTAINER_HOST=0.0.0.0
1515
- CONTAINER_PORT=5000
16+
- PYGEOAPI_SERVER_URL=${PYGEOAPI_SERVER_URL:-http://localhost:5000}
1617

1718
frontend:
1819
image: ${FRONTEND_IMAGE:-ghcr.io/yejiyang/global-tsunami-risk-map-frontend:latest}
@@ -37,6 +38,7 @@ services:
3738
- CONTAINER_NAME=pygeoapi
3839
- CONTAINER_HOST=0.0.0.0
3940
- CONTAINER_PORT=5000
41+
- PYGEOAPI_SERVER_URL=http://localhost:5000
4042
profiles:
4143
- local
4244

k8s-pygeoapi.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: pygeoapi
5+
labels:
6+
app: pygeoapi
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: pygeoapi
12+
template:
13+
metadata:
14+
labels:
15+
app: pygeoapi
16+
spec:
17+
containers:
18+
- name: pygeoapi
19+
image: ghcr.io/yejiyang/pygeoapi-w-global-tsunami-data:latest
20+
ports:
21+
- containerPort: 5000
22+
env:
23+
- name: PYGEOAPI_CONFIG
24+
value: /pygeoapi/local.config.yml
25+
- name: PYGEOAPI_OPENAPI
26+
value: /tmp/openapi.yml
27+
- name: CONTAINER_NAME
28+
value: pygeoapi
29+
- name: CONTAINER_HOST
30+
value: 0.0.0.0
31+
- name: CONTAINER_PORT
32+
value: "5000"
33+
- name: PYGEOAPI_SERVER_URL
34+
# The URL that users will access your service through - adjust based on your Kubernetes setup
35+
# This could be your ingress URL or load balancer address
36+
value: "https://your-domain.com" # Replace with your actual domain
37+
---
38+
apiVersion: v1
39+
kind: Service
40+
metadata:
41+
name: pygeoapi
42+
spec:
43+
selector:
44+
app: pygeoapi
45+
ports:
46+
- port: 80
47+
targetPort: 5000
48+
type: ClusterIP
49+
---
50+
# Optional: If you're using an Ingress controller
51+
apiVersion: networking.k8s.io/v1
52+
kind: Ingress
53+
metadata:
54+
name: pygeoapi-ingress
55+
annotations:
56+
# Add appropriate annotations for your ingress controller
57+
# For example, for nginx:
58+
# kubernetes.io/ingress.class: nginx
59+
# nginx.ingress.kubernetes.io/rewrite-target: /
60+
spec:
61+
rules:
62+
- host: your-domain.com # Replace with your actual domain
63+
http:
64+
paths:
65+
- path: /
66+
pathType: Prefix
67+
backend:
68+
service:
69+
name: pygeoapi
70+
port:
71+
number: 80

pygeoapi/pygeoapi-config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ server:
22
bind:
33
host: 0.0.0.0
44
port: 5000
5-
url: http://localhost:5000/
5+
url: ${PYGEOAPI_SERVER_URL:-http://localhost:5000/}
66
mimetype: application/json; charset=UTF-8
77
encoding: utf-8
88
language: en-US
@@ -29,13 +29,13 @@ metadata:
2929
- api
3030
keywords_type: theme
3131
terms_of_service: https://creativecommons.org/licenses/by/4.0/
32-
url: http://localhost:5000
32+
url: ${PYGEOAPI_SERVER_URL:-http://localhost:5000}
3333
license:
3434
name: CC-BY 4.0 license
3535
url: https://creativecommons.org/licenses/by/4.0/
3636
provider:
3737
name: Organization Name
38-
url: http://localhost:5000
38+
url: ${PYGEOAPI_SERVER_URL:-http://localhost:5000}
3939
contact:
4040
name: Admin
4141
position: Admin
@@ -54,7 +54,7 @@ resources:
5454
- type: application/geo+json
5555
rel: items
5656
title: Norway Hazard Points (GeoJSON)
57-
href: http://localhost:5000/collections/points/items
57+
href: "${PYGEOAPI_SERVER_URL:-http://localhost:5000}/collections/points/items"
5858
extents:
5959
spatial:
6060
bbox: [3, 56, 32, 72] # Norway with 100km buffer
@@ -90,11 +90,11 @@ resources:
9090
- type: application/geo+json
9191
rel: items
9292
title: Global Hazard Points (GeoJSON)
93-
href: http://localhost:5000/collections/hazardglobal/items
93+
href: "${PYGEOAPI_SERVER_URL:-http://localhost:5000}/collections/hazardglobal/items"
9494
- type: application/vnd.mapbox-vector-tile
9595
rel: tiles
9696
title: Global Hazard Points (Vector Tiles)
97-
href: http://localhost:5000/collections/hazardglobal/tiles
97+
href: "${PYGEOAPI_SERVER_URL:-http://localhost:5000}/collections/hazardglobal/tiles"
9898
extents:
9999
spatial:
100100
bbox: [-180, -90, 180, 90]

0 commit comments

Comments
 (0)