SuperAPI AI 工具集

enter-services

部署与运维

查看项目

更新于 10-16 08:23

技能介绍

用途

该技能用于部署和管理 enter.pollinations.ai 的文本与图像服务,运行环境为 EC2 实例,并通过 Cloudflare Worker 作为网关进行路由。

使用前提

使用前需确保具备以下条件:

  • SSH 密钥:通过 GitHub secrets 配置(参见 workflow)
  • sops:使用 brew install sops 安装(用于解密密钥)
  • Wrangler:使用 npm install -g wrangler 安装
  • Node.js:使用 brew install node 安装
  • 必须在 pollinations 仓库根目录运行

架构概览

环境 网关(Cloudflare Worker) 文本/图像服务(EC2)
生产 enter.pollinations.ai 3.80.56.235(端口 16384/16385)
预发 staging.enter.pollinations.ai 44.222.254.250(端口 16384/16385)

SSH 配置

在 ~/.ssh/config 中添加:

# Production instance
Host enter-services
  HostName 3.80.56.235
  User ubuntu
  IdentityFile ~/.ssh/enter-services-shared-key

# Staging instance
Host enter-services-staging
  HostName 44.222.254.250
  User ubuntu
  IdentityFile ~/.ssh/enter-services-staging-key

常用命令

生产环境

# Service status
ssh enter-services "sudo systemctl status text-pollinations.service image-pollinations.service"

# View logs (real-time)
ssh enter-services "sudo journalctl -u text-pollinations.service -f"
ssh enter-services "sudo journalctl -u image-pollinations.service -f"

# Restart services
ssh enter-services "sudo systemctl restart text-pollinations.service image-pollinations.service"

# Recent errors
ssh enter-services "sudo journalctl -u text-pollinations.service -p err -n 20"

预发环境

# Service status
ssh enter-services-staging "sudo systemctl status text-pollinations.service image-pollinations.service"

# View logs
ssh enter-services-staging "sudo journalctl -u text-pollinations.service -f"

# Restart
ssh enter-services-staging "sudo systemctl restart text-pollinations.service image-pollinations.service"

部署到生产环境

GitHub workflow 会在推送到 production 分支时自动处理生产部署。

手动部署:

# 1. SSH into production
ssh enter-services

# 2. Pull and restart
cd /home/ubuntu/pollinations
git pull origin production
cd text.pollinations.ai && npm install
cd ../image.pollinations.ai && npm install
sudo systemctl restart text-pollinations.service image-pollinations.service

部署到预发环境

完整搭建(新实例)

# 1. SSH into the new instance
ssh enter-services-staging

# 2. Install build tools (if needed)
sudo apt-get update && sudo apt-get install -y build-essential

# 3. Clone repo
git clone https://github.com/pollinations/pollinations.git
cd pollinations

# 4. Run setup script
bash enter.pollinations.ai/scripts/setup-services.sh /home/ubuntu/pollinations

# 5. From your LOCAL machine - decrypt and copy env files
cd /path/to/pollinations
sops --output-type dotenv -d text.pollinations.ai/secrets/env.json > /tmp/text.env
sops --output-type dotenv -d image.pollinations.ai/secrets/env.json > /tmp/image.env
scp /tmp/text.env enter-services-staging:/home/ubuntu/pollinations/text.pollinations.ai/.env
scp /tmp/image.env enter-services-staging:/home/ubuntu/pollinations/image.pollinations.ai/.env
rm /tmp/text.env /tmp/image.env

# 6. Restart services
ssh enter-services-staging "sudo systemctl restart text-pollinations.service image-pollinations.service"

更新预发环境

ssh enter-services-staging "cd /home/ubuntu/pollinations && git pull && cd text.pollinations.ai && npm install && cd ../image.pollinations.ai && npm install && sudo systemctl restart text-pollinations.service image-pollinations.service"

部署 Cloudflare Worker(enter.pollinations.ai)

cd enter.pollinations.ai

# Production
npm run deploy:production

# Staging
npm run deploy:staging

服务位置(EC2 上)

  • 服务定义:/etc/systemd/system/
  • 文本服务:/home/ubuntu/pollinations/text.pollinations.ai/
  • 图像服务:/home/ubuntu/pollinations/image.pollinations.ai/

Wrangler 配置

wrangler.toml 包含环境配置:

环境 路由 服务 URL
production enter.pollinations.ai 生产 EC2
staging staging.enter.pollinations.ai 预发 EC2
local localhost:3000 本地开发

故障排查

服务无法启动

# Check logs
ssh enter-services-staging "sudo journalctl -u text-pollinations.service -n 50"

# Check if .env exists
ssh enter-services-staging "ls -la /home/ubuntu/pollinations/text.pollinations.ai/.env"

# Check node/npm
ssh enter-services-staging "node -v && npm -v"

缺少依赖

ssh enter-services-staging "cd /home/ubuntu/pollinations/text.pollinations.ai && npm install"

需要构建工具

ssh enter-services-staging "sudo apt-get install -y build-essential"

注意事项

  • 推送到 production 分支时自动部署生产环境
  • 推送到 staging 分支时自动部署预发环境
  • 合并到生产环境前务必先在预发环境测试
  • Cloudflare Worker(enter.pollinations.ai)负责路由到 EC2 服务
  • 文本服务端口:16385,图像服务端口:16384