Jawad Ali Yousafzai commited on
Commit
d5decf5
Β·
1 Parent(s): 20c8fc2
Files changed (4) hide show
  1. DEPLOY.md +52 -89
  2. Dockerfile +42 -0
  3. apps/backend/server.js +1 -1
  4. render.yaml +9 -0
DEPLOY.md CHANGED
@@ -2,115 +2,78 @@
2
 
3
  ## πŸš€ Deployment Options
4
 
5
- ### Option 1: Railway (Backend) + Vercel (Frontend) - Recommended
6
 
7
- #### Deploy Backend to Railway:
8
 
9
- 1. **Create Railway Account**
10
- - Go to https://railway.app
11
- - Sign up with GitHub
12
 
13
- 2. **Create New Project**
14
- - Click "New Project"
15
- - Select "Deploy from GitHub repo"
16
- - Choose your repository
17
- - Railway will auto-detect the Node.js app
18
 
19
- 3. **Configure Environment**
20
- - No environment variables needed (custom API is external)
21
- - Railway will automatically install dependencies
 
 
22
 
23
- 4. **Deploy**
24
- - Railway will build and deploy automatically
25
- - Copy your Railway URL (e.g., `https://your-app.railway.app`)
 
 
 
26
 
27
- #### Deploy Frontend to Vercel:
 
 
28
 
29
- 1. **Create Vercel Account**
30
- - Go to https://vercel.com
31
- - Sign up with GitHub
32
 
33
- 2. **Import Project**
34
- - Click "New Project"
35
- - Import your GitHub repository
36
- - Framework Preset: Vite
37
- - Root Directory: `apps/frontend`
38
 
39
- 3. **Configure Build Settings**
40
- - Build Command: `npm run build`
41
- - Output Directory: `dist`
42
- - Install Command: `npm install`
43
 
44
- 4. **Add Environment Variable**
45
- - Name: `VITE_API_URL`
46
- - Value: Your Railway backend URL (e.g., `https://your-app.railway.app`)
 
 
 
47
 
48
- 5. **Deploy**
49
- - Click "Deploy"
50
- - Vercel will build and deploy your frontend
51
 
52
- ### Option 2: Railway Only (Full Stack)
53
-
54
- You can deploy both backend and frontend on Railway:
55
-
56
- 1. **Deploy Backend** (same as above)
57
-
58
- 2. **Deploy Frontend as Separate Service**
59
- - Create another Railway service
60
- - Point to same repo
61
- - Root Directory: `apps/frontend`
62
- - Build Command: `npm run build`
63
- - Start Command: `npx serve -s dist -l $PORT`
64
- - Add environment variable: `VITE_API_URL` = your backend URL
65
 
66
  ## πŸ“‹ Pre-Deployment Checklist
67
 
68
- - βœ… Removed OpenAI dependencies
69
- - βœ… Removed ElevenLabs dependencies
70
- - βœ… Using custom API for chat
71
- - βœ… Using local Python TTS
72
- - βœ… Health check endpoint added
73
- - βœ… CORS enabled for all origins
74
-
75
- ## πŸ”§ Important Notes
76
-
77
- ### Python Requirement
78
- The backend uses Python for TTS. Make sure Python is available in your deployment environment:
79
-
80
- **For Railway:**
81
- - Add a `nixpacks.toml` file (Railway auto-detects Python)
82
 
83
- **For Render/Other:**
84
- - Use a buildpack that includes Python
85
 
86
- ### Environment Variables
87
-
88
- **Backend:** None required (custom API URL is hardcoded)
89
-
90
- **Frontend:**
91
- - `VITE_API_URL` - Your backend URL
92
 
93
  ## πŸ§ͺ Testing After Deployment
94
 
95
- 1. Test backend health: `https://your-backend-url/health`
96
- 2. Test frontend: `https://your-frontend-url`
97
- 3. Send a message and verify avatar responds
98
 
99
  ## πŸ†˜ Troubleshooting
100
 
101
- **Backend Issues:**
102
- - Check Railway logs for Python errors
103
- - Verify `/health` endpoint returns 200
104
- - Check if TTS script is executable
105
-
106
- **Frontend Issues:**
107
- - Verify `VITE_API_URL` is set correctly
108
- - Check browser console for CORS errors
109
- - Ensure backend URL doesn't have trailing slash
110
-
111
- ## πŸ“± URLs After Deployment
112
-
113
- **Backend:** `https://your-app.railway.app`
114
- **Frontend:** `https://your-app.vercel.app`
115
-
116
- Share the frontend URL with anyone!
 
2
 
3
  ## πŸš€ Deployment Options
4
 
5
+ This project is configured to be deployed as a single Docker container, which hosts both the Node.js backend and the React frontend.
6
 
7
+ ### Option 1: Render (Recommended)
8
 
9
+ Render is a unified cloud to build and run all your apps and websites.
 
 
10
 
11
+ 1. **Create Render Account**
12
+ - Go to https://render.com
13
+ - Sign up with GitHub
 
 
14
 
15
+ 2. **Create New Web Service**
16
+ - Click "New +" -> "Web Service"
17
+ - Connect your GitHub repository
18
+ - Render should automatically detect the `render.yaml` or `Dockerfile`.
19
+ - If asked, choose **Docker** as the runtime.
20
 
