Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

Commit db91466

Browse files
Opencdms api#32 (#34)
* update default docker-compose [docker-compose.yml] * update readme * allow /climsoft/docs and /climsoft/openapi.json without auth * climsoft fork, opencdms-process not yet installed * add opencdms process using pygeoapi * add pygeoapi link on homepage * update readme * suggest postman * refactor github actions
1 parent 2988e2f commit db91466

File tree

11 files changed

+173
-8
lines changed

11 files changed

+173
-8
lines changed

.github/workflows/ci_cd.yml renamed to .github/workflows/deploy_latest.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy on EC2
1+
name: Deploy on EC2 - Latest
22

33
on:
44
push:
@@ -11,9 +11,10 @@ jobs:
1111
- uses: actions/checkout@v2
1212
- name: Deploy in EC2
1313
env:
14-
PRIVATE_KEY: ${{secrets.AWS_PRIVATE_KEY}}
15-
HOSTNAME : ${{secrets.HOSTNAME}}
14+
PRIVATE_KEY: ${{secrets.AWS_PRIVATE_KEY_LATEST}}
15+
HOSTNAME : ${{secrets.HOSTNAME_LATEST}}
1616
USERNAME : ${{secrets.USERNAME}}
17+
HOST_FQDN: ${{secrets.LATEST_HOST_FQDN}}
1718

