prole/docs/DOCKER-BUILD-FIX.md
chrisfu a069989315 Rename prole-db to knoe-db, add knoe-auth as cluster-internal KDC
Itemized changes:

1. knoe-auth: New cluster-internal KDC and SSO gateway service
   - Created etc/init_knoe_auth.sh based on init_kdc.sh with knoe-auth naming
   - Namespace defaults to SERVICE_NAMESPACE (knoe-system)
   - ConfigMap: knoe-auth-kdc-config, Secret: knoe-auth-secrets
   - Legacy cleanup removes old auth/dog/authority deployments

2. Orchestration: knoe-auth initializes before CloudNativePG
   - Updated prole.sh to insert init_knoe_auth.sh as step 2 (before CNPG)
   - Renumbered all subsequent initialization steps

3. Kong routing: Updated init_kong.sh to route to knoe-auth in SERVICE_NAMESPACE

4. Comment/reference updates for knoe-auth
   - Updated init_common_services.sh, init_service_layer.sh, init_kerberos.sh

5. prole-db renamed to knoe-db across the entire codebase
   - Renamed prole-db/ directory to knoe-db/
   - Renamed all prole-db Kubernetes manifests (deploy/opentofu, k8s/)
   - Renamed scripts: docker-root-knoe-db.sh, docker-run-knoe-db.sh, test-cnpg-knoe-db.sh
   - Renamed etc/init_prole-db-reset.sh to etc/init_knoe-db-reset.sh
   - Renamed etc/prole-db-passwwd.sh to etc/knoe-db-passwwd.sh
   - Renamed mock_val counterparts accordingly
   - Renamed tests/etc/test_init_prole-db-reset.sh to test_init_knoe-db-reset.sh
   - Renamed docs/prole-db-documentation-mcp-architecture.md to knoe-db variant
   - Renamed modes/k3d/prole-db/ to modes/k3d/knoe-db/
   - Renamed prole-db.iml to knoe-db.iml

6. Configuration updates
   - Updated conf/dev, conf/prod, conf/test, conf/service prole.cfg files
   - Updated conf/port-mapping.cfg
   - Updated etc/prole_cfg.sh and mock_val/prole_cfg.sh
   - Updated service/prole.cfg

7. Kubernetes manifests and deploy configuration
   - Updated deploy/opentofu/k3s ArgoCD application YAMLs
   - Updated kong-configmap.yaml and kustomization.yaml
   - Updated k3s/kong-config.yml and prole-resources.yaml
   - Updated prole-mssql-db deployment YAMLs
   - Updated supabase helm render and deploy scripts

8. Infrastructure and GCP Terraform
   - Updated deploy/gcp/terraform: folders, groups, IAM, service-projects

9. Python/installer code updates
   - Updated knoe/core: actions, build_context, controller, env, milestones
   - Updated knoe/milestone.py
   - Updated knoe/ui/screens: cfg, database, database_options, deploy, docker,
     navigation, security, services, validate
   - Updated knoe.spec, status.py

10. Shell script updates
    - Updated etc/: build_db, init_cloudnative_pg, init_cnpg_backup,
      init_db_manager, init_forgejo, init_gitlab, init_monitoring, init_openbao,
      init_port_forwards, init_postgrest, init_supabase_ports, status
    - Updated mock_val/ counterparts for all above scripts
    - Updated prole-net/init-prole-dns.sh
    - Updated bin/prole-kpf.sh, gitea/deploy.sh, supabase/deploy.sh

11. Test updates
    - Updated tests/etc/: test_init_cloudnative_pg*, test_init_cnpg_backup*,
      test_init_kdc*, test_init_kerberos*, test_init_kong*, test_prole_cfg*
    - Updated tests/installer/: test_actions_helpers, test_cfg_save_kubecontext,
      test_controller, test_core_classes, test_milestones, test_milestones_extended,
      test_namespace_propagation
    - Updated tests/: test_database_options, test_navigation,
      test_render_supabase_hostname, test_docker_build_fix,
      test_all_prole_home_fixes, silent_install_test, final_test

