Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fe3c8e7
Adding fastapi server. Work in progress.
sfoale May 8, 2025
92ba6f6
Add test data and instrument endpoint tests.
sfoale May 12, 2025
4da60f9
Add pointing tests. Work in progress
sfoale May 13, 2025
08e90ad
Add candidate and gw_alert tests.
sfoale May 19, 2025
4fd6a0b
Add more tests.
sfoale May 27, 2025
260e930
More tests completed.
sfoale May 28, 2025
76d5abc
All tests complete.
sfoale Jun 5, 2025
93ba921
Complete test coverage of fastapi endpoints.
sfoale Jun 9, 2025
f94b067
Merge branch 'master' into fastapi
sfoale Jun 9, 2025
f7045c5
Missing test.
sfoale Jun 10, 2025
4d0c79d
Update README with better signposting for running and testing fastapi…
sfoale Jun 12, 2025
dde0893
Correct paths
sfoale Jun 12, 2025
b3e0821
Copilot review comments.
sfoale Jun 17, 2025
a2470c2
Add a github action to run the fastapi tests.
sfoale Jul 3, 2025
3203d15
PEP 8 formatting with black.
sfoale Jul 3, 2025
4a29345
fix skaffold run in github action
sfoale Jul 3, 2025
6fdabfb
Use docker compose for the testing github action.
sfoale Jul 3, 2025
0ab1cb7
Use docker compose.
sfoale Jul 3, 2025
8142eed
Initialiase db for github action tests.
sfoale Jul 3, 2025
71cda89
Create db tables from models with sqlalchemy.
sfoale Jul 3, 2025
7da8951
Python formatting.
sfoale Jul 3, 2025
e927869
Add missing model imports.
sfoale Jul 3, 2025
25abaa0
Enable postgis extension in the github actions
sfoale Jul 3, 2025
233fe9e
Debug actions failures
sfoale Jul 3, 2025
c7632f4
Fix the fastapi models.
sfoale Jul 3, 2025
bf11172
Debug actions failures
sfoale Jul 3, 2025
a230f64
Remove debug steps that were polluting test code.
sfoale Jul 3, 2025
e06350e
Update GitHub Action to use FastAPI database initialisation.
sfoale Jul 3, 2025
e43f7cf
Fix instrument_name field length from 25 to 64 characters.
sfoale Jul 3, 2025
daa0528
Clean up github action.
sfoale Jul 3, 2025
6e4e95b
Remove Redis dependency from GitHub Actions workflow
sfoale Jul 3, 2025
41a17d5
Pin dependency versions to speed up docker build.
sfoale Jul 3, 2025
867e5ec
Pin dependency versions to speed up docker build.
sfoale Jul 3, 2025
76939c3
Pin dependency versions to speed up docker build.
sfoale Jul 3, 2025
8ace7c0
Revert.
sfoale Jul 3, 2025
a67b246
PEP 8 check.
sfoale Jul 3, 2025
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
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ static/*.fits.gz
venv/
.git/
viz-example/
tests/
__pycache__/
*.pyc
*.pyo
*.pyd
.pytest_cache/
.coverage
.idea/
.vscode/
*.egg-info/
103 changes: 103 additions & 0 deletions .github/workflows/fastapi-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: FastAPI Tests

on:
push:
branches: [ master, fastapi ]
pull_request:
branches: [ master, fastapi ]

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python for test dependencies
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt

- name: Set up environment variables
run: |
echo "DB_USER=treasuremap" >> $GITHUB_ENV
echo "DB_PWD=treasuremap" >> $GITHUB_ENV
echo "DB_NAME=treasuremap" >> $GITHUB_ENV
echo "MAIL_PASSWORD=dummy" >> $GITHUB_ENV
echo "RECAPTCHA_PUBLIC_KEY=dummy" >> $GITHUB_ENV
echo "RECAPTCHA_PRIVATE_KEY=dummy" >> $GITHUB_ENV
echo "ZENODO_ACCESS_KEY=dummy" >> $GITHUB_ENV
echo "AWS_ACCESS_KEY_ID=dummy" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=dummy" >> $GITHUB_ENV

- name: Build FastAPI Docker image
run: |
docker build -f server/Dockerfile -t gwtm_fastapi:latest .

- name: Start database with Docker Compose
run: |
docker compose up -d db

- name: Wait for database to be ready
run: |
timeout 120 bash -c 'until docker compose exec -T db pg_isready -U treasuremap -d treasuremap; do sleep 5; done'

- name: Enable PostGIS extension
run: |
docker compose exec -T db psql -U treasuremap -d treasuremap -c "CREATE EXTENSION IF NOT EXISTS postgis;"

- name: Initialize database schema with FastAPI models
run: |
docker run --rm --network gwtm_default \
-e DB_USER=treasuremap \
-e DB_PWD=treasuremap \
-e DB_NAME=treasuremap \
-e DB_HOST=gwtm_db \
-e DB_PORT=5432 \
gwtm_fastapi:latest \
python -c "from server.db.init_db import create_database_tables; create_database_tables()"

- name: Load test data
run: |
docker compose exec -T db psql -U treasuremap -d treasuremap < tests/test-data.sql

- name: Start FastAPI server
run: |
docker run -d --name fastapi-server \
--network gwtm_default \
-e DB_USER=treasuremap \
-e DB_PWD=treasuremap \
-e DB_NAME=treasuremap \
-e DB_HOST=gwtm_db \
-e DB_PORT=5432 \
-p 8000:8000 \
gwtm_fastapi:latest

- name: Wait for FastAPI server to be ready
run: |
timeout 120 bash -c 'until curl -f http://localhost:8000/health; do echo "Waiting for FastAPI..."; sleep 5; done'

- name: Run FastAPI tests
run: |
python -m pytest tests/fastapi/ -v --disable-warnings
env:
API_BASE_URL: http://localhost:8000
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: treasuremap
DB_USER: treasuremap
DB_PWD: treasuremap

- name: Cleanup
if: always()
run: |
docker stop fastapi-server || true
docker rm fastapi-server || true
docker compose down -v
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ environment_variables.sh
envars.sh
test
*.DS_Store
deploy/
deploy/
*venv/
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# GW Treasure Map
Website environment

## Quick Start

**For the modern FastAPI backend (recommended):**
The FastAPI application requires database and cache services. Use Skaffold for the complete development environment:
```bash
cd gwtm-helm
skaffold dev # Starts full stack including FastAPI, database, and cache
```
FastAPI will be available at http://localhost:8000 with API docs at http://localhost:8000/docs

See the [FastAPI README](server/README.md) for detailed setup instructions and testing.

**For the legacy Flask application:**
```bash
python gwtm.wsgi # Development server on :5000
```

### Step-by-step installation

### Python:
Expand Down
81 changes: 81 additions & 0 deletions gwtm-helm/fastapi-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{{- /* This file is for documentation only and should not be processed as a template */ -}}
# FastAPI Helm Templates

