fix: copy packages/ to Docker build context (fixes HF Spaces build #30)
Browse files* docs: spec #30 - HF Spaces build error missing packages/ directory
* fix: copy packages/ to docker build context before pip install (fixes HF Spaces build)
Root cause: Dockerfile copied requirements.txt but not packages/ directory.
pip install failed because ./packages/niivueviewer path didn't exist.
Changes:
- Dockerfile: Add COPY packages/ before pip install
- .dockerignore: Add standard exclusions, keep node_modules out of context
Note: Do NOT ignore scripts/ - deepisles_adapter.py is required by Dockerfile.
- .dockerignore +33 -0
- Dockerfile +4 -0
- docs/specs/30-bug-hf-spaces-build-packages-dir.md +116 -0
.dockerignore
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Docker ignore file
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
*.pyo
|
| 5 |
+
*.pyd
|
| 6 |
+
.Python
|
| 7 |
+
env/
|
| 8 |
+
venv/
|
| 9 |
+
.venv/
|
| 10 |
+
.git/
|
| 11 |
+
.github/
|
| 12 |
+
.vscode/
|
| 13 |
+
.idea/
|
| 14 |
+
.DS_Store
|
| 15 |
+
*.egg-info/
|
| 16 |
+
.mypy_cache/
|
| 17 |
+
.pytest_cache/
|
| 18 |
+
.ruff_cache/
|
| 19 |
+
.coverage
|
| 20 |
+
htmlcov/
|
| 21 |
+
dist/
|
| 22 |
+
build/
|
| 23 |
+
site/
|
| 24 |
+
docs/_build/
|
| 25 |
+
|
| 26 |
+
# Ignore local data and test artifacts
|
| 27 |
+
data/
|
| 28 |
+
results/
|
| 29 |
+
tests/
|
| 30 |
+
# NOTE: Do NOT ignore scripts/ - deepisles_adapter.py is needed by Dockerfile
|
| 31 |
+
|
| 32 |
+
# Ignore node_modules in custom components to keep build context small
|
| 33 |
+
**/node_modules/
|
Dockerfile
CHANGED
|
@@ -31,6 +31,10 @@ WORKDIR /home/user/demo
|
|
| 31 |
# Copy requirements first for better layer caching
|
| 32 |
COPY --chown=1000:1000 requirements.txt /home/user/demo/requirements.txt
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Install Python dependencies into SYSTEM Python (NOT conda env)
|
| 35 |
# DeepISLES conda env is Python 3.8, but Gradio 6 needs Python 3.10+
|
| 36 |
# We'll shell out to conda env for inference only
|
|
|
|
| 31 |
# Copy requirements first for better layer caching
|
| 32 |
COPY --chown=1000:1000 requirements.txt /home/user/demo/requirements.txt
|
| 33 |
|
| 34 |
+
# Copy local packages (Custom Components) BEFORE pip install
|
| 35 |
+
# This is required because requirements.txt refers to ./packages/niivueviewer
|
| 36 |
+
COPY --chown=1000:1000 packages/ /home/user/demo/packages/
|
| 37 |
+
|
| 38 |
# Install Python dependencies into SYSTEM Python (NOT conda env)
|
| 39 |
# DeepISLES conda env is Python 3.8, but Gradio 6 needs Python 3.10+
|
| 40 |
# We'll shell out to conda env for inference only
|
docs/specs/30-bug-hf-spaces-build-packages-dir.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Spec #30: HF Spaces Build Error - Missing packages/ Directory
|
| 2 |
+
|
| 3 |
+
## Status: π΄ P0 BLOCKER
|
| 4 |
+
|
| 5 |
+
## Issue
|
| 6 |
+
HuggingFace Spaces Docker build fails with:
|
| 7 |
+
```
|
| 8 |
+
ERROR: Invalid requirement: './packages/niivueviewer': Expected package name at the start of dependency specifier
|
| 9 |
+
./packages/niivueviewer
|
| 10 |
+
^ (from line 28 of requirements.txt)
|
| 11 |
+
Hint: It looks like a path. File './packages/niivueviewer' does not exist.
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
## Root Cause Analysis
|
| 15 |
+
|
| 16 |
+
### Timeline
|
| 17 |
+
1. PR #29 added `gradio_niivueviewer` custom component in `packages/niivueviewer/`
|
| 18 |
+
2. Added `./packages/niivueviewer` to `requirements.txt` line 28 for local installs
|
| 19 |
+
3. Dockerfile copies `requirements.txt` but NOT `packages/` directory
|
| 20 |
+
4. `pip install -r requirements.txt` fails because path doesn't exist
|
| 21 |
+
|
| 22 |
+
### Architecture Gap
|
| 23 |
+
```
|
| 24 |
+
Local Development:
|
| 25 |
+
requirements.txt β ./packages/niivueviewer β β
EXISTS
|
| 26 |
+
|
| 27 |
+
HF Spaces Docker:
|
| 28 |
+
COPY requirements.txt β Container
|
| 29 |
+
pip install -r requirements.txt
|
| 30 |
+
β ./packages/niivueviewer β β NOT COPIED
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
## Solution Options
|
| 34 |
+
|
| 35 |
+
### Option A: Copy packages/ in Dockerfile (Recommended)
|
| 36 |
+
Add `COPY --chown=1000:1000 packages/ /home/user/demo/packages/` before pip install.
|
| 37 |
+
|
| 38 |
+
**Pros:**
|
| 39 |
+
- Simple fix
|
| 40 |
+
- Preserves local development workflow
|
| 41 |
+
- Editable install works correctly
|
| 42 |
+
|
| 43 |
+
**Cons:**
|
| 44 |
+
- Adds ~1.3MB to Docker image (compiled JS bundle)
|
| 45 |
+
|
| 46 |
+
### Option B: Build wheel and include in Docker
|
| 47 |
+
Pre-build wheel, copy to container, install from wheel file.
|
| 48 |
+
|
| 49 |
+
**Pros:**
|
| 50 |
+
- More "production" approach
|
| 51 |
+
|
| 52 |
+
**Cons:**
|
| 53 |
+
- More complex build process
|
| 54 |
+
- Need to manage wheel artifacts
|
| 55 |
+
|
| 56 |
+
### Option C: Separate requirements files
|
| 57 |
+
Create `requirements-docker.txt` without local path dependencies.
|
| 58 |
+
|
| 59 |
+
**Pros:**
|
| 60 |
+
- Clear separation of concerns
|
| 61 |
+
|
| 62 |
+
**Cons:**
|
| 63 |
+
- Duplicate maintenance
|
| 64 |
+
- Easy to drift out of sync
|
| 65 |
+
|
| 66 |
+
## Recommended Fix
|
| 67 |
+
|
| 68 |
+
**Option A** - Simple, maintainable, aligns with how local development works.
|
| 69 |
+
|
| 70 |
+
### Implementation
|
| 71 |
+
|
| 72 |
+
```dockerfile
|
| 73 |
+
# BEFORE pip install, add:
|
| 74 |
+
COPY --chown=1000:1000 packages/ /home/user/demo/packages/
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Full Dockerfile Change
|
| 78 |
+
|
| 79 |
+
```dockerfile
|
| 80 |
+
# Copy requirements first for better layer caching
|
| 81 |
+
COPY --chown=1000:1000 requirements.txt /home/user/demo/requirements.txt
|
| 82 |
+
|
| 83 |
+
# Copy custom component packages (required for pip install)
|
| 84 |
+
COPY --chown=1000:1000 packages/ /home/user/demo/packages/
|
| 85 |
+
|
| 86 |
+
# Install Python dependencies into SYSTEM Python
|
| 87 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## Test Plan
|
| 91 |
+
|
| 92 |
+
### Level 1: Local Docker Build
|
| 93 |
+
```bash
|
| 94 |
+
docker build -t stroke-demo-test .
|
| 95 |
+
docker run -p 7860:7860 stroke-demo-test
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
### Level 2: HF Spaces Deploy
|
| 99 |
+
Push to HF Spaces, verify build succeeds and app loads.
|
| 100 |
+
|
| 101 |
+
### Level 3: Functional Test
|
| 102 |
+
- Upload NIfTI files
|
| 103 |
+
- Run segmentation
|
| 104 |
+
- Verify NiiVue 3D viewer renders volumes
|
| 105 |
+
|
| 106 |
+
## Files to Modify
|
| 107 |
+
- `Dockerfile` - Add COPY for packages/ directory
|
| 108 |
+
|
| 109 |
+
## Risk Assessment
|
| 110 |
+
- **Low risk** - Additive change, doesn't modify existing code
|
| 111 |
+
- **Reversible** - Can easily remove if issues arise
|
| 112 |
+
|
| 113 |
+
## Acceptance Criteria
|
| 114 |
+
- [ ] HF Spaces build succeeds
|
| 115 |
+
- [ ] App loads without "Loading..." hang
|
| 116 |
+
- [ ] NiiVue viewer displays volumes correctly
|