Skip to content
Open
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
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# VCS
.git
.gitignore

# Local pixi environment (built inside the image via `pixi install`)
.pixi

# Local dev / bootstrap artifacts (regenerated in the image)
instance
report.md
docs/_build
GeoHealthCheck/static/lib
GeoHealthCheck/data.db

# Tooling / caches
.pytest_cache
**/__pycache__
*.pyc
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
max-line-length = 79
exclude = .git,.cache,docs,docker,build,dist,GeoHealthCheck/migrations
exclude = .git,.cache,docs,docker,build,dist,.pixi,GeoHealthCheck/migrations
# max-complexity = 38
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SCM syntax highlighting & preventing 3-way merges
pixi.lock merge=binary linguist-language=YAML linguist-generated=true -diff
51 changes: 29 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# https://github.com/geopython/pycsw/blob/master/.github/workflows/main.yml
#
# Author: Just van den Broecke - 2021
# Migrated to pixi - 2026 by @francbartoli
#
name: Main GHC CI ⚙️

Expand All @@ -10,44 +11,50 @@ on: [ push, pull_request ]
jobs:
main:
runs-on: ubuntu-24.04
strategy:
matrix:
include:
- python-version: 3.12.3
steps:
- name: Checkout ✅
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }} 🐍
uses: actions/setup-python@v2
# Installs pixi (pinned) and the `dev` environment from the committed
# pixi.lock (locked: true fails if the lock is out of sync). Python and
# all dependencies come from the lock, so no separate setup-python step.
- name: Setup pixi 🧰
uses: prefix-dev/setup-pixi@v0.10.0
with:
python-version: ${{ matrix.python-version }}

- name: Install Requirements 📦
run: |
python -m pip install --upgrade pip
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
pixi-version: v0.72.0
environments: dev
locked: true
cache: true

- name: Setup GHC App and init DB 🗃️
run: |
invoke setup
echo -e "admin\ntest\ntest\nyou@example.com\nyou@example.com" | python3 GeoHealthCheck/models.py create
pixi run -e dev setup
pixi run -e dev create -u admin -p admin -e a@a.com

- name: Flake8 - Verify Coding Conventions ⚙️
run: flake8
run: pixi run -e dev flake8

- name: Load Fixtures Test Data ⚙️
run: python3 GeoHealthCheck/models.py load tests/data/fixtures.json y
run: pixi run -e dev load-data tests/data/fixtures.json

# - name: Test DB downgrade to previous schema (via Alembic) ⚙️
# run: pixi run -e dev db-action downgrade
#
# - name: Test DB upgrade back to current schema (via Alembic) ⚙️
# run: pixi run -e dev db-action upgrade

- name: Run Probes ⚙️
run: python3 GeoHealthCheck/healthcheck.py
run: pixi run -e dev run-healthchecks

- name: Run Unit Tests ⚙️
run: python3 tests/run_tests.py
run: pixi run -e dev test

- name: Publish Test Report 📄
if: always()
run: cat report.md >> "$GITHUB_STEP_SUMMARY" || true

- name: Build Docs 📖
run: cd docs && make html
run: pixi run -e dev docs

- name: Cleanup 💯
run: python3 GeoHealthCheck/models.py drop
run: pixi run -e dev drop-data
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ GeoHealthCheck.conf

# Data
GeoHealthCheck/data.db
# test report
report.md

