Skip to content

Commit f6423a4

Browse files
committed
Register deployments automatically with DRGON
1 parent 7976905 commit f6423a4

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from task_logger import log
2+
import bs4 as bs
3+
import os
4+
import requests
5+
6+
def register_with_drgon():
7+
host = os.environ["DRGON_HOST"]
8+
api_key = os.environ["DRGON_API_KEY"]
9+
10+
if host == "" or api_key == "":
11+
log("Host or API key not found, can't register this deployment with DRGON.")
12+
return 0
13+
14+
res = requests.get("http://geocml-server/cgi-bin/qgis_mapserv.fcgi?SERVICE=WFS&VERSION=1.3.0&REQUEST=GetCapabilities")
15+
xml = bs.BeautifulSoup(res.text, "html.parser")
16+
abstract = xml.find("ows:abstract", text=lambda text: isinstance(text, bs.CData)).string.strip()
17+
title = xml.find("ows:title").text
18+
url = "https://google.com" # TODO: make this dynamic
19+
owner = xml.find("ows:individualname").text
20+
keywords = xml.find("ows:keywords").find_all("ows:keyword")
21+
tags = ""
22+
for keyword in keywords:
23+
tags += f"{keyword.text},"
24+
tags = tags[:-1]
25+
26+
res = requests.post(f"{host}/registry", json={
27+
"title": title,
28+
"description": abstract,
29+
"url": url,
30+
"owner": owner,
31+
"tags": tags,
32+
"key": api_key
33+
})
34+
35+
if res.json()["message"] != "Done.":
36+
log(f"Failed to register deployment with DRGON: {res.json()['message']}")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
pyyaml
22
psycopg2-binary
3+
bs4
4+
requests

build-resources/geocml-task-scheduler/geocml-task-scheduler/schedule.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from backup_geocml_db import backup_geocml_db
33
from restore_geocml_db_from_backups import restore_geocml_db_from_backups
44
from healthcheck_services import healthcheck_services
5+
from register_with_drgon import register_with_drgon
56

67
backup_geocml_db_task = Task(backup_geocml_db, (), 3600) # task runs every hour
78
backup_geocml_db_task.start()
@@ -12,5 +13,8 @@
1213
healthcheck_services_task = Task(healthcheck_services, (), 60)
1314
healthcheck_services_task.start()
1415

16+
register_with_drgon_task = Task(register_with_drgon, (), 60)
17+
register_with_drgon_task.start()
18+
1519
while True:
1620
pass # keep schedule.py process running in container

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ services:
88
image: ghcr.io/geocml/geocml-base-deployment:task-scheduler
99
hostname: geocml-task-scheduler
1010
environment:
11-
- PATH=/geocml-task-scheduler/tabor/dist/tabor:$PATH
11+
PATH: /geocml-task-scheduler/tabor/dist/tabor:$PATH
12+
DRGON_API_KEY: ${DRGON_API_KEY}
13+
DRGON_HOST: ${DRGON_HOST}
1214
networks:
1315
- geocml-network
1416
volumes:

0 commit comments

Comments
 (0)