Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
file: ./ops/docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
id: run-tests
continue-on-error: true
run: |
npm run build/start-server.js &
node build/start-server.js &
echo "Waiting for gateway to start..."
while ! curl -s http://localhost:8787 > /dev/null; do
sleep 1
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ npx @portkey-ai/gateway

<sup>
Deployment guides:
&nbsp; <a href="./ops/README.md">Ops</a>
&nbsp; <a href="https://portkey.wiki/gh-18"><img height="12" width="12" src="https://cfassets.portkey.ai/logo/dew-color.svg" /> Portkey Cloud (Recommended)</a>
&nbsp; <a href="./docs/installation-deployments.md#docker"><img height="12" width="12" src="https://cdn.simpleicons.org/docker/3776AB" /> Docker</a>
&nbsp; <a href="./docs/installation-deployments.md#nodejs-server"><img height="12" width="12" src="https://cdn.simpleicons.org/node.js/3776AB" /> Node.js</a>
Expand Down
4 changes: 2 additions & 2 deletions docs/installation-deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Save the response in a YAML file for later use.

3. Copy the deployment YAML
```shell
wget https://raw.githubusercontent.com/Portkey-AI/gateway/main/deployment.yaml
wget https://raw.githubusercontent.com/Portkey-AI/gateway/main/ops/kubernetes/deployment.yaml
```

