4.4 KiB
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
- TrueNAS Scale installed and running.
- Docker Hub Account: You need an account to host your container images.
- 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.
- Open your terminal in the project root.
- Make the build script executable:
chmod +x build-and-push.sh - Run the script with your Docker Hub username and optional version tag:
Replace
./build-and-push.sh your_dockerhub_username [version]your_dockerhub_usernamewith your actual Docker Hub username. If version is omitted, it defaults tolatest.
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.
- Log in to your TrueNAS Scale web interface.
- Go to Apps.
- Click Discover Apps.
- 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 Port27017(or any available port). - Storage: Configure a Host Path or PVC to
/data/dbto persist data.
- Application Name:
Step 3: Deploy Backend
- Go to Apps -> Discover Apps -> Custom App.
- Application Name:
stock-analyzer-backend - Container Image:
- Repository:
your_dockerhub_username/stock-analyzer-backend - Tag:
latest
- Repository:
- 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).
- Container Port:
- 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.
- Save/Install.
Step 4: Deploy Frontend
-
Go to Apps -> Discover Apps -> Custom App.
-
Application Name:
stock-analyzer-frontend -
Container Image:
- Repository:
your_dockerhub_username/stock-analyzer-frontend - Tag:
latest
- Repository:
-
Port Forwarding:
- Container Port:
80 - Node Port:
3000(or any available port you want to access the app from).
- Container Port:
-
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
/apicalls tohttp://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
backenddoesn'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
backendresolves.
For a standard "Custom App" deployment where containers can't easily talk via DNS names like
backend: You may need to update thenginx.confin the source code to point to your TrueNAS IP and the Backend Node Port, then rebuild/push.Edit
frontend/nginx.confbefore building:location /api { proxy_pass http://<YOUR_TRUENAS_IP>:<BACKEND_NODE_PORT>; ... } -
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