Files
stock-analyzer/TRUENAS_DEPLOYMENT.md
T
2025-12-12 14:47:36 +01:00

100 lines
4.4 KiB
Markdown

# Deploying Stock Analyzer to TrueNAS Scale
This guide explains how to deploy the Stock Analyzer application to TrueNAS Scale using the "Custom App" feature.
## Prerequisites
1. **TrueNAS Scale** installed and running.
2. **Docker Hub Account**: You need an account to host your container images.
3. **Terminal Access**: Access to a terminal where you have the project code and Docker installed (to run the build script).
## Step 1: Build and Push Images
Before deploying, you need to build the Docker images and push them to Docker Hub so TrueNAS can download them.
1. Open your terminal in the project root.
2. Make the build script executable:
```bash
chmod +x build-and-push.sh
```
3. Run the script with your Docker Hub username and optional version tag:
```bash
./build-and-push.sh your_dockerhub_username [version]
```
*Replace `your_dockerhub_username` with your actual Docker Hub username. If version is omitted, it defaults to `latest`.*
Wait for the script to finish. It will build both backend and frontend images and push them to your account.
## Step 2: Deploy MongoDB
The application requires a MongoDB database.
1. Log in to your TrueNAS Scale web interface.
2. Go to **Apps**.
3. Click **Discover Apps**.
4. Search for **MongoDB** (or use the "Custom App" button if you prefer a raw container).
* **Recommended**: Use the official TrueCharts or iXsystems MongoDB chart if available for easier management.
* **Alternative (Custom App)**:
* Application Name: `mongodb`
* Image repository: `mongo`
* Image Tag: `latest`
* Port Forwarding: Container Port `27017` -> Node Port `27017` (or any available port).
* Storage: Configure a Host Path or PVC to `/data/db` to persist data.
## Step 3: Deploy Backend
1. Go to **Apps** -> **Discover Apps** -> **Custom App**.
2. **Application Name**: `stock-analyzer-backend`
3. **Container Image**:
* Repository: `your_dockerhub_username/stock-analyzer-backend`
* Tag: `latest`
4. **Port Forwarding**:
* Container Port: `8080`
* Node Port: `8080` (or another available port, e.g., `9000`. If you change this, remember it for the frontend config).
5. **Environment Variables**:
Add the following name/value pairs:
* `MONGO_URI`: `mongodb://<truenas-ip>:27017/stock_analyzer` (Replace `<truenas-ip>` with your TrueNAS IP address).
* `OPENAI_API_KEY`: Your OpenAI API Key.
* `OPENAI_MODEL`: `gpt-4o` (or your preferred model).
* `ANTHROPIC_API_KEY`: Your Anthropic API Key.
* `ANTHROPIC_MODEL`: `claude-3-5-sonnet-20240620` (or your preferred model).
* `NEWS_API_KEY`: Your NewsAPI Key.
6. **Save/Install**.
## Step 4: Deploy Frontend
1. Go to **Apps** -> **Discover Apps** -> **Custom App**.
2. **Application Name**: `stock-analyzer-frontend`
3. **Container Image**:
* Repository: `your_dockerhub_username/stock-analyzer-frontend`
* Tag: `latest`
4. **Port Forwarding**:
* Container Port: `80`
* Node Port: `3000` (or any available port you want to access the app from).
5. **Networking**:
* The frontend is an SPA (Single Page Application). It runs in the user's browser.
* **Important**: The frontend needs to know where the backend is.
* By default, the nginx config in the frontend container proxies `/api` calls to `http://backend:8080`.
* **TrueNAS Specific**: Since Kubernetes/Docker networking in TrueNAS can be complex for simple service discovery without a proper chart, you might need to adjust the Nginx configuration or use a reverse proxy (like Traefik) if the internal DNS `backend` doesn't resolve.
* **Simple Fix**: If the default proxying doesn't work, you might need to expose the backend directly and update the frontend code to point to the full URL, OR ensure both apps are in the same namespace/network where `backend` resolves.
*For a standard "Custom App" deployment where containers can't easily talk via DNS names like `backend`:*
You may need to update the `nginx.conf` in the source code to point to your TrueNAS IP and the Backend Node Port, then rebuild/push.
*Edit `frontend/nginx.conf` before building:*
```nginx
location /api {
proxy_pass http://<YOUR_TRUENAS_IP>:<BACKEND_NODE_PORT>;
...
}
```
6. **Save/Install**.
## Step 5: Access the Application
Open your browser and navigate to:
`http://<YOUR_TRUENAS_IP>:<FRONTEND_NODE_PORT>`
Example: `http://192.168.1.100:3000`