Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitblanc committed Nov 3, 2023
0 parents commit 191c8b1
Show file tree
Hide file tree
Showing 16 changed files with 653 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "🐍 Lint"

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- main
paths:
- "**.py"
- ".github/workflows/linter.yml"
pull_request:
branches:
- main
paths:
- "**.py"

env:
PYTHON_VERSION: "3.10"

jobs:
lint:
name: 🐍 Lint
runs-on: ubuntu-latest

steps:
- name: Get source code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
cache-dependency-path: "requirements/*.txt"

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements/requirements.txt
python -m pip install -r requirements/development.txt
- name: Format with black
uses: psf/black@stable
with:
options: "--check --verbose"
version: "23.10.0"

- name: Run isort
uses: isort/isort-action@v1

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
46 changes: 46 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: 🚀 Publish Docker image

on:
push:
branches:
- main
tags:
- "v*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
name: 🚀 Build and push Docker image
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Get source code
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv/
__pycache__/
.flaskenv
.env
51 changes: 51 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
exclude: ".venv|__pycache__"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ["--maxkb=500"]
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: fix-encoding-pragma
args: [--remove]
- id: pretty-format-json
args: ["--autofix", "--no-sort-keys"]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix-only"]

- repo: https://github.com/psf/black
rev: 23.10.0
hooks:
- id: black
args: ["--target-version=py310"]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
language: python
types:
- python
args:
[
"--config=setup.cfg",
]
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contributing Guidelines

First off, thanks for considering to contribute to this project!

These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.

## Git hooks

We use git hooks through [pre-commit](https://pre-commit.com/) to enforce and automatically check some "rules". Please install them (`pre-commit install`) before to push any commit.

See the relevant configuration file: `.pre-commit-config.yaml`.

## Code Style

Make sure your code *roughly* follows [PEP-8](https://www.python.org/dev/peps/pep-0008/) and keeps things consistent with the rest of the code:

- formatting: [black](https://black.readthedocs.io/) is used to automatically format the code without debate.
- sorted imports: [isort](https://pycqa.github.io/isort/) is used to sort imports
- static analisis: [flake8](https://flake8.pycqa.org/en/latest/) is used to catch some dizziness and keep the source code healthy.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM sourcepole/qwc-uwsgi-base:alpine-v2023.10.26

ADD . /srv/qwc_service

RUN \
apk add --no-cache --update --virtual runtime-deps postgresql-libs && \
apk add --no-cache --update --virtual build-deps git postgresql-dev g++ python3-dev && \
pip3 install --no-cache-dir -r /srv/qwc_service/requirements/requirements.txt && \
apk del build-deps

ENV SERVICE_MOUNTPOINT=/api/v1/postgresfts
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Benoît Blanc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
QWC Postgres Fulltext Search Service
====================================

Setup
-----

Configuration
-------------

Usage
-----

Set the `CONFIG_PATH` environment variable to the path containing the service config and permission files when starting this service (default: `config`).

Base URL:

http://localhost:5050/

Service API:

http://localhost:5050/api/

Development
-----------

Create a virtual environment:

virtualenv --python=/usr/bin/python3 --system-site-packages .venv

Without system packages:

virtualenv --python=/usr/bin/python3 .venv

Activate virtual environment:

source .venv/bin/activate

Install requirements:

pip install -r requirements/requirements.txt

Set the `CONFIG_PATH` environment variable to the path containing the service config and permission files when starting this service (default: `config`).

export CONFIG_PATH=../qwc-docker/volumes/config

Configure environment:

echo FLASK_ENV=development >.flaskenv

Start local service:

python server.py

Testing
-------

Run all tests:

python test.py
9 changes: 9 additions & 0 deletions requirements/development.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Develoment dependencies
# -----------------------

black
flake8>=4,<7
flake8-builtins>=1.5,<3
flake8-isort>=6,<7
isort>=5.11,<6
pre-commit>=3,<4
7 changes: 7 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Flask==2.3.2
flask-restx==1.1.0
Flask-JWT-Extended==4.4.4
SQLAlchemy==1.4.48
psycopg2==2.9.6
requests==2.31.0
qwc-services-core==1.3.19
101 changes: 101 additions & 0 deletions schemas/qwc-postgres-fts-service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/benoitblanc/qwc-postgres-fts-service/main/schemas/qwc-postgres-fts-service.json",
"title": "QWC Postgres FTS Service",
"type": "object",
"properties": {
"$schema": {
"title": "JSON Schema",
"description": "Reference to JSON schema of this config",
"type": "string",
"format": "uri",
"default": "https://raw.githubusercontent.com/benoitblanc/qwc-postgres-fts-service/main/schemas/qwc-postgres-fts-service.json"
},
"service": {
"title": "Service name",
"type": "string",
"const": "postgresFTSSearch"
},
"config": {
"title": "Config options",
"type": "object",
"properties": {
"search_result_limit": {
"description": "Result count limit per search",
"type": "integer",
"default": 50
}
}
},
"resources": {
"title": "Resources",
"type": "object",
"properties": {
"documents": {
"title": "Search documents",
"type": "array",
"items": {
"title": "Document",
"type": "object",
"properties": {
"name": {
"description": "Document name",
"type": "string"
},
"text_search_config": {
"description": "Text search configuration used for search",
"type": "string",
"default": "english"
},
"db_url": {
"description": "DB connection for result query",
"type": "string"
},
"schema": {
"description": "Schema to query for search",
"type": "string"
},
"table": {
"description": "Table to query for search",
"type": "string"
},
"primary_key": {
"description": "Primary key of the table to query",
"type": "string"
},
"columns": {
"description": "Attributes to query for search and display as result",
"type": "array",
"items": {
"type": "string"
}
},
"geometry_column": {
"description": "Geometry column in search result table",
"type": "string",
"default": "geom"
}
},
"required": [
"name",
"db_url",
"schema",
"table",
"primary_key",
"display_name",
"columns"
]
}
}
},
"required": [
"documents"
]
}
},
"required": [
"service",
"config",
"resources"
]
}
Loading

0 comments on commit 191c8b1

Please sign in to comment.