# DBIS Core Deployment - Source Code Deployment Required

## Current Status

All infrastructure and containers are ready, but **source code deployment is incomplete** because the GitHub repository requires authentication.

## ✅ What's Complete

1. **All 6 containers created and running**:
   - PostgreSQL Primary (10100) - Database configured ✅
   - PostgreSQL Replica (10101) - Container ready ✅
   - Redis (10120) - Running ✅
   - API Primary (10150) - Node.js installed ✅
   - API Secondary (10151) - Node.js installed ✅
   - Frontend (10130) - Node.js and Nginx installed ✅

2. **Node.js 18.20.8 installed** via nvm in all application containers
3. **Git installed** in all containers
4. **Systemd service files** created for API containers
5. **Nginx configured** for frontend
6. **All deployment scripts** ready and available

## ⚠️ What's Needed

**Source code must be deployed** to each container. The repository `git@github.com:Order-of-Hospitallers/dbis_core.git` requires authentication.

## Solutions

### Solution 1: Run Deployment Scripts (Once Git Auth is Configured)

The deployment scripts will handle everything automatically:

```bash
ssh root@192.168.11.10 "cd /root/proxmox/dbis_core/scripts/deployment && ./deploy-all.sh"
```

**Prerequisites**: Set up SSH keys for git access first (see Solution 2).

### Solution 2: Set Up Git SSH Authentication

Configure SSH keys on containers to allow git clone:

```bash
# Generate SSH key on each container
for vmid in 10150 10151 10130; do
  ssh root@192.168.11.10 "pct exec $vmid -- bash -c 'ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N \"\" -C \"dbis-core-$vmid\" && cat ~/.ssh/id_ed25519.pub'"
done

# Add each public key to GitHub (deploy keys or user SSH keys)
# Then test clone:
ssh root@192.168.11.10 "pct exec 10150 -- bash -c 'GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no\" git clone git@github.com:Order-of-Hospitallers/dbis_core.git /opt/dbis-core'"
```

### Solution 3: Use Personal Access Token (HTTPS)

If you prefer HTTPS with a token:

```bash
# On each container, clone with token
ssh root@192.168.11.10 "pct exec 10150 -- bash -c 'git clone https://YOUR_TOKEN@github.com/Order-of-Hospitallers/dbis_core.git /opt/dbis-core'"
```

### Solution 4: Copy Source from Local Machine

If you have the source code locally, copy it directly:

```bash
# Create tar archive locally
cd /home/intlc/projects/proxmox
tar czf /tmp/dbis_source.tar.gz dbis_core/src dbis_core/package.json dbis_core/prisma dbis_core/frontend --exclude=node_modules --exclude=dist

# Copy to each container
for vmid in 10150 10151 10130; do
  scp /tmp/dbis_source.tar.gz root@192.168.11.10:/tmp/
  ssh root@192.168.11.10 "pct push $vmid /tmp/dbis_source.tar.gz /tmp/dbis_source.tar.gz && pct exec $vmid -- bash -c 'cd /opt && rm -rf dbis-core && mkdir -p dbis-core && tar xzf /tmp/dbis_source.tar.gz -C dbis-core && rm /tmp/dbis_source.tar.gz'"
done
```

## After Source Code is Deployed

Once source code is in `/opt/dbis-core` on each container:

### For API Containers (10150, 10151):

```bash
ssh root@192.168.11.10 "pct exec 10150 -- bash -c '
source /root/.nvm/nvm.sh
cd /opt/dbis-core
npm install
npx prisma generate
npm run build

# Create .env file
cat > .env <<EOF
DATABASE_URL=postgresql://dbis:8cba649443f97436db43b34ab2c0e75b5cf15611bef9c099cee6fb22cc3d7771@192.168.11.100:5432/dbis_core
JWT_SECRET=\$(openssl rand -hex 32)
ALLOWED_ORIGINS=http://192.168.11.130,https://192.168.11.130
NODE_ENV=production
LOG_LEVEL=info
HSM_ENABLED=false
REDIS_URL=redis://192.168.11.120:6379
PORT=3000
EOF

# Restart service
systemctl restart dbis-api
systemctl status dbis-api
'"
```

### For Frontend Container (10130):

```bash
ssh root@192.168.11.10 "pct exec 10130 -- bash -c '
source /root/.nvm/nvm.sh
cd /opt/dbis-core/frontend

# Create .env file
cat > .env <<EOF
VITE_API_BASE_URL=http://192.168.11.150:3000
VITE_APP_NAME=DBIS Admin Console
VITE_REAL_TIME_UPDATE_INTERVAL=5000
EOF

npm install
npm run build

# Restart nginx
systemctl restart nginx
systemctl status nginx
'"
```

### Run Database Migrations:

```bash
ssh root@192.168.11.10 "cd /root/proxmox/dbis_core/scripts/deployment && DBIS_DB_PASSWORD=8cba649443f97436db43b34ab2c0e75b5cf15611bef9c099cee6fb22cc3d7771 ./configure-database.sh"
```

## Database Credentials

- **Database**: dbis_core
- **User**: dbis
- **Password**: `8cba649443f97436db43b34ab2c0e75b5cf15611bef9c099cee6fb22cc3d7771`
- **Host**: 192.168.11.100:5432

⚠️ **Save this password securely!**

## Quick Verification

After deployment:

```bash
# Check API health
curl http://192.168.11.150:3000/health

# Check Frontend
curl http://192.168.11.130

# Check service status
ssh root@192.168.11.10 "cd /root/proxmox/dbis_core/scripts/management && ./status.sh"
```

## Summary

**All infrastructure is ready!** Once source code is deployed (requires git authentication setup), the deployment scripts will handle the rest automatically, or you can complete it manually using the commands above.