1819
run: |
1920
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Deploy on EC2 - Stable
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
Deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Deploy in EC2
14+
env:
15+
PRIVATE_KEY: ${{secrets.AWS_PRIVATE_KEY_STABLE}}
16+
HOSTNAME : ${{secrets.HOSTNAME_STABLE}}
17+
USERNAME : ${{secrets.USERNAME}}
18+
HOST_FQDN: ${{secrets.STABLE_HOST_FQDN}}
19+
20+
run: |
21+
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
22+
ssh -o StrictHostKeyChecking=no -i private_key ${USERNAME}@${HOSTNAME} '
23+
cd /home/ubuntu/opencdms-api
24+
git pull origin main
25+
docker-compose -f docker-compose.prod.yml build
26+
docker-compose -f docker-compose.prod.yml stop opencdms-api
27+
sleep 30
28+
docker-compose -f docker-compose.prod.yml up -d --build
29+
'

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,49 @@ To run the tests, you just need to run `docker-compose -f docker-compose.test.ym
9191

9292
Check the logs for error.
9393

94-
### How to access surface, climsoft or mch API
94+
### How to access surface, climsoft, pygeoapi or mch API
95+
96+
OpenCDMS API server is a FastAPI application. surface, climsoft, pygeoapi, mch servers are
97+
mounted to this FastAPI application. When mounting these child applications, we also have
98+
enforced an Auth Middleware. So, if you want to access the endpoints on these child applications,
99+
you have to make authenticated request.
100+
101+
To get an access token using default username and password:
102+
103+
```bash
104+
$ curl -X 'POST' \
105+
'http://localhost:5070/auth' \
106+
-H 'accept: application/json' \
107+
-H 'Content-Type: application/json' \
108+
-d '{
109+
"username": "admin",
110+
"password": "password123"
111+
}'
112+
```
113+
114+
Say, it returns
115+
116+
```bash
117+
{
118+
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTY0MzgzMDUzMiwidG9rZW5fdHlwZSI6ImFjY2VzcyIsImp0aSI6ImEzM2Q4OWMyLTNlNmEtNDJlYS04MGZjLWViZjEzNTcyZjU5MSIsInVzZXJfaWQiOjF9.dp_wPSDZwL4HAN8JWCWyGRlL0s8gRvWKASUeDPQQygY"
119+
}
120+
```
121+
122+
Now you can make request to protected endpoints using this access token as `Bearer` token.
123+
124+
Here is an example:
125+
126+
```bash
127+
$ curl -X 'GET' \
128+
'http://localhost:5070/climsoft/v1/acquisition-types/?limit=25&offset=0' \
129+
-H 'accept: application/json' \
130+
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTY0MzgzMDUzMiwidG9rZW5fdHlwZSI6ImFjY2VzcyIsImp0aSI6ImEzM2Q4OWMyLTNlNmEtNDJlYS04MGZjLWViZjEzNTcyZjU5MSIsInVzZXJfaWQiOjF9.dp_wPSDZwL4HAN8JWCWyGRlL0s8gRvWKASUeDPQQygY'
131+
```
132+
133+
which will return something like this:
134+
135+
```bash
136+
{"message":"Successfully fetched acquisition types.","status":"success","result":[]}
137+
```
138+
139+
You can use Postman to make this requests easily.

docker-compose.prod.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ services:
5252
- surfacedb
5353
- mchdb
5454
environment:
55+
- PYGEOAPI_CONFIG=/code/pygeoapi-config.yml
56+
- PYGEOAPI_OPENAPI=/code/pygeoapi-openapi.yml
5557
- PYTHONPATH=/code/surface/api
5658
- CLIMSOFT_DATABASE_URI=mysql+mysqldb://root:password@climsoftdb:3306/climsoft
5759
- CLIMSOFT_SECRET_KEY=6v(n93zuas7&k^-zcvkp5kq*3hw49t%ra0nt6!_3(0&4!
@@ -123,9 +125,10 @@ services:
123125
- MCH_API_ENABLED=true
124126
- DEFAULT_USERNAME=admin
125127
- DEFAULT_PASSWORD=password123
128+
126129
labels:
127130
- "traefik.enable=true"
128-
- "traefik.http.routers.fastapi.rule=Host(`api.opencdms.org`)"
131+
- "traefik.http.routers.fastapi.rule=Host(`$HOST_FQDN`)"
129132
- "traefik.http.routers.fastapi.tls=true"
130133
- "traefik.http.routers.fastapi.tls.certresolver=letsencrypt"
131134
command:

docker-compose.test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ services:
99
expose:
1010
- "5000"
1111
environment:
12+
- PYGEOAPI_CONFIG=/code/pygeoapi-config.yml
13+
- PYGEOAPI_OPENAPI=/code/pygeoapi-openapi.yml
1214
- PYTHONPATH=/code/surface/api
1315
- TIMESCALEDB_TELEMETRY=off
1416
- PGDATA=/var/lib/postgresql/data/pgdata
@@ -80,6 +82,7 @@ services:
8082
- MCH_API_ENABLED=true
8183
- DEFAULT_USERNAME=admin
8284
- DEFAULT_PASSWORD=password123
85+
8386
depends_on:
8487
- test_opencdms_surface_db
8588
- test_opencdms_mch_db

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ services:
1111
env_file:
1212
- .env
1313
environment:
14+
- PYGEOAPI_CONFIG=/code/pygeoapi-config.yml
15+
- PYGEOAPI_OPENAPI=/code/pygeoapi-openapi.yml
1416
- PYTHONPATH=/code/surface/api
1517
- CLIMSOFT_DATABASE_URI=mysql+mysqldb://root:password@opencdms_climsoftdb:3306/climsoft
1618
- CLIMSOFT_SECRET_KEY=climsoft-secret-key

dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ ENV PYTHONFAULTHANDLER=1 \
99
PIP_NO_CACHE_DIR=1
1010

1111
RUN apt-get update --fix-missing
12-
RUN apt-get install -y g++ libgdal-dev libpq-dev libgeos-dev libproj-dev openjdk-17-jre vim wait-for-it
12+
RUN apt-get install -y g++ libgdal-dev libpq-dev libgeos-dev libproj-dev openjdk-17-jre vim wait-for-it r-base-core libmagick++-dev
1313
RUN apt-get install -y curl git && pip install --upgrade pip
14+
RUN R -e "install.packages('magick')"
1415

1516
WORKDIR /code
1617

@@ -33,6 +34,8 @@ RUN useradd -m opencdms_api_user && chown -R opencdms_api_user /code
3334

3435
RUN ["chmod", "+x", "/code/scripts/load_initial_surface_data.sh"]
3536

37+
COPY ["pygeoapi-config.yml", "/code"]
38+
3639
USER opencdms_api_user
3740

3841
ENTRYPOINT [ "/bin/sh", "entrypoint.sh" ]

entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
python surface/api/manage.py migrate
44
python init_climsoft_db.py
55
./scripts/load_initial_surface_data.sh
6+
pygeoapi openapi generate /code/pygeoapi-config.yml >| /code/pygeoapi-openapi.yml
67
exec $@

pygeoapi-config.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
server:
2+
bind:
3+
host: 0.0.0.0
4+
port: 443
5+
url: https://${HOST_FQDN}/pygeoapi/
6+
mimetype: application/json; charset=UTF-8
7+
encoding: utf-8
8+
gzip: false
9+
languages:
10+
- en-US
11+
- fr-CA
12+
cors: true
13+
pretty_print: true
14+
limit: 10
15+
16+
map:
17+
url: https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png
18+
attribution: '<a href="https://wikimediafoundation.org/wiki/Maps_Terms_of_Use">Wikimedia maps</a> | Map data &copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
19+
manager:
20+
name: TinyDB
21+
connection: /tmp/pygeoapi-test-process-manager.db
22+
output_dir: /tmp
23+
24+
logging:
25+
level: ERROR
26+
27+
metadata:
28+
identification:
29+
title:
30+
en: pygeoapi default instance
31+
fr: instance par défaut de pygeoapi
32+
description:
33+
en: pygeoapi provides an API to geospatial data
34+
fr: pygeoapi fournit une API aux données géospatiales
35+
keywords:
36+
en:
37+
- geospatial
38+
- data
39+
- api
40+
fr:
41+
- géospatiale
42+
- données
43+
- api
44+
keywords_type: theme
45+
terms_of_service: https://creativecommons.org/licenses/by/4.0/
46+
url: http://example.org
47+
license:
48+
name: CC-BY 4.0 license
49+
url: https://creativecommons.org/licenses/by/4.0/
50+
provider:
51+
name: Organization Name
52+
url: https://pygeoapi.io
53+
contact:
54+
name: Lastname, Firstname
55+
position: Position Title
56+
address: Mailing Address
57+
city: City
58+
stateorprovince: Administrative Area
59+
postalcode: Zip or Postal Code
60+
country: Country
61+
phone: +xx-xxx-xxx-xxxx
62+
fax: +xx-xxx-xxx-xxxx
63+
email: you@example.org
64+
url: Contact URL
65+
hours: Hours of Service
66+
instructions: During hours of service. Off on weekends.
67+
role: pointOfContact
68+
69+
resources:
70+
windrose-generator:
71+
type: process
72+
processor:
73+
name: opencdms_process.process.climatol.windrose_generator.WindroseProcessor

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mch-api @ git+https://github.com/opencdms/mch-api.git@main
3333
mysqlclient
3434
numpy
3535
opencdms @ git+https://github.com/opencdms/pyopencdms.git@main
36-
climsoft_api @ git+https://github.com/faysal-ishtiaq/climsoft-api.git@package-installer
36+
climsoft_api @ git+https://github.com/opencdms/climsoft-api.git@main
3737
packaging
3838
pandas
3939
passlib
@@ -63,3 +63,5 @@ typing-extensions
6363
urllib3
6464
uvicorn
6565
Werkzeug
66+
Flask-Cors
67+
opencdms_process @ git+https://github.com/opencdms/opencdms-process.git@main

0 commit comments

Comments
 (0)