Skip to content

Commit 0a477b3

Browse files
committed
Add HA API server with Docker support
- Add ha_api.py: async aiohttp server with ProcessPoolExecutor for handling hundreds of concurrent queries without timeouts - Add Dockerfile for containerised deployment - Add GitHub Actions docker.yml workflow for DockerHub CI/CD - Add aiohttp dependency to requirements.txt and setup.py - Bump version to 0.6.0
1 parent 02439aa commit 0a477b3

6 files changed

Lines changed: 399 additions & 4 deletions

File tree

.github/workflows/docker.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
release:
6+
types: [published]
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Extract metadata
18+
id: meta
19+
run: |
20+
if [[ $GITHUB_REF == refs/tags/* ]]; then
21+
TAG=${GITHUB_REF#refs/tags/}
22+
else
23+
TAG=${GITHUB_REF#refs/heads/}
24+
fi
25+
echo "tag=$TAG" >> $GITHUB_OUTPUT
26+
27+
- name: Build test Docker image
28+
run: docker build --no-cache . --file Dockerfile --tag test-image
29+
30+
- name: Test container startup
31+
run: |
32+
docker run -d --name test-container -p 8080:8080 test-image
33+
sleep 10
34+
if docker ps | grep -q test-container; then
35+
echo "Container is running successfully"
36+
curl -sf http://localhost:8080/health || { echo "Health check failed"; docker logs test-container; exit 1; }
37+
echo "Health check passed"
38+
else
39+
echo "Container failed to start"
40+
docker logs test-container
41+
exit 1
42+
fi
43+
docker stop test-container || true
44+
docker rm test-container
45+
46+
- name: Build Docker image
47+
run: docker build . --file Dockerfile --tag virtualflybrain/vfbquery:${{ steps.meta.outputs.tag }}
48+
49+
- name: Login to Docker Hub
50+
uses: docker/login-action@v3
51+
with:
52+
username: ${{ secrets.DOCKER_HUB_USER }}
53+
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
54+
55+
- name: Push Docker image
56+
run: docker push virtualflybrain/vfbquery:${{ steps.meta.outputs.tag }}

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
# Install system deps (some vfb_connect/pandas wheels need these)
6+
RUN apt-get update && \
7+
apt-get install -y --no-install-recommends gcc g++ && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
# Install Python deps first (layer caching)
11+
COPY requirements.txt setup.py pyproject.toml README.md ./
12+
COPY src/ src/
13+
RUN pip install --no-cache-dir aiohttp && \
14+
pip install --no-cache-dir -e .
15+
16+
EXPOSE 8080
17+
18+
# Tuning via env vars:
19+
# VFBQUERY_PORT (default 8080)
20+
# VFBQUERY_HOST (default 0.0.0.0)
21+
# VFBQUERY_WORKERS (default: CPU count)
22+
# VFBQUERY_MAX_CONCURRENT (default: workers × 4)
23+
24+
ENTRYPOINT ["python", "-m", "vfbquery.ha_api"]

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ dataclasses-json
33
dacite
44
requests
55
pysolr
6-
get_version
6+
get_version
7+
aiohttp

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
here = path.abspath(path.dirname(__file__))
55

6-
__version__ = "0.5.9"
6+
__version__ = "0.6.0"
77

88
# Get the long description from the README file
99
with open(path.join(here, 'README.md')) as f:
@@ -30,7 +30,8 @@
3030
"pysolr",
3131
"pandas",
3232
"marshmallow",
33-
"vfb_connect"
33+
"vfb_connect",
34+
"aiohttp",
3435
],
3536
python_requires=">=3.7",
3637
project_urls={ # Optional

src/vfbquery/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ def clear_solr_cache(query_type: str, term_id: str) -> bool:
9595
__solr_caching_available__ = False
9696

9797
# Version information
98-
__version__ = "0.5.9"
98+
__version__ = "0.6.0"

0 commit comments

Comments
 (0)