Skip to content

Latest commit

 

History

History
253 lines (195 loc) · 4.91 KB

File metadata and controls

253 lines (195 loc) · 4.91 KB

🚀 VPS Setup Guide - Connecting All the Dots

🎯 Overview

This guide will help you connect all the existing infrastructure (ffmpeg, GCS, rclone) with the thumbnail generator service.

✅ Prerequisites (Already Working)

  • ✅ ffmpeg installed and working
  • ✅ Google Cloud SDK (gsutil) configured
  • ✅ rclone configured for R2
  • ✅ GCP service account with storage access
  • ✅ R2 API tokens configured

🔧 Step-by-Step Setup

Step 1: Install Dependencies

# Navigate to the thumbnail service
cd yiku-thumbnail

# Install Node.js dependencies
npm install

# Create necessary directories
mkdir -p temp/videos temp/thumbnails credentials

Step 2: Configure Environment Variables

Create a .env file in the yiku-thumbnail directory:

# Create .env file
nano .env

Add the following content (replace with your actual values):

# Service Configuration
PORT=3000
NODE_ENV=production

# Disk Management
MAX_DISK_USAGE=80
CLEANUP_INTERVAL=300000

# Temp Directories
TEMP_DIR=./temp/videos
THUMBNAIL_DIR=./temp/thumbnails

# Google Cloud Platform Configuration
GOOGLE_APPLICATION_CREDENTIALS=./credentials/gcp-service-account.json
GCP_PROJECT_ID=your-gcp-project-id

# Cloudflare R2 Configuration
R2_ACCOUNT_ID=your-r2-account-id
R2_ACCESS_KEY_ID=your-r2-access-key-id
R2_SECRET_ACCESS_KEY=your-r2-secret-access-key
R2_BUCKET_NAME=your-r2-bucket-name
R2_PUBLIC_URL=https://your-public-domain.com

Step 3: Set Up Credentials

GCP Service Account

# Copy your existing GCP service account key
cp /path/to/your/gcp-service-account.json credentials/

# Set proper permissions
chmod 600 credentials/gcp-service-account.json

R2 Configuration

# Verify rclone configuration
rclone listremotes

# Should show: r2:

Step 4: Test the Service

Start the Service

# Start in development mode
npm run dev

# Or start in production mode
npm start

Test Endpoints

# Test health endpoint
curl http://localhost:3000/health

# Test status endpoint
curl http://localhost:3000/status

# Test thumbnail generation (replace with real data)
curl -X POST http://localhost:3000/generate \
  -H "Content-Type: application/json" \
  -d '{
    "video_url": "gs://your-bucket/your-video.mp4",
    "video_id": "test-video-123"
  }'

Step 5: Integration with n8n

Add HTTP Request Node in n8n

  1. Method: POST
  2. URL: http://localhost:3000/generate (or http://thumbnail-generator:3000/generate if using Docker)
  3. Headers: Content-Type: application/json
  4. Body: JSON
{
  "video_url": "{{ $json.video_url }}",
  "video_id": "{{ $json.video_id }}"
}

Handle Response

  • Check success field
  • Use thumbnailUrl if successful
  • Handle errors appropriately

🔍 Troubleshooting

Common Issues

  1. GCP Authentication Failed
# Check if service account key exists
ls -la credentials/gcp-service-account.json

# Test gcloud authentication
gcloud auth activate-service-account --key-file=credentials/gcp-service-account.json

# Test gsutil
gsutil ls gs://your-bucket/
  1. R2 Authentication Failed
# Check rclone configuration
rclone listremotes

# Test R2 connection
rclone lsd r2:

# Test upload to R2
rclone copy test.jpg r2:your-bucket/test.jpg
  1. ffmpeg Not Found
# Check ffmpeg installation
ffmpeg -version

# Install if needed
sudo apt-get update && sudo apt-get install -y ffmpeg
  1. Permission Issues
# Fix file permissions
chmod 600 credentials/gcp-service-account.json
chmod 755 temp/videos temp/thumbnails

# Check service permissions
ls -la temp/

Service Logs

# Check service logs
npm run dev

# Look for these key messages:
# ✅ GCP authentication successful
# ✅ R2 authentication successful
# Thumbnail generated successfully: [URL]
# Cleanup completed

🐳 Docker Deployment (Optional)

If you want to dockerize the service:

# Build the image
docker build -t yiku-thumbnail .

# Run with docker-compose
docker-compose up -d

# Check logs
docker-compose logs -f yiku-thumbnail

📊 Monitoring

Health Check

curl http://localhost:3000/health

Expected response:

{
  "status": "healthy",
  "diskUsage": "15%",
  "gcpAuth": true,
  "r2Auth": true,
  "timestamp": "2024-01-01T12:00:00.000Z"
}

Status Check

curl http://localhost:3000/status

Expected response:

{
  "diskUsage": "15%",
  "tempVideos": 0,
  "tempThumbnails": 0,
  "gcpAuth": true,
  "r2Auth": true,
  "timestamp": "2024-01-01T12:00:00.000Z"
}

🎯 Next Steps

  1. ✅ Test basic functionality
  2. 🔄 Configure real credentials
  3. 🐳 Dockerize for production (optional)
  4. 🔗 Integrate with n8n workflow
  5. 📊 Set up monitoring and alerts

📞 Support

If you encounter issues:

  1. Check the service logs
  2. Verify all prerequisites are installed
  3. Test each component individually
  4. Check the troubleshooting section above