21
+ 3. **Configuration**
22
+ - **Name**: `healbot-avatar` (or your choice)
23
+ - **Region**: Choose one close to you
24
+ - **Branch**: `main`
25
+ - **Runtime**: Docker
26
+ - **Plan**: Free (or higher)
27
 
28
+ 4. **Deploy**
29
+ - Click "Create Web Service"
30
+ - Render will build the Docker image (this may take a few minutes) and deploy it.
31
 
32
+ ### Option 2: Hugging Face Spaces
 
 
33
 
34
+ You can deploy this application to Hugging Face Spaces using their Docker SDK.
 
 
 
 
35
 
36
+ 1. **Create Hugging Face Account**
37
+ - Go to https://huggingface.co
38
+ - Sign up
 
39
 
40
+ 2. **Create New Space**
41
+ - Click on your profile -> "New Space"
42
+ - **Space Name**: `healbot-avatar`
43
+ - **License**: MIT (optional)
44
+ - **SDK**: Docker
45
+ - **Hardware**: CPU Basic (Free) is usually sufficient, but Upgrade if needed for faster TTS.
46
 
47
+ 3. **Upload Code**
48
+ - You can sync your GitHub repo with the Space, or push your code directly to the Space's repo.
49
+ - Ensure the `Dockerfile` is in the root directory.
50
 
51
+ 4. **Configuration**
52
+ - Hugging Face Spaces usually listen on port 7860. You might need to update the `Dockerfile` or `server.js` if HF doesn't map port 3000 automatically.
53
+ - **Note**: For Hugging Face, it is recommended to change the port in `apps/backend/server.js` to `7860` or use an environment variable.
54
+ - Add a variable `PORT` = `7860` in the Space Settings -> "Variables and secrets".
 
 
 
 
 
 
 
 
 
55
 
56
  ## πŸ“‹ Pre-Deployment Checklist
57
 
58
+ - βœ… Removed Vercel and Railway configurations
59
+ - βœ… Added `Dockerfile` for multi-stage build
60
+ - βœ… Added `render.yaml` for Render Blueprints
61
+ - βœ… Backend serves Frontend static files
62
+ - βœ… `edge-tts` and `ffmpeg` included in Docker image
 
 
 
 
 
 
 
 
 
63
 
64
+ ## πŸ”§ Environment Variables
 
65
 
66
+ **Render / Hugging Face:**
67
+ - `PORT`: Defaults to `3000`. Set to `7860` for Hugging Face if needed.
 
 
 
 
68
 
69
  ## πŸ§ͺ Testing After Deployment
70
 
71
+ 1. Open your deployed URL (e.g., `https://healbot-avatar.onrender.com` or `https://huggingface.co/spaces/username/healbot-avatar`)
72
+ 2. The frontend should load.
73
+ 3. Send a message. The backend should process it using `edge-tts` and return the audio and animation.
74
 
75
  ## πŸ†˜ Troubleshooting
76
 
77
+ - **Build Fails**: Check the logs. Ensure `ffmpeg` and `python` are correctly installed in the Docker image.
78
+ - **Audio Issues**: If TTS fails, check if `edge-tts` is working. The logs will show python errors.
79
+ - **Connection Refused**: Ensure the port matches the environment variable.
 
 
 
 
 
 
 
 
 
 
 
 
 
Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nikolaik/python-nodejs:python3.10-nodejs20
2
+
3
+ # Install ffmpeg
4
+ RUN apt-get update && apt-get install -y ffmpeg
5
+
6
+ WORKDIR /app
7
+
8
+ # Copy root package files
9
+ COPY package*.json ./
10
+
11
+ # Copy backend package files
12
+ COPY apps/backend/package*.json ./apps/backend/
13
+
14
+ # Copy frontend package files
15
+ COPY apps/frontend/package*.json ./apps/frontend/
16
+
17
+ # Install root dependencies
18
+ RUN npm install
19
+
20
+ # Install backend dependencies
21
+ WORKDIR /app/apps/backend
22
+ RUN npm install
23
+ RUN pip install edge-tts
24
+
25
+ # Install frontend dependencies
26
+ WORKDIR /app/apps/frontend
27
+ RUN npm install
28
+
29
+ # Copy source code
30
+ WORKDIR /app
31
+ COPY . .
32
+
33
+ # Build frontend
34
+ WORKDIR /app/apps/frontend
35
+ RUN npm run build
36
+
37
+ # Expose port
38
+ EXPOSE 3000
39
+
40
+ # Start backend
41
+ WORKDIR /app/apps/backend
42
+ CMD ["node", "server.js"]
apps/backend/server.js CHANGED
@@ -17,7 +17,7 @@ app.use(cors());
17
 
18
  // Serve static files from the frontend build directory
19
  app.use(express.static(path.join(__dirname, "../frontend/dist")));
20
- const port = 3000;
21
 
22
  // Helper function to select animation based on message content
23
  const selectAnimation = (message) => {
 
17
 
18
  // Serve static files from the frontend build directory
19
  app.use(express.static(path.join(__dirname, "../frontend/dist")));
20
+ const port = process.env.PORT || 3000;
21
 
22
  // Helper function to select animation based on message content
23
  const selectAnimation = (message) => {
render.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ services:
2
+ - type: web
3
+ name: healbot-avatar
4
+ env: docker
5
+ plan: free
6
+ dockerfilePath: ./Dockerfile
7
+ envVars:
8
+ - key: PORT
9
+ value: 3000