# Deployment Guide This guide covers deploying the Multi-API Server to Dokku on your production server. ## Prerequisites - Dokku server running on 104.248.219.197 - Domain configured: app.lobott.com with wildcard DNS - SSH access to the server - Git repository with your application code ## Deployment Steps ### 1. Prepare Your Application Ensure your application has the required files: - `package.json` with proper dependencies and scripts - `Procfile` specifying how to start your app - `app.js` as your main application file ### 2. Create Dokku App SSH into your server and create the application: ```bash ssh root@104.248.219.197 dokku apps:create api ``` ### 3. Add Git Remote From your local project directory: ```bash git remote add dokku dokku@104.248.219.197:api ``` ### 4. Deploy Application Push your code to Dokku: ```bash git push dokku main ``` ### 5. Configure Domain Add your custom domain: ```bash ssh root@104.248.219.197 dokku domains:add api api.app.lobott.com ``` ### 6. Enable SSL Enable Let's Encrypt SSL certificate: ```bash dokku letsencrypt:enable api ``` ## Environment Configuration Set any required environment variables: ```bash dokku config:set api NODE_ENV=production dokku config:set api PORT=3000 ``` ## Verification After deployment, verify your application: 1. **Health Check**: Visit https://api.app.lobott.com/health 2. **API Endpoints**: Test https://api.app.lobott.com/api 3. **Web Interface**: Check https://api.app.lobott.com ## Troubleshooting ### Common Issues **Build Fails** - Check your `package.json` for correct dependencies - Ensure `Procfile` has the correct start command - Verify Node.js version compatibility **App Won't Start** - Check logs: `dokku logs api --tail` - Verify port configuration in your app - Ensure all dependencies are properly installed **SSL Issues** - Verify domain DNS points to your server - Check Let's Encrypt status: `dokku letsencrypt:list` - Retry SSL: `dokku letsencrypt:enable api` ### Manual Recovery If standard deployment fails, use manual Docker method: ```bash # Create deployment archive tar -czf app.tar.gz --exclude='.git' --exclude='node_modules' . # Upload to server scp app.tar.gz root@104.248.219.197:/tmp/ # Manual Docker deployment ssh root@104.248.219.197 ' cd /tmp && rm -rf api-deploy && mkdir api-deploy && cd api-deploy && tar -xzf /tmp/app.tar.gz && docker build -t dokku/api:new . && docker stop api.web.1 2>/dev/null || true && docker rm api.web.1 2>/dev/null || true && docker run -d --name api.web.1 --restart=always -p 3000 --label=dokku=api dokku/api:new npm start ' ``` ## Updates and Maintenance ### Deploying Updates ```bash # Make changes to your code git add . git commit -m "Update: description of changes" # Deploy updates git push dokku main ``` ### Monitoring - **Logs**: `dokku logs api --tail` - **Status**: `dokku ps:report api` - **Health**: `curl https://api.app.lobott.com/health` ### Scaling If needed, scale your application: ```bash dokku ps:scale api web=2 ``` ## Auto-Recovery Setup For automatic recovery after server restarts, consider setting up a systemd service similar to your Thai Rhyme API setup. Create `/etc/systemd/system/api-auto-recovery.service`: ```ini [Unit] Description=Multi-API Auto-Recovery Service After=docker.service Requires=docker.service [Service] Type=oneshot ExecStartPre=/bin/sleep 30 ExecStart=/usr/local/bin/api-auto-fix.sh RemainAfterExit=true [Install] WantedBy=multi-user.target ``` ## Security Considerations - Keep dependencies updated - Monitor logs for unusual activity - Use environment variables for sensitive data - Enable firewall rules as needed ## Performance Optimization - Use compression middleware (already included) - Monitor memory usage via `/api/stats` - Consider scaling horizontally if traffic increases - Use nginx caching if needed (handled by Dokku) This deployment pattern follows the same proven approach used for your Thai Rhyme API, ensuring reliability and consistency.