Spaces:
Running
Running
File size: 9,613 Bytes
907b200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | # Changelog: SQLite Migration & Hugging Face Spaces Deployment
> **Date:** 2026-06-09
> **Branch:** `feature/hugging-face-deploy`
> **Commits:** `fd94aa0..1cbbcaa` (3 commits)
---
## Overview
Migrated AILIXIR from **MySQL/MariaDB** to **SQLite** and deployed the entire platform to **5 Hugging Face Spaces** with GitHub-to-HF auto-sync.
---
## Part 1: SQLite Database Migration
### Migration Fixes
**4 migration files were modified** to remove MySQL-specific syntax:
| File | Problem | Fix |
|------|---------|-----|
| `database/migrations/2026_04_20_135553_create_admets_table.php` | `useCurrentOnUpdate()` β MySQL-only | Replaced manual timestamps with `$table->timestamps()` |
| `database/migrations/2026_04_20_044726_create_screening_results_table.php` | `output` column not nullable, causing `->change()` failure | Changed `json('output')` to `json('output')->nullable()` |
| `database/migrations/2026_04_20_055149_create_target_lookups_table.php` | Same as above | Same fix |
| `database/migrations/2026_04_21_155344_add_status_to_screening_tables.php` | Used `->change()` which requires MySQL-like `ALTER TABLE MODIFY` | Rewritten to only add `status` column, removed all `->change()` calls |
### Configuration Changes
- **`config/database.php`** β SQLite connection configured with:
- `journal_mode` = `wal` (Write-Ahead Logging for concurrent reads)
- `busy_timeout` = `5000` (5 second wait on locked DB)
- `transaction_mode` = `IMMEDIATE` (prevents "database is locked" errors)
### Environment Files Updated
| File | Before | After |
|------|--------|-------|
| `.env.example` | `DB_CONNECTION=mysql` + host/port/user/pass | `DB_CONNECTION=sqlite`, `DB_DATABASE=database/ailixir.sqlite` |
| `.env.docker` | Same MySQL config | Same SQLite config |
| `docker/laravel.env` | Same MySQL config | Same SQLite config |
### `.gitignore`
Added `*.sqlite`, `*.sqlite-wal`, `*.sqlite-shm` to prevent accidental commits of database files.
---
## Part 2: Docker Infrastructure Changes
### `Dockerfile`
- **PHP extension**: `pdo_mysql` β `pdo_sqlite`
- **System packages**: Added `libsqlite3-dev`, `supervisor`
- **Ports**: Added `EXPOSE 7860` for Hugging Face Spaces
- **Database directory**: Creates `database/` directory during build
- Removed `COPY docker/laravel.env .env` (env vars now come from HF Space secrets)
### `docker/supervisord.conf` (new)
Runs two processes in a single container for HF Spaces:
- `[program:laravel]` β `php artisan serve --host=0.0.0.0 --port=7860`
- `[program:queue]` β `php artisan queue:work --sleep=3 --tries=3 --timeout=300`
### `docker/entrypoint.sh`
- Creates SQLite database file at runtime if it doesn't exist
- Checks `RUN_MODE=hf` environment variable β if set, starts supervisord instead of the default CMD
- Still supports Docker Compose mode (runs migrations, then exec's the passed CMD)
### `docker-compose.yml`
- **Removed** the entire `mysql:` service (was MariaDB 11.4)
- **Removed** `mysql-data` volume
- **Removed** `depends_on: mysql` from `laravel` and `queue` services
- **Removed** `DB_HOST: mysql` environment overrides
- AI microservice configs remain unchanged
### `.env.hf` (new)
Template file with all HF Space URLs pre-configured for the AI microservice URLs.
---
## Part 3: Hugging Face Spaces Deployment
### Spaces Created (5)
| Space | Type | Content |
|-------|------|---------|
| `ailixir-api` | Docker (Laravel) | Root repo (excludes `ai_apps/`, `Diagrams/`) |
| `ailixir-admet` | Docker (FastAPI) | `ai_apps/ADMIT/admet_inference/` |
| `ailixir-drug-repurposing` | Docker (FastAPI) | `ai_apps/Drug Reporposing/` |
| `ailixir-chemical-rag` | Docker (FastAPI) | `ai_apps/chemical-rag-system/chemical-rag-system/` |
| `ailixir-generation` | Docker (FastAPI) | `ai_apps/generation/` (CPU-only Dockerfile) |
### Space Configuration
- All spaces use `cpu-basic` hardware (free tier)
- Port configured to **7860** in each Dockerfile
- `README.md` with proper YAML frontmatter added to each space
- 15-minute sleep timeout for free tier cost savings
### Generation Service Adaptation
The generation service originally required NVIDIA CUDA + GPU. For HF Spaces (CPU-only), a **lightweight Dockerfile** was created that:
- Uses `python:3.10-slim` base (instead of `nvidia/cuda`)
- Installs only `fastapi`, `uvicorn`, `pydantic`, `requests`, `rdkit`
- Disables AutoDock-GPU and DeepPurpose (CPU-only)
- Provides basic molecule generation and docking scoring
---
## Part 4: GitHub-to-HF Auto-Sync
### 5 GitHub Actions Workflows
| File | Triggers | Syncs |
|------|----------|-------|
| `.github/workflows/sync-hf-backend.yml` | Push to `main`/`develop` (excl. `ai_apps/`) | Whole repo β `ailixir-api` |
| `.github/workflows/sync-hf-admet.yml` | Push to `ai_apps/ADMIT/admet_inference/` | Subdir β `ailixir-admet` |
| `.github/workflows/sync-hf-drug-repurposing.yml` | Push to `ai_apps/Drug Reporposing/` | Subdir β `ailixir-drug-repurposing` |
| `.github/workflows/sync-hf-chemical-rag.yml` | Push to `ai_apps/chemical-rag-system/` | Subdir β `ailixir-chemical-rag` |
| `.github/workflows/sync-hf-generation.yml` | Push to `ai_apps/generation/` | Subdir β `ailixir-generation` |
Each workflow:
1. Clones the target HF Space repo
2. Rsyncs the relevant files (excluding `.git`, `__pycache__`, etc.)
3. Commits with the GitHub commit SHA
4. Pushes to HF Space
### GitHub Actions Workflow Updates
- **`api-tests.yml`** β Removed MySQL wait loop and health check; removed MySQL log collection
- **`integration-test.yml`** β Same changes across all 4 job definitions
---
## Part 5: Files Modified/Created Summary
### Modified (15 files)
```
.config/database.php
.env.docker
.env.example
.gitignore
Dockerfile
docker-compose.yml
docker/entrypoint.sh
docker/laravel.env
.github/workflows/api-tests.yml
.github/workflows/integration-test.yml
database/migrations/2026_04_20_044726_create_screening_results_table.php
database/migrations/2026_04_20_055149_create_target_lookups_table.php
database/migrations/2026_04_20_135553_create_admets_table.php
database/migrations/2026_04_21_155344_add_status_to_screening_tables.php
database/ailixir.sqlite (new, empty)
```
### Created (9 files)
```
.env.hf
docker/supervisord.conf
.github/workflows/sync-hf-backend.yml
.github/workflows/sync-hf-admet.yml
.github/workflows/sync-hf-drug-repurposing.yml
.github/workflows/sync-hf-chemical-rag.yml
.github/workflows/sync-hf-generation.yml
HF_SPACES_GUIDE.md (this file)
CHANGELOG_SQLITE_HF.md (this file)
```
---
## Architecture Diagram
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub Repository β
β RottenShadow/ β
β AILIXIR_BackEnd β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β Push triggers
βΌ
βββββββββββββββββββββββββββββββ
β GitHub Actions (5 WFs) β
β Auto-sync to HF Spaces β
βββββββββββββββ¬ββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
βailixir- β βailixir- β βailixir- β βailixir- β βailixir- β
βapi β βadmet β βdrug- β βchemical- β βgenerationβ
β(Laravel) β β(ADMET) β βrepurpos. β βrag β β(Molec. β
βSQLite β β β β β β β βGen.) β
ββββββ¬ββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
β
β HTTP proxying to AI microservices
ββββ https://shdwRow-ailixir-admet.hf.space
ββββ https://RottenShadow-ailixir-drug-repurposing.hf.space
ββββ https://RottenShadow-ailixir-chemical-rag.hf.space
ββββ https://shdwRow-ailixir-generation.hf.space
```
---
## Remaining Steps (Manual)
1. **Set HF tokens as GitHub secrets** β Required for auto-sync workflows
- Go to: https://github.com/RottenShadow/AILIXIR_BackEnd/settings/secrets/actions
- Add secret: `HF_TOKEN` = `YOUR_ROTTENSHADOW_TOKEN`
- Add secret: `HF_TOKEN_AILIXIR` = `YOUR_AILIXIR_AI_TEAM_TOKEN`
2. **Set backend Space secrets** β Required for `ailixir-api` to function
- Go to: https://huggingface.co/spaces/Ailixir-AI-Team/ailixir-api/settings
- Add all secrets listed in `HF_SPACES_GUIDE.md` section 3.1
- **Minimum:** `APP_KEY`, `RUN_MODE=hf`, and all AI service URLs
3. **Wait for builds to complete** β Backend Docker image is large (~5GB) and takes 15β45 minutes to build on HF free tier
4. **Verify connectivity** β Test the health endpoints and ensure the backend can reach all AI services
|