Add Proxy Support for AI Services #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to VPS | |
| on: | |
| push: | |
| branches: [ "master" ] | |
| env: | |
| REGISTRY: ghcr.io | |
| # github.repository as <account>/<repo> | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| # ------------------------------------------------------------------ | |
| # ЭТАП 1: ПРОВЕРКА КОДА (CI) | |
| # ------------------------------------------------------------------ | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install flake8 | |
| # Если есть зависимости, нужные для линтинга, можно их поставить, | |
| # но для flake8 обычно достаточно самого кода. | |
| - name: Lint with flake8 | |
| run: | | |
| # stop the build if there are Python syntax errors or undefined names | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # exit-zero treats all errors as warnings. | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics | |
| # ------------------------------------------------------------------ | |
| # ЭТАП 2: СБОРКА И ПУШ ОБРАЗА (CD - Build) | |
| # ------------------------------------------------------------------ | |
| build-and-push: | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest | |
| type=sha | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| # ------------------------------------------------------------------ | |
| # ЭТАП 3: ДЕПЛОЙ НА VPS (CD - Deploy) | |
| # ------------------------------------------------------------------ | |
| deploy: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Execute remote ssh commands using key | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| # Приводим имя репозитория к нижнему регистру для Docker | |
| REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
| IMAGE_URL="ghcr.io/$REPO_LOWER:latest" | |
| echo "Deploying $IMAGE_URL..." | |
| # Логинимся в реестр | |
| echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| # Скачиваем образ | |
| docker pull $IMAGE_URL | |
| # Перезапускаем контейнер | |
| docker stop netwho || true | |
| docker rm netwho || true | |
| docker run -d \ | |
| --name netwho \ | |
| --restart unless-stopped \ | |
| --env-file /opt/netwho/.env \ | |
| $IMAGE_URL | |
| # Чистим старые образы | |
| docker image prune -f | |