4. Apply the manifest
Expand Down Expand Up @@ -220,7 +220,7 @@ For more information on the Docker image, check [here](https://hub.docker.com/r/
1. Download Compose File from the Repository:

```sh
wget "https://raw.githubusercontent.com/Portkey-AI/gateway/main/docker-compose.yaml"
wget "https://raw.githubusercontent.com/Portkey-AI/gateway/main/ops/docker/docker-compose.yaml"
```

2. Run:
Expand Down
167 changes: 167 additions & 0 deletions ops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Ops: deploy and automation

Эта директория собирает инфраструктурные файлы Gateway в одном месте.

## Что где лежит

- `docker/Dockerfile` - сборка production-образа для Node.js runtime.
- `docker/Dockerfile.dockerignore` - ignore-файл для Docker build context.
- `docker/docker-compose.yaml` - запуск опубликованного образа через Docker Compose.
- `docker/docker-compose.local.yaml` - локальная сборка и запуск текущего checkout через Docker Compose.
- `kubernetes/deployment.yaml` - namespace, Deployment и Service для Kubernetes.
- `cloudflare/wrangler.toml` - конфигурация Cloudflare Workers.
- `automation/github/workflows/` - копии GitHub Actions для публикации, тестов, форматирования и triage.
- `automation/husky/` - копии локальных git hooks.

Важно: рабочие GitHub Actions остаются в `.github/workflows`, а рабочие husky hooks - в `.husky`. GitHub и husky запускают автоматизацию только из этих системных путей; копии в `ops/automation` нужны как единая точка обзора.

## Локальный запуск через Node.js

Требования:

- Node.js 20.x
- npm

Команды:

```sh
npm install
npm run build
npm run start:node
```

Gateway будет доступен:

- API: `http://localhost:8787/v1`
- локальная консоль логов: `http://localhost:8787/public/`

Для разработки без предварительной сборки:

```sh
npm run dev:node
```

Если нужен другой порт:

```sh
node build/start-server.js --port=8790
```

## Локальный запуск через Docker

Собрать образ из текущего репозитория:

```sh
docker build -f ops/docker/Dockerfile -t portkey-gateway:local .
docker run --rm -p 8787:8787 portkey-gateway:local
```

Собрать и запустить текущий код через Compose:

```sh
docker compose -f ops/docker/docker-compose.local.yaml up -d
docker compose -f ops/docker/docker-compose.local.yaml logs -f
```

Запустить опубликованный образ без сборки:

```sh
docker run --rm -p 8787:8787 portkeyai/gateway:latest
docker compose -f ops/docker/docker-compose.yaml up -d
```

Остановить:

```sh
docker compose -f ops/docker/docker-compose.local.yaml down
docker compose -f ops/docker/docker-compose.yaml down
```

## Проверка после запуска

Быстрая проверка, что сервер отвечает:

```sh
curl http://localhost:8787
```

Пример запроса к OpenAI-compatible endpoint:

```sh
curl http://localhost:8787/v1/chat/completions \
-H "content-type: application/json" \
-H "x-portkey-provider: openai" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Say gateway is working"}],
"max_tokens": 20
}'
```

Ключи провайдеров не нужно хранить в репозитории. Передавайте их через заголовки запроса, переменные окружения или внешний secret manager.

## Cloudflare Workers

Локальный dev-server Cloudflare Workers:

```sh
npm install
npm run dev
```

Deploy в Cloudflare:

```sh
npm run deploy
```

Скрипты `dev` и `deploy` уже используют конфиг `ops/cloudflare/wrangler.toml`.

## Kubernetes

Применить манифест:

```sh
kubectl apply -f ops/kubernetes/deployment.yaml
```

Проверить:

```sh
kubectl get pods -n portkeyai
kubectl get svc -n portkeyai
```

Для локального доступа через port-forward:

```sh
kubectl port-forward -n portkeyai svc/portkeyai 8787:8787
```

Удалить ресурсы:

```sh
kubectl delete -f ops/kubernetes/deployment.yaml
```

## Автоматизация

Активная автоматизация проекта:

- `.github/workflows/check_code_formatting.yml` - проверка Prettier на pull request в `main`.
- `.github/workflows/docker_publish.yml` - публикация Docker image в Docker Hub при GitHub release.
- `.github/workflows/npm_publish.yml` - публикация npm package при GitHub release.
- `.github/workflows/run_tests.yml` - запуск gateway tests по комментарию `run tests` в PR.
- `.github/workflows/link-checker.yml` - проверка markdown-ссылок.
- `.github/workflows/triage-label.yml` - автоматическая метка `triage` на новых issues.
- `.husky/pre-commit` - проверка форматирования, с попыткой автоформата.
- `.husky/pre-push` - `npm run pre-push`, то есть build и тестовый запуск.

Для локальной проверки перед push:

```sh
npm run format:check
npm run build
npm run test:gateway
```
25 changes: 25 additions & 0 deletions ops/automation/github/workflows/check_code_formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Check Prettier Formatting

on:
pull_request:
branches:
- main

jobs:
check-formatting:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20.x'

- name: Install dependencies
run: npm install

- name: Check formatting
run: npm run format:check
44 changes: 44 additions & 0 deletions ops/automation/github/workflows/docker_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish Docker image

on:
release:
types: [published]

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_ORGANISATION }}/gateway
tags: |
type=raw,value=latest
type=pep440,pattern={{version}},value=${{ github.event.release.tag_name }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./ops/docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
51 changes: 51 additions & 0 deletions ops/automation/github/workflows/link-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Check Markdown links

on:
push:
paths:
- '**/*.md' # Only run when markdown files change
pull_request:
branches:
- main
schedule:
- cron: '0 0 * * 0' # Run weekly on Sundays
workflow_dispatch: # Allows manual triggering

jobs:
linkChecker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Link Checker
uses: lycheeverse/lychee-action@v1.8.0
with:
args: --verbose --no-progress './**/*.md'
fail: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Issue If Failed
if: failure()
uses: actions/github-script@v6
with:
script: |
const title = '🔗 Broken links found in documentation';
const body = 'The link checker found broken links in the documentation. Please check the [workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.';

const existingIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'documentation,broken-links',
});

const issueExists = existingIssues.data.some(issue => issue.title === title);
if (!issueExists) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['documentation', 'broken-links']
});
}
21 changes: 21 additions & 0 deletions ops/automation/github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish to NPM
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Publish package on NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading