# Synology Deployment Guide (ManeshTrader Web)

This guide documents the exact deployment flow that worked for this project on Synology NAS.

## App Location

This project runs from:

- NAS folder: `/volume1/docker/maneshtrader`
- Container port: `8501`
- URL: `http://<NAS_IP>:8501`

## Prerequisites (One-Time)

On Synology DSM:

1. Install `Container Manager` from Package Center.
2. Enable SSH:
   - `Control Panel -> Terminal & SNMP -> Enable SSH service`
3. Ensure your user can run Docker:
   - Add user to `administrators` group.
   - Grant `Container Manager` app permission for that user.

Notes:

- Store data only in shared folders (use `/volume1/...` paths).
- If Docker commands fail with socket permission errors, use `sudo -i` (see Troubleshooting).

## Required Files in `web/src`

These files must exist (already added in this repo):

- `Dockerfile`
- `docker-compose.yml`
- `app.py`
- `requirements.txt`
- `web_core/`

## Initial Deploy

Run from your Mac (repo root), using your SSH port `25`:

```bash
rsync -avz --delete -e "ssh -p 25" \
  --exclude ".pytest_cache" --exclude "__pycache__" \
  web/src/ mbrucedogs@192.168.1.128:/volume1/docker/maneshtrader/
```

Then SSH to Synology:

```bash
ssh -p 25 mbrucedogs@192.168.1.128
```

Start the container:

```sh
sudo -i
cd /volume1/docker/maneshtrader
mkdir -p data
docker compose up -d --build
```

If your DSM uses legacy compose command:

```sh
docker-compose up -d --build
```

## Verify It Is Running

```sh
sudo -i
docker ps --filter name=maneshtrader
docker logs --tail 100 maneshtrader
```

Open in browser:

- `http://192.168.1.128:8501`

## Update Workflow (After Code Changes)

You do **not** need to redo full setup. Just:

1. Sync updated source.
2. Rebuild/restart compose service.

From Mac:

```bash
rsync -avz --delete -e "ssh -p 25" \
  web/src/ mbrucedogs@192.168.1.128:/volume1/docker/maneshtrader/
```

On Synology:

```sh
sudo -i
cd /volume1/docker/maneshtrader
docker compose up -d --build
```

## Useful Operations

Restart app:

```sh
sudo -i
cd /volume1/docker/maneshtrader
docker compose restart
```

Stop app:

```sh
sudo -i
cd /volume1/docker/maneshtrader
docker compose down
```

Follow logs live:

```sh
sudo -i
docker logs -f maneshtrader
```

## Troubleshooting

### Error: `permission denied while trying to connect to the Docker daemon socket`

Cause:

- SSH user does not have Docker daemon access.

Fix:

1. Run commands as root shell:

```sh
sudo -i
```

2. If `sudo` is unavailable, in DSM:
   - Add user to `administrators`.
   - Allow `Container Manager` permission.
   - Reconnect SSH.

Do **not** run insecure socket permission changes like:

```sh
chmod 666 /var/run/docker.sock
```

### `docker compose` not found

Try legacy command:

```sh
docker-compose up -d --build
```

Or extend PATH:

```sh
export PATH=$PATH:/usr/local/bin:/var/packages/ContainerManager/target/usr/bin
```

## Optional: One-Liner Update From Mac

```bash
rsync -avz --delete -e "ssh -p 25" \
  web/src/ mbrucedogs@192.168.1.128:/volume1/docker/maneshtrader/ && \
ssh -p 25 mbrucedogs@192.168.1.128 \
  "sudo -i sh -lc 'cd /volume1/docker/maneshtrader && docker compose up -d --build'"
```