These templates are used to deploy the FastAPI backend service of the GWTM application.

## Templates

- `deployment.yaml`: Defines the Kubernetes Deployment for the FastAPI service.
- `service.yaml`: Defines the Kubernetes Service for the FastAPI service.
- `configmap.yaml`: Contains configuration data for the FastAPI service.

## Configuration

Configuration for the FastAPI service is defined in the `values.yaml` file under the `fastapi` key:

```yaml
fastapi:
name: fastapi-backend
replicas: 2
image:
repository: gwtm-fastapi
tag: latest
pullPolicy: IfNotPresent
service:
port: 8000
targetPort: 8000
readinessProbe:
enabled: true
path: /docs
initialDelaySeconds: 10
periodSeconds: 5
livenessProbe:
enabled: true
path: /docs
initialDelaySeconds: 30
periodSeconds: 15
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 200m
memory: 256Mi
```

## Ingress Configuration

The FastAPI service is exposed through the following routes in the Ingress:

- `/api/v1/*`: API endpoints
- `/docs`: Swagger UI documentation
- `/redoc`: ReDoc documentation
- `/openapi.json`: OpenAPI schema
- `/health`: Health check endpoint

## Environment Variables

The FastAPI service uses environment variables from the `secrets.yaml` template, which includes:

- Database credentials
- Mail configuration
- AWS/Azure credentials
- Other application-specific settings

## Usage

To deploy the FastAPI service, include these templates in your Helm installation:

```bash
helm install gwtm ./gwtm-helm
```

You can customize the deployment by overriding values:

```bash
helm install gwtm ./gwtm-helm --set fastapi.replicas=3 --set fastapi.image.tag=v1.0.0
```

## Health Checks