12. Documentation updates
    - Updated docs/: DOCKER-BUILD-FIX, PROLE-CFG-SECRETS, PROLE-HOME-DIRECTORY,
      build-system, patent
    - Updated scan/network_description.txt
    - Updated pom.xml

13. Miscellaneous script updates
    - Updated root-level: _adopt_replica_pvcs, _fix_replica_merlin, _import_pi,
      _patch_cluster, _prebind_pvcs, _rebind_d002, _rebind_d002b, test_resolve
    - Updated scripts/generate_spec.py

Co-authored-by: Junie <junie@jetbrains.com>
2026-03-22 22:16:21 -07:00

256 lines
6.6 KiB
Markdown

# Docker Build Fix for PyInstaller Bundle
## Problem
When the Prole Installer is packaged with PyInstaller and run as a standalone binary, Docker builds fail with the error:
```
Building knoe-db:17.7-037 in /var/folders/rt/pywlnmxj3dn7t5552vwdcpp80000gn/T/_MEIGozuj4/knoe-db...
```
The build hangs or fails because:
1. PyInstaller extracts resources to a temporary read-only directory (`/tmp/_MEIxxxxxx/`)
2. Docker build requires a writable context directory
3. The temporary directory has restrictive permissions
4. Docker cannot create the build context properly
## Solution
Copy the Docker build context to a writable user directory before building.
### Implementation
**Location:** `install.py`, `run_db_build()` method (line ~1791)
**Before:**
```python
def worker():
tag = self.get_knoe_db_version()
cwd = PROJECT_ROOT / "knoe-db" # ✗ Points to read-only _MEIPASS
cmd = ['docker', 'build', '-t', f"knoe-db:{tag}", '.']
proc = subprocess.Popen(cmd, cwd=cwd, ...)
```
**After:**
```python
def worker():
tag = self.get_knoe_db_version()
# Use $PROLE_HOME/build for Docker build context
prole_home = resolve_prole_home()
# Use a mode-scoped build dir to avoid cross-mode interference (k3d vs k3s)
mode_key = _deployment_mode_from_env(env_key) or "default"
build_dir = prole_home / "build" / mode_key / "knoe-db"
build_dir.mkdir(parents=True, exist_ok=True)
# Copy DB build context to writable location
source_dir = get_resource_path("knoe-db")
if not source_dir.exists():
source_dir = get_resource_path("knoe-db")
if source_dir.exists():
import shutil
if build_dir.exists():
shutil.rmtree(build_dir)
shutil.copytree(source_dir, build_dir)
cwd = build_dir # ✓ Writable user directory
cmd = ['docker', 'build', '-t', f"knoe-db:{tag}", '.']
proc = subprocess.Popen(cmd, cwd=cwd, ...)
```
## Directory Structure (Mode-scoped)
The installer now creates and uses:
```
$HOME/.prole/
└── build/
└── k3d/ # or k3s, k8s
└── knoe-db/ # Docker build context
├── Dockerfile
├── conf/
├── scripts/
├── ...
└── .prole_build_context_ready # marker to preserve generated Dockerfile
Version metadata is also mode-scoped:
```
$HOME/.prole/
└── modes/
└── k3d/ # or k3s, k8s
├── conf/postgresql/.version
└── knoe-db/.version
```
```
## Why This Works
1. **Writable Location:** `$HOME/.prole/` is user-writable
2. **Persistent:** Files remain between runs (can be cached)
3. **Clean State:** Each build starts fresh (old dir removed)
4. **Docker Compatible:** Standard directory Docker can access
## Resource Path Resolution
The `knoe-db` directory is:
- **Included in spec:** `('knoe-db', 'knoe-db')`
- **Extracted by PyInstaller:** To `_MEIPASS/knoe-db/`
- **Copied to writable location:** `$HOME/.prole/build/<mode>/knoe-db/`
- **Used for build:** Docker builds from writable copy
## Performance
**First Build:**
- Copy knoe-db (~1-5 MB): < 1 second
- Docker build: 30-60 seconds (varies)
**Subsequent Builds:**
- Directory recreation: < 1 second
- Docker build: May use layer cache
## Testing
### Test from Source
```bash
python3 install.py --gui
# Navigate to "Build Container" screen
# Click "Build Database Image"
# Should succeed without hanging
```
### Test from Package
```bash
make package
./dist/Prole\ Installer.app/Contents/MacOS/prole-installer --gui
# Navigate to "Build Container" screen
# Click "Build Database Image"
# Should create ~/.prole/build/<mode>/knoe-db and succeed
```
### Verify Directory Creation
```bash
# After build starts
ls -la ~/.prole/build/<mode>/knoe-db/
# Should show Dockerfile and other files
```
## Cleanup
The build directory persists after the installer exits. To clean up:
```bash
rm -rf ~/.prole/build
```
Or include in the installer:
```python
def cleanup_build_dirs():
"""Clean up temporary build directories."""
build_dir = Path.home() / ".prole" / "build"
if build_dir.exists():
shutil.rmtree(build_dir)
```
## Other Potential Issues
If Docker build still hangs, check:
1. **Docker daemon running:**
```bash
docker info
```
2. **Docker context accessible:**
```bash
ls -la ~/.prole/build/<mode>/knoe-db/Dockerfile
```
3. **Disk space:**
```bash
df -h ~
```
4. **Docker permissions:**
```bash
docker ps
# Should not require sudo
```
## Alternative Solutions Considered
### 1. Use /tmp with Unique Names
```python
import tempfile
build_dir = Path(tempfile.mkdtemp(prefix="prole-build-"))
```
**Pros:** Automatic cleanup
**Cons:** Lost between runs, no caching
### 2. Build in Place (_MEIPASS)
```python
cwd = get_resource_path("knoe-db")
```
**Pros:** No copying needed
**Cons:** ✗ Fails due to read-only permissions
### 3. Use PROJECT_ROOT for Both
```python
cwd = PROJECT_ROOT / "knoe-db"
```
**Pros:** Works from source
**Cons:** ✗ Fails from package (_MEIPASS is read-only)
### 4. **Chosen: Copy to ~/.prole/build** ✓
**Pros:** Works from both source and package, writable, persistent
**Cons:** Requires disk space, manual cleanup
## Related Changes
- **Spec file updated:** Added `('knoe-db', 'knoe-db')` to data files
- **Resource path:** Uses `get_resource_path("knoe-db")` for source
- **Build output:** Console shows build directory location
## Future Enhancements
1. **Add cleanup option:**
```python
# In exit handler or menu
if messagebox.askyesno("Cleanup", "Remove build directories?"):
cleanup_build_dirs()
```
2. **Progress indication:**
```python
self._db_build_console.write("Copying build context...\n")
shutil.copytree(source_dir, build_dir)
self._db_build_console.write("Build context ready.\n")
```
3. **Cache detection:**
```python
if build_dir.exists() and not force_clean:
self._db_build_console.write("Using cached build context...\n")
else:
shutil.copytree(source_dir, build_dir)
```
## Multi-version deploy safety (CNPG)
`etc/init_cloudnative_pg.sh` now enforces:
- Multiple DB image versions **must** be deployed into **different namespaces** (for parallel installs)
- Reusing the same namespace with a different image/version requires an explicit upgrade flag: `--upgrade`
## Summary
The Docker build now works correctly from both source and packaged binary by:
1. Creating `~/.prole/build/<mode>/knoe-db/` directory
2. Copying build context from embedded resources
3. Running `docker build` in the writable directory
4. Avoiding PyInstaller's read-only temporary extraction directory