Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
include:
- python-version: 3.10.12
- python-version: 3.12.3
steps:
- name: Checkout ✅
uses: actions/checkout@v2
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:jammy
FROM ubuntu:noble

# Credits to yjacolin for providing first versions
LABEL original_developer="yjacolin <yves.jacolin@camptocamp.com>" \
Expand All @@ -18,9 +18,8 @@ ENV LC_ALL="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
\
\
DEB_PACKAGES="locales gunicorn postgresql-client python3-gunicorn python3-gevent python3-psycopg2 python3-lxml python3-pyproj" \
DEB_PACKAGES="locales gunicorn python3.12-venv postgresql-client python3-gunicorn python3-gevent python3-lxml python3-pyproj" \
DEB_BUILD_DEPS="make python3-pip" \
# GHC ENV settings\
ADMIN_NAME=admin \
ADMIN_PWD=admin \
ADMIN_EMAIL=admin.istrator@mydomain.com \
Expand Down Expand Up @@ -91,7 +90,7 @@ COPY . /GeoHealthCheck
# Install
RUN \
chmod a+x /*.sh && ./install.sh \
# Cleanup TODO: remove unused Locales and TZs
# Cleanup TODO: remove unused Locales and TZs \
&& apt-get remove --purge -y ${DEB_BUILD_DEPS} \
&& apt-get clean \
&& apt autoremove -y \
Expand Down
14 changes: 7 additions & 7 deletions GeoHealthCheck/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#
# =================================================================

from datetime import datetime
from datetime import datetime, timezone
import logging
import json
from urllib.request import urlopen
Expand Down Expand Up @@ -95,7 +95,7 @@ def run_resource(resourceid):
# Run test
result = run_test_resource(resource)

run1 = Run(resource, result, datetime.utcnow())
run1 = Run(resource, result, datetime.now(timezone.utc))

DB.session.add(run1)

Expand Down Expand Up @@ -144,7 +144,7 @@ def sniff_test_resource(config, resource_type, url):
raise RuntimeError(msg2)

title = None
start_time = datetime.utcnow()
start_time = datetime.now(timezone.utc)
message = None
resource_type_map = {'OGC:WMS': [partial(WebMapService, version='1.3.0'),
partial(WebMapService, version='1.1.1')],
Expand Down Expand Up @@ -223,7 +223,7 @@ def sniff_test_resource(config, resource_type, url):
title = urlparse(url).hostname
elif resource_type == 'OSGeo:GeoNode':
endpoints = ows
end_time = datetime.utcnow()
end_time = datetime.now(timezone.utc)
delta = end_time - start_time
response_time = '%s.%s' % (delta.seconds, delta.microseconds)
base_tags = geonode_make_tags(url)
Expand Down Expand Up @@ -259,7 +259,7 @@ def sniff_test_resource(config, resource_type, url):
message = msg
success = False

end_time = datetime.utcnow()
end_time = datetime.now(timezone.utc)

delta = end_time - start_time
response_time = '%s.%s' % (delta.seconds, delta.microseconds)
Expand Down Expand Up @@ -311,10 +311,10 @@ def geonode_make_tags(base_url):

if __name__ == '__main__':
print('START - Running health check tests on %s'
% datetime.utcnow().isoformat())
% datetime.now(timezone.utc).isoformat())
run_resources()
print('END - Running health check tests on %s'
% datetime.utcnow().isoformat())
% datetime.now(timezone.utc).isoformat())
# from init import App
# if len(sys.argv) < 3:
# print('Usage: %s <resource_type> <url>' % sys.argv[0])
Expand Down
2 changes: 0 additions & 2 deletions GeoHealthCheck/migrations/versions/2638c2a40625_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"""
from alembic import op
import sqlalchemy as sa
import imp
import os
from GeoHealthCheck.migrations import alembic_helpers

# revision identifiers, used by Alembic.
Expand Down
2 changes: 0 additions & 2 deletions GeoHealthCheck/migrations/versions/496427d03f87_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"""
from alembic import op
import sqlalchemy as sa
import imp
import os
from GeoHealthCheck.migrations import alembic_helpers

# revision identifiers, used by Alembic.
Expand Down
2 changes: 0 additions & 2 deletions GeoHealthCheck/migrations/versions/992013af402f_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"""
from alembic import op
import sqlalchemy as sa
import imp
import os
from GeoHealthCheck.migrations import alembic_helpers

# revision identifiers, used by Alembic.
Expand Down
12 changes: 6 additions & 6 deletions GeoHealthCheck/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import json
import logging
from flask_babel import gettext as _
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from sqlalchemy import func, and_

Expand All @@ -58,7 +58,7 @@ def flush_runs():
all_runs = Run.query.all()
run_count = 0
for run in all_runs:
days_old = (datetime.utcnow() - run.checked_datetime).days
days_old = (datetime.now(timezone.utc) - run.checked_datetime).days
if days_old > retention_days:
run_count += 1
DB.session.delete(run)
Expand Down Expand Up @@ -87,7 +87,7 @@ class Run(DB.Model):
report = deferred(DB.Column(DB.Text, default={}))

def __init__(self, resource, result,
checked_datetime=datetime.utcnow()):
checked_datetime=datetime.now(timezone.utc)):
self.resource = resource
self.success = result.success
self.response_time = result.response_time_str
Expand Down Expand Up @@ -680,13 +680,13 @@ def __init__(self, resource, owner, interval_mins):
self.init_datetimes(interval_mins)

def init_datetimes(self, interval_mins):
self.start_time = datetime.utcnow()
self.start_time = datetime.now(timezone.utc)
# Subtract some space from end-time to allow obtain at scheduled time
minutes = interval_mins - 1
self.end_time = self.start_time + timedelta(minutes=minutes)

def has_expired(self):
now = datetime.utcnow()
now = datetime.now(timezone.utc)
return now > self.end_time

def obtain(self, owner, frequency):
Expand Down Expand Up @@ -723,7 +723,7 @@ def __init__(self, username, password, email, role='user'):
self.set_password(password)
self.email = email
self.role = role
self.registered_on = datetime.utcnow()
self.registered_on = datetime.now(timezone.utc)

def authenticate(self, password):
return util.verify_hash(password, self.password)
Expand Down
6 changes: 3 additions & 3 deletions GeoHealthCheck/probe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys

import datetime
from datetime import datetime, timezone
import requests

from factory import Factory
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_metadata_cached(self, resource, version='any'):
metadata = None
if key in Probe.METADATA_CACHE:
entry = Probe.METADATA_CACHE[key]
delta = datetime.datetime.utcnow() - entry['time']
delta = datetime.now(timezone.utc) - entry['time']
metadata = entry['metadata']

# Don't keep cache forever, refresh every N mins
Expand All @@ -144,7 +144,7 @@ def get_metadata_cached(self, resource, version='any'):
# Store entry with time, for expiry later
entry = {
"metadata": metadata,
"time": datetime.datetime.utcnow()
"time": datetime.now(timezone.utc)
}
Probe.METADATA_CACHE[key] = entry

Expand Down
6 changes: 3 additions & 3 deletions GeoHealthCheck/result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
from datetime import datetime, timezone


class Result(object):
Expand Down Expand Up @@ -36,10 +36,10 @@ def set(self, success, message):
self.message = message

def start(self):
self.start_time = datetime.datetime.utcnow()
self.start_time = datetime.now(timezone.utc)

def stop(self):
self.end_time = datetime.datetime.utcnow()
self.end_time = datetime.now(timezone.utc)

delta = self.end_time - self.start_time
self.response_time_secs = delta.seconds
Expand Down
15 changes: 7 additions & 8 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ For example [run.sh](run.sh) which launches GHC using the robust `gunicorn` WSGI
## Run

```
docker run -d --name ghc_web -p 8083:80 -v ghc_sqlitedb:/GeoHealthCheck/DB geopython/geohealthcheck:latest
docker run -d --name ghc_web --rm -p 8083:80 -v ghc_sqlitedb:/GeoHealthCheck/DB geopython/geohealthcheck:latest
```

go to http://localhost:8083 (port 80 in GHC Container is mapped to 8083 on host).
Expand All @@ -56,7 +56,7 @@ This mode can be disabled by passing `GHC_RUNNER_IN_WEBAPP` to as an ENV
var to the Docker container:

```
docker run --name ghc_web -e GHC_RUNNER_IN_WEBAPP=False -p 8083:80 -v ghc_sqlitedb:/GeoHealthCheck/DB geopython/geohealthcheck:latest
docker run --name ghc_web --rm -e GHC_RUNNER_IN_WEBAPP=False -p 8083:80 -v ghc_sqlitedb:/GeoHealthCheck/DB geopython/geohealthcheck:latest

```

Expand All @@ -66,21 +66,21 @@ You can then run `GHC Runner` as a separate container by overriding
the default `ENTRYPOINT` with `/run-runner.sh`:

```
docker run -d --name ghc_runner --entrypoint "/run-runner.sh" -v ghc_sqlitedb:/GeoHealthCheck/DB geopython/geohealthcheck:latest
docker run -d --name ghc_runner --rm --entrypoint "/run-runner.sh" -v ghc_sqlitedb:/GeoHealthCheck/DB geopython/geohealthcheck:latest
```

But the most optimal way to run GHC with scheduled jobs and optionally Postgres as backend DB,
is to use [Docker Compose](https://docs.docker.com/compose), see below.

## Using docker-compose
## Using docker compose

This allows a complete Docker setup, including scheduling and optionally using
Postgres/PostGIS as database (recommended).
See the [Docker Compose Documentation](https://docs.docker.com/compose)
for more info. GHC Webapp and Runner are in this case
deployed as separate processes (Docker containers).

*Note that the `docker-compose` YAML files below are meant as examples to be adapted to your*
*Note that the `docker compose` YAML files below are meant as examples to be adapted to your*
*local deployment situation.*

### Using sqlite DB (default)
Expand All @@ -92,7 +92,7 @@ To run (`-d` allows running in background):

```
cd docker/compose
docker-compose -f docker-compose.yml up [-d]
docker compose -f docker-compose.yml up [-d]

# go to http://localhost:8083 (port 80 in GHC Container is mapped to 8083 on host)

Expand All @@ -105,10 +105,9 @@ similar but uses Postgres as the database.

To run:


```
cd docker/compose
docker-compose -f docker-compose.postgis.yml up [-d]
docker compose -f docker-compose.postgis.yml up [-d]

# go to http://localhost:8083 (port 80 in GHC Container is mapped to 8083 on host)

Expand Down
13 changes: 13 additions & 0 deletions docker/compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@

Within this directory are *examples* for running GHC using Docker compose.
You should copy and adapt these for your own deployment.

## Running with SQLite DB
```shell
docker compose up -d
docker compose down --remove-orphans

```
## Running with PostGIS DB
```shell
docker compose -f docker-compose.postgis.yml up -d
docker compose -f docker-compose.postgis.yml down --remove-orphans

```
5 changes: 2 additions & 3 deletions docker/compose/docker-compose.postgis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# GHC Docker setup with Postgres as backend DB.
#
# To run:
# sudo docker-compose -f docker-compose.postgis.yml up [-d]
# sudo docker compose -f docker-compose.postgis.yml up [-d]
#
version: "3"

services:
ghc_web:
Expand Down Expand Up @@ -63,7 +62,7 @@ services:
# - ./../GeoHealthCheck/plugins:/plugins:ro

postgis_ghc:
image: mdillon/postgis:10-alpine
image: postgis/postgis:14-3.5-alpine

container_name: postgis_ghc

Expand Down
6 changes: 5 additions & 1 deletion docker/compose/ghc-postgis.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# We mainly need to override the default (sqlite) DB URI
SQLALCHEMY_DATABASE_URI=postgresql://ghc:ghc@postgis_ghc:5432/ghc

# Postgres Docker container settings
# PostgreSQL/PostGIS Docker container settings
POSTGRES_HOST=postgis_ghc
POSTGRES_PORT=5432
POSTGRES_USER=ghc
PGUSER=ghc
POSTGRES_PASSWORD=ghc
PGPASSWORD=ghc
POSTGRES_DB=ghc
15 changes: 13 additions & 2 deletions docker/docker-clean.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#!/bin/bash
docker rm $(docker ps -a -q)
docker rmi $(docker images -f dangling=true -q)

#
# Remove all exited containers
for c in $(docker ps -a -f status=exited -q)
do
docker rm ${c}
done

# And dangling images
for i in $(docker images -f dangling=true -q)
do
docker rmi ${i}
done
Loading
Loading