The FastAPI service includes readiness and liveness probes that check the `/docs` endpoint to verify that the service is running correctly.
1 change: 1 addition & 0 deletions gwtm-helm/restore-db
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ kubectl cp $DUMP_FILE $POSTGRES_POD:/tmp/dump.sql -n $NAMESPACE

# Execute restore
echo "Restoring database..."

kubectl -n $NAMESPACE exec -it $POSTGRES_POD -- bash -c "PGPASSWORD=$DB_PASSWORD psql -U $DB_USER -f /tmp/dump.sql -a"

echo "Restore completed!"
141 changes: 92 additions & 49 deletions gwtm-helm/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,102 @@
apiVersion: skaffold/v2beta28
apiVersion: skaffold/v4beta13
kind: Config
metadata:
name: gwtm
build:
artifacts:
- image: gwtm
context: ..
docker: {}
- image: gwtm-fastapi
context: ..
docker:
dockerfile: server/Dockerfile
sync:
manual:
- src: "server/routes/**/*.py"
dest: "/app/server/routes/"
- src: "server/db/**/*.py"
dest: "/app/server/db/"
- src: "server/schemas/**/*.py"
dest: "/app/server/schemas/"
- src: "server/services/**/*.py"
dest: "/app/server/services/"
- src: "server/utils/**/*.py"
dest: "/app/server/utils/"
- src: "server/auth/**/*.py"
dest: "/app/server/auth/"
- src: "server/core/**/*.py"
dest: "/app/server/core/"
- src: "server/main.py"
dest: "/app/server/"
- src: "server/config.py"
dest: "/app/server/"
local:
push: false
artifacts:
- image: gwtm
context: ..
docker:
dockerfile: Dockerfile
manifests:
helm:
releases:
- name: gwtm
chartPath: .
valuesFiles:
- values-dev.yaml
setValues:
backend.image.repository: gwtm
backend.image.tag: latest
backend.livenessProbe.enabled: "true"
backend.readinessProbe.enabled: "true"
cache.livenessProbe.enabled: "true"
cache.persistence.enabled: "false"
cache.readinessProbe.enabled: "true"
database.initScripts.enabled: "true"
database.livenessProbe.enabled: "true"
database.persistence.enabled: "false"
database.readinessProbe.enabled: "true"
global.createNamespace: "true"
global.namespace: gwtm
createNamespace: true
wait: true
upgradeOnChange: true
deploy:
helm:
releases:
- name: gwtm
chartPath: .
createNamespace: true
valuesFiles:
- values-dev.yaml
setValues:
global.namespace: gwtm
global.createNamespace: true

# Database values
database.initScripts.enabled: true
database.livenessProbe.enabled: true
database.readinessProbe.enabled: true
database.persistence.enabled: false

# Cache values
cache.livenessProbe.enabled: true
cache.readinessProbe.enabled: true
cache.persistence.enabled: false

# Backend values
backend.readinessProbe.enabled: true
backend.livenessProbe.enabled: true

# Image settings
backend.image.repository: gwtm
backend.image.tag: latest
wait: true
upgradeOnChange: true
- name: gwtm
chartPath: .
valuesFiles:
- values-dev.yaml
setValues:
backend.image.repository: gwtm
backend.image.tag: latest
backend.livenessProbe.enabled: "true"
backend.readinessProbe.enabled: "true"
cache.livenessProbe.enabled: "true"
cache.persistence.enabled: "false"
cache.readinessProbe.enabled: "true"
database.initScripts.enabled: "true"
database.livenessProbe.enabled: "true"
database.persistence.enabled: "false"
database.readinessProbe.enabled: "true"
global.createNamespace: "true"
global.namespace: gwtm
createNamespace: true
wait: true
upgradeOnChange: true
portForward:
# Direct backend access on local port 8080
- resourceType: service
resourceName: flask-backend
namespace: gwtm
port: 8080
localPort: 8080
address: 0.0.0.0
# Frontend on local port 8081
- resourceType: service
resourceName: frontend
namespace: gwtm
port: 80
localPort: 8081
address: 0.0.0.0
- resourceType: service
resourceName: flask-backend
namespace: gwtm
port: 8080
address: 0.0.0.0
localPort: 8080
- resourceType: service
resourceName: frontend
namespace: gwtm
port: 80
address: 0.0.0.0
localPort: 8081
- resourceType: service
resourceName: fastapi-backend
namespace: gwtm
port: 8000
address: 0.0.0.0
localPort: 8000
Loading