Перейти к содержанию

Деплоймент

Локальный деплойment

1. Установка зависимостей

pip install -r requirements.txt

2. Настройка окружения

cp .env.example .env
# Отредактируйте .env файл

3. Запуск

python main.py

Docker деплойment

1. Создание Dockerfile

FROM python:3.10-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 3000

CMD ["python", "main.py"]

2. Сборка образа

docker build -t gemini-simplechat .

3. Запуск

docker run -p 3000:3000 -v $(pwd):/app gemini-simplechat

Продакшен деплойment

1. Настройка nginx

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /ws {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }
}

2. Настройка systemd

sudo nano /etc/systemd/system/gemini-simplechat.service
[Unit]
Description=gemini-simplechat Server
After=network.target

[Service]
User=your_user
WorkingDirectory=/path/to/gemini-simplechat
ExecStart=/path/to/gemini-simplechat/venv/bin/python main.py
Restart=always

[Install]
WantedBy=multi-user.target
sudo systemctl enable gemini-simplechat
sudo systemctl start gemini-simplechat

Kubernetes

1. deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: gemini-simplechat
spec:
  replicas: 3
  selector:
    matchLabels:
      app: gemini-simplechat
  template:
    metadata:
      labels:
        app: gemini-simplechat
    spec:
      containers:
      - name: gemini-simplechat
        image: gemini-simplechat:latest
        ports:
        - containerPort: 3000
        env:
        - name: GEMINI_API_KEY_NAMES
          valueFrom:
            secretKeyRef:
              name: gemini-secrets
              key: api-key
        - name: JWT_SECRET
          valueFrom:
            secretKeyRef:
              name: gemini-secrets
              key: jwt-secret

2. service.yaml

apiVersion: v1
kind: Service
metadata:
  name: gemini-simplechat
spec:
  selector:
    app: gemini-simplechat
  ports:
  - port: 80
    targetPort: 3000
  type: LoadBalancer

CI/CD

GitHub Actions workflow

name: Deploy to Production

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Setup Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.10'

    - name: Install dependencies
      run: pip install -r requirements.txt

    - name: Run tests
      run: pytest

    - name: Deploy
      run: |
        # Your deployment script

← Development | ← Назад в меню