# pixi environments
.pixi/*
!.pixi/config.toml
34 changes: 20 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:noble
FROM ghcr.io/prefix-dev/pixi:0.72.0-noble

# Credits to yjacolin for providing first versions
LABEL original_developer="yjacolin <yves.jacolin@camptocamp.com>" \
Expand All @@ -18,14 +18,15 @@ ENV LC_ALL="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
\
\
DEB_PACKAGES="locales gunicorn python3.12-venv postgresql-client python3-gunicorn python3-gevent python3-lxml python3-pyproj" \
DEB_BUILD_DEPS="make python3-pip" \
DEB_PACKAGES="ca-certificates locales postgresql-client" \
DEB_BUILD_DEPS="curl adduser" \
ADMIN_NAME=admin \
ADMIN_PWD=admin \
ADMIN_EMAIL=admin.istrator@mydomain.com \
SQLALCHEMY_DATABASE_URI='sqlite:////GeoHealthCheck/DB/data.db' \
SQLALCHEMY_ENGINE_OPTION_PRE_PING=False \
SECRET_KEY='d544ccc37dc3ad214c09b1b7faaa64c60351d5c8bb48b342' \
GHC_HOME=/GeoHealthCheck \
GHC_PROBE_HTTP_TIMEOUT_SECS=30 \
GHC_MINIMAL_RUN_FREQUENCY_MINS=10 \
GHC_RETENTION_DAYS=30 \
Expand Down Expand Up @@ -72,30 +73,35 @@ WSGI_WORKER_CLASS='gevent' \
# GHC User Plugins, best be overridden via Container environment \
GHC_USER_PLUGINS=''

# Install operating system dependencies
RUN \
apt-get update \
&& apt-get --no-install-recommends install -y ${DEB_PACKAGES} ${DEB_BUILD_DEPS} ${ADD_DEB_PACKAGES} \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \
&& echo "For ${TZ} date=$(date)" && echo "Locale=$(locale)"

# Add standard files and Add/override Plugins
# Alternative Entrypoints to run GHC jobs
# Override default Entrypoint with these on Containers
COPY docker/scripts/*.sh docker/config_site.py docker/plugins /

# Add Source Code
COPY . /GeoHealthCheck
COPY . ${GHC_HOME}

# Install
WORKDIR ${GHC_HOME}

# Install operating system dependencies
RUN \
chmod a+x /*.sh && ./install.sh \
# Cleanup TODO: remove unused Locales and TZs \
apt-get update \
&& apt-get --no-install-recommends install -y ${DEB_PACKAGES} ${DEB_BUILD_DEPS} ${ADD_DEB_PACKAGES} \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \
&& echo "For ${TZ} date=$(date)" && echo "Locale=$(locale)" \
&& adduser --disabled-password --shell /bin/bash --home ${GHC_HOME} --gecos "User" ghc \
&& chmod +x /*.sh \
&& pixi install --locked -e prod \
&& pixi run -e prod setup \
&& cp /config_site.py ${GHC_HOME}/instance/config_site.py \
&& if [ -d /plugins ]; then cp -ar /plugins/* ${GHC_HOME}/GeoHealthCheck/plugins/; fi && rm -rf /plugins \
&& apt-get remove --purge -y ${DEB_BUILD_DEPS} \
&& apt-get clean \
&& apt autoremove -y \
&& rm -rf /var/lib/apt/lists/*

# For later: run as user 'ghc'
# USER ghc

# For SQLite
VOLUME ["/GeoHealthCheck/DB/"]
Expand Down
53 changes: 37 additions & 16 deletions GeoHealthCheck/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@
# Usage:
#
# $ python3 manage.py --help
# usage: manage.py [-h] {shell,db,runserver} ...
#
# positional arguments:
# {shell,db,runserver}
# shell Runs a Python shell inside Flask application context.
# db Perform database migrations
# runserver Runs the Flask development server i.e. app.run()
# usage: manage.py action
#
# optional arguments:
# -h, --help show this help message and exit
#
# For DB management:
# $ python3 manage.py db --help
# $ python manage.py upgrade
# usage: Perform database migrations
#
# positional arguments:
# action arguments:
# {upgrade,migrate,current,stamp,init,downgrade,history,revision}
# upgrade Upgrade to a later version
# migrate Alias for 'revision --autogenerate'
Expand All @@ -37,17 +31,44 @@
# optional arguments:
# -h, --help show this help message and exit

from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
import sys
import os
from flask_migrate import (Migrate, upgrade, downgrade, current,
migrate, history, revision)
from init import App

DB = App.get_db()
APP = App.get_app()
workdir_path = os.path.dirname(__file__)
migrations_path = os.path.join(workdir_path, 'migrations')
Migrate(APP, DB, directory=migrations_path)
ACTIONS = ['current', 'upgrade', 'downgrade', 'migrate', 'history', 'revision']

if __name__ == '__main__':
if len(sys.argv) < 1 or sys.argv[1] not in ACTIONS:
print(f'Invalid action, valid values: {ACTIONS}')
sys.exit(1)

migrate = Migrate(APP, DB)
# Valid action name
action = sys.argv[1]

manager = Manager(APP)
manager.add_command('db', MigrateCommand)
os.chdir(workdir_path)

if __name__ == '__main__':
manager.run()
with APP.app_context():
if action == 'current':
current()
elif action == 'upgrade':
# Upgrade to latest version
upgrade()
elif action == 'downgrade':
# Downgrade one version back
downgrade()
elif action == 'migrate':
# Generate revision
migrate()
elif action == 'history':
# Show revisions
history()
elif action == 'revision':
# Create new revision
revision()
19 changes: 10 additions & 9 deletions GeoHealthCheck/migrations/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Database upgrade support

This dir contains various files for developing database upgrades.
Upgrades are supported using Alembic via Flask-Migrate
and Flask-Script.
Users should be able to upgrade existing installs via:
Upgrades are supported using Alembic via Flask-Migrate.
Users should be able to upgrade existing installations via `pixi`:

# In top dir of installation
invoke upgrade
pixi run db-action upgrade
# or the equivalent
python manage.py upgrade

The `versions` dir contains the various upgrades. These were
initially created using the Alembic `autogenerate` facility
Expand All @@ -20,12 +21,12 @@ for various DB management tasks related to migrations and upgrading.
Whenever a change in the database schema or table content
conventions has changed a new migration should be created via the command.

python3 manage.py db migrate
python manage.py migrate

Where `migrate` is an alias for `revision --autogenerate`.
Alternatively if the autogeneration does not work, create an empty migration:

python3 manage.py db revision
python manage.py revision

In both cases this will create a new revision and a `<revision_number>_.py` file
under `versions/` to upgrade
Expand All @@ -37,9 +38,9 @@ to check various DB metadata.

Subsequently the upgrade can be performed using:

python3 manage.py db upgrade
# or the equivalent (for users)
invoke upgrade
pixi run db-action upgrade
# or the equivalent
python manage.py upgrade

## Revisions

Expand Down
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
[![Full Documentation](https://img.shields.io/badge/ReadTheDocs-online-green.svg)](https://docs.geohealthcheck.org)
[![Gitter](https://img.shields.io/gitter/room/geopython/GeoHealthCheck.svg?style=flat-square)](https://gitter.im/geopython/GeoHealthCheck)

GeoHealthCheck
==============
# GeoHealthCheck

GeoHealthCheck (GHC) is a Service Status and QoS Checker for OGC Web Services and web APIs in general.
See also the [full GHC documentation](http://docs.geohealthcheck.org/).

Easiest is [to run GHC using Docker](https://github.com/geopython/GeoHealthCheck/blob/master/docker/README.md).

## Manual Install
Below a quick overview of a manual install on Unix-based systems like Apple MacOS and Linux.

```bash
Expand Down Expand Up @@ -66,4 +67,58 @@ python3 GeoHealthCheck/models.py load <.json data file> [y/n]

```

## Install with Pixi

[Pixi](https://pixi.sh) manages the environment; tasks run via `pixi run`,
so no shell activation is needed.

```
git clone https://github.com/geopython/GeoHealthCheck.git
cd GeoHealthCheck

# Install production environment
pixi install -e prod

# bootstrap the app (config, static assets, i18n, local docs, DB)
pixi run -e prod setup

# generate secret key
pixi run -e prod create-secret-key
# setup local configuration (overrides GeoHealthCheck/config_main.py)
vi instance/config_site.py
# edit at least secret key:
# - SECRET_KEY # copy/paste result string from the command above

# Optional: edit other settings or leave defaults (see above)

# setup superuser account password and email directly
pixi run -e prod create -username admin -password admin --email a@a.com

# or shorter
pixi run -e prod create -u admin -p admin --e a@a.com

# run locally
pixi run -e prod run

# open http://localhost:8000 in browser

```

### Development and tests

```
# install the dev environment (adds flake8, pytest, ...)
pixi install -e dev

# bootstrap once, needed before the tests can run
pixi run -e dev setup

# run the unit tests
pixi run -e dev test
```

Prefer an interactive shell? `pixi shell -e prod` (or `-e dev`) activates the
environment, after which `invoke ...` and `python ...` work directly.


More in the [full GHC documentation](http://docs.geohealthcheck.org/).
1 change: 0 additions & 1 deletion docker/compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# configured in the GHC Web App.
#
# Plugins (optional) need to be configured for both Docker containers.
version: "3"

services:
ghc_web:
Expand Down
Loading
Loading