Spaces:
Build error
Build error
Jawad Ali Yousafzai
commited on
Commit
Β·
d5decf5
1
Parent(s):
20c8fc2
render
Browse files- DEPLOY.md +52 -89
- Dockerfile +42 -0
- apps/backend/server.js +1 -1
- render.yaml +9 -0
DEPLOY.md
CHANGED
|
@@ -2,115 +2,78 @@
|
|
| 2 |
|
| 3 |
## π Deployment Options
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
- Go to https://railway.app
|
| 11 |
-
- Sign up with GitHub
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
- Choose your repository
|
| 17 |
-
- Railway will auto-detect the Node.js app
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
- Go to https://vercel.com
|
| 31 |
-
- Sign up with GitHub
|
| 32 |
|
| 33 |
-
|
| 34 |
-
- Click "New Project"
|
| 35 |
-
- Import your GitHub repository
|
| 36 |
-
- Framework Preset: Vite
|
| 37 |
-
- Root Directory: `apps/frontend`
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
- Install Command: `npm install`
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 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
|
| 69 |
-
- β
|
| 70 |
-
- β
|
| 71 |
-
- β
|
| 72 |
-
- β
|
| 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 |
-
|
| 84 |
-
- Use a buildpack that includes Python
|
| 85 |
|
| 86 |
-
|
| 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.
|
| 96 |
-
2.
|
| 97 |
-
3.
|
| 98 |
|
| 99 |
## π Troubleshooting
|
| 100 |
|
| 101 |
-
**
|
| 102 |
-
-
|
| 103 |
-
-
|
| 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
|