Skip to content

Commit 6900a62

Browse files
Merge pull request #49 from NikolaosSokos/bug_fixingt
Bug fixing
2 parents 5ed4596 + 071c74c commit 6900a62

33 files changed

Lines changed: 4138 additions & 584 deletions

.github/workflows/publish.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Publish Python Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
- 'v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+'
8+
- 'v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+'
9+
- 'v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+'
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v4
17+
18+
- name: Install UV
19+
run: |
20+
curl -LsSf https://astral.sh/uv/install.sh | sh
21+
echo "$HOME/.local/bin" >> $GITHUB_PATH
22+
23+
- name: Build Package
24+
run: uv build
25+
26+
- name: Upload Build Artifact
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: release-dists
30+
path: dist/
31+
32+
publish-pypi:
33+
if: startsWith(github.ref, 'refs/tags/')
34+
runs-on: ubuntu-latest
35+
needs: [build]
36+
permissions:
37+
id-token: write # Required for OIDC
38+
contents: read
39+
steps:
40+
- name: Download Build Artifact
41+
uses: actions/download-artifact@v4
42+
with:
43+
name: release-dists
44+
path: dist/
45+
46+
- name: Publish to PyPI
47+
uses: pypa/gh-action-pypi-publish@v1.12.4
48+
49+
github-release:
50+
if: startsWith(github.ref, 'refs/tags/')
51+
runs-on: ubuntu-latest
52+
needs: [build]
53+
permissions:
54+
contents: write
55+
steps:
56+
- name: Download Build Artifact
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: release-dists
60+
path: dist/
61+
62+
- name: Create GitHub Release
63+
uses: softprops/action-gh-release@v2
64+
with:
65+
files: dist/*
66+
tag_name: ${{ github.ref_name }}
67+
name: "Release ${{ github.ref_name }}"
68+
draft: false
69+
prerelease: ${{ contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') || contains(github.ref_name, '-rc') }}

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
pull_request:
8+
branches:
9+
- "**"
10+
11+
jobs:
12+
test:
13+
name: Run tests
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v5
21+
with:
22+
version: "latest"
23+
24+
- name: Set up Python
25+
run: uv python install
26+
27+
- name: Install the project
28+
run: uv sync --all-extras --dev
29+
30+
- name: Run tests
31+
run: uv run pytest
32+
env:
33+
PYTHONPATH: ./apps/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Config
2-
config.py
2+
# config.py
33

44
# Virtual environment
55
env/

Dockerfile.api

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
FROM python:3.10-slim
2-
RUN pip install --upgrade pip
3-
RUN pip install --no-cache-dir gunicorn
4-
COPY requirements-api.txt /
5-
RUN pip install --no-cache-dir -r /requirements-api.txt
2+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
63

74
WORKDIR /appli
5+
COPY pyproject.toml uv.lock ./
6+
RUN uv sync --frozen --no-dev
7+
88
COPY start.py config.py ./
99
COPY apps ./apps/
1010
COPY templates ./templates/
11+
COPY tests ./tests/
12+
13+
# Place executables in the environment at the front of the path
14+
ENV PATH="/appli/.venv/bin:$PATH"
1115

1216
CMD ["/bin/bash", "-c", "gunicorn --workers 2 --timeout 600 --bind 0.0.0.0:9001 start:app"]

Dockerfile.cacher

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
FROM python:3.10-slim
2-
RUN pip install --upgrade pip
3-
COPY requirements-cacher.txt /
4-
RUN pip install --no-cache-dir -r /requirements-cacher.txt
2+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
53

64
WORKDIR /appli
5+
COPY pyproject.toml uv.lock ./
6+
RUN uv sync --frozen --no-dev
7+
78
COPY cache.py config.py ./
89
COPY apps ./apps/
910

10-
CMD ["/bin/bash", "-c", "python3 cache.py"]
11+
# Place executables in the environment at the front of the path
12+
ENV PATH="/appli/.venv/bin:$PATH"
13+
14+
CMD ["python", "cache.py"]

Dockerfile.worker

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.10-slim
2+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
3+
4+
WORKDIR /appli
5+
COPY pyproject.toml uv.lock ./
6+
RUN uv sync --frozen --no-dev
7+
8+
# Copy app code
9+
COPY apps ./apps/
10+
11+
# Place executables in the environment at the front of the path
12+
ENV PATH="/appli/.venv/bin:$PATH"
13+
14+
# Run the worker in daemon mode by default
15+
CMD ["python", "apps/worker.py", "--daemon"]

README.md

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,9 @@ Following implementation requires MongoDB v4.2 or higher.
1515
## Deployment
1616

1717
1. Clone the [https://github.com/EIDA/ws-availability] repository and go to its root
18-
1. Copy `config.py.sample` to `config.py` and adjust it as needed (please notice there are two sections - `RUNMODE == "production"` and `RUNMODE == "test"`; for Docker deployment use the `production` section):
19-
20-
```bash
21-
# WFCatalog MongoDB
22-
MONGODB_HOST = "localhost" #MongoDB host
23-
MONGODB_PORT = 27017 #MongoDB port
24-
MONGODB_USR = "" #MongoDB user
25-
MONGODB_PWD = "" #MongoDB password
26-
MONGODB_NAME = "wfrepo" #MongoDB database name
27-
FDSNWS_STATION_URL = "https://orfeus-eu.org/fdsnws/station/1/query" #FDSNWS-Station endpoint to harvest restriction information from
28-
CACHE_HOST = "localhost" #Cache host
29-
CACHE_PORT = 6379 #Cache port
30-
CACHE_INVENTORY_KEY = "inventory" #Cache key for restriction information
31-
CACHE_INVENTORY_PERIOD = 0 #Cache invalidation period for `inventory` key; 0 = never invalidate
32-
CACHE_RESP_PERIOD = 1200 #Cache invalidation period for API response
33-
```
18+
1. Configure the application using Environment Variables. You can use `config.py.sample` as a reference for available variables found in the `Config` class.
19+
20+
**Note:** The application now uses a strict typed configuration system. The legacy `config.py` file is no longer loaded directly; parameters must be supplied via environment variables (which fits naturally with the Docker setup below).
3421

3522
1. Build the containers:
3623

@@ -226,23 +213,11 @@ Following implementation requires MongoDB v4.2 or higher.
226213
## Running in development environment
227214
228215
1. Go to the root directory.
229-
1. Copy `config.py.sample` to `config.py` and adjust it as needed.
230-
1. Create the virtual environment:
231-
232-
```bash
233-
python3 -m venv env
234-
```
235-
236-
1. Activate the virtual environment:
237-
238-
```bash
239-
source env/bin/activate
240-
```
241-
242-
1. Install the dependencies:
216+
1. Configure Environment Variables (e.g. by exporting them or creating a `.env` file). Reference `config.py.sample` for names.
217+
1. Install dependencies using `uv` (faster alternative to pip):
243218
244219
```bash
245-
pip install -r requirements.txt
220+
uv sync
246221
```
247222
248223
1. Create Redis instance (mandatory for WFCatalog-based deployment):
@@ -254,17 +229,17 @@ Following implementation requires MongoDB v4.2 or higher.
254229
1. Build the cache:
255230
256231
```bash
257-
python3 cache.py
232+
uv run python cache.py
258233
```
259234
260235
1. Now you can either:
261236
1. Run it:
262237
263238
```bash
264-
RUNMODE=test FLASK_APP=start.py flask run
239+
RUNMODE=test FLASK_APP=start.py uv run flask run --port 9001
265240
266241
# Or with gunicorn:
267-
RUNMODE=test gunicorn --workers 2 --timeout 60 --bind 0.0.0.0:9001 start:app
242+
RUNMODE=test uv run gunicorn --workers 2 --timeout 60 --bind 0.0.0.0:9001 start:app
268243
```
269244
270245
1. Debug it in VS Code (F5) after selecting "Launch (Flask)" config.
@@ -279,7 +254,7 @@ Following implementation requires MongoDB v4.2 or higher.
279254
Tests can be executed from the respository root using following command:
280255
281256
```bash
282-
PYTHONPATH=./apps/ python3 -m unittest discover tests/
257+
uv run pytest
283258
```
284259
285260
## Ideas for improvements

0 commit comments

Comments
 (0)