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

Register deployments automatically with DRGON #94

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from task_logger import log
import bs4 as bs
import os
import requests

def register_with_drgon():
host = os.environ["DRGON_HOST"]
api_key = os.environ["DRGON_API_KEY"]
deployment_host = os.environ["GEOCML_DEPLOYMENT_HOST"]

if host == "" or api_key == "" or deployment_host == "":
log("Host or API key not found, can't register this deployment with DRGON.")
return 0

res = requests.get("http://geocml-server/cgi-bin/qgis_mapserv.fcgi?SERVICE=WFS&VERSION=1.3.0&REQUEST=GetCapabilities")
xml = bs.BeautifulSoup(res.text, "html.parser")
abstract = xml.find("ows:abstract", text=lambda text: isinstance(text, bs.CData)).string.strip()
title = xml.find("ows:title").text
owner = xml.find("ows:individualname").text
keywords = xml.find("ows:keywords").find_all("ows:keyword")
tags = ""
for keyword in keywords:
tags += f"{keyword.text},"
tags = tags[:-1]

res = requests.post(f"{host}/registry", json={
"title": title,
"description": abstract,
"url": deployment_host,
"owner": owner,
"tags": tags,
"key": api_key
})

if res.json()["message"] != "Done.":
log(f"Failed to register deployment with DRGON: {res.json()['message']}")
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pyyaml
psycopg2-binary
bs4
requests
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from backup_geocml_db import backup_geocml_db
from restore_geocml_db_from_backups import restore_geocml_db_from_backups
from healthcheck_services import healthcheck_services
from register_with_drgon import register_with_drgon

backup_geocml_db_task = Task(backup_geocml_db, (), 3600) # task runs every hour
backup_geocml_db_task.start()
Expand All @@ -12,5 +13,8 @@
healthcheck_services_task = Task(healthcheck_services, (), 60)
healthcheck_services_task.start()

register_with_drgon_task = Task(register_with_drgon, (), 60)
register_with_drgon_task.start()

while True:
pass # keep schedule.py process running in container
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ services:
image: ghcr.io/geocml/geocml-base-deployment:task-scheduler
hostname: geocml-task-scheduler
environment:
- PATH=/geocml-task-scheduler/tabor/dist/tabor:$PATH
PATH: /geocml-task-scheduler/tabor/dist/tabor:$PATH
DRGON_API_KEY: ${DRGON_API_KEY}
DRGON_HOST: ${DRGON_HOST}
GEOCML_DEPLOYMENT_HOST: ${GEOCML_DEPLOYMENT_HOST}
networks:
- geocml-network
volumes:
Expand Down
Loading