Skip to content

Commit

Permalink
feat: add ai proxy (#1506)
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks authored Oct 29, 2024
1 parent bc2f063 commit 7401ede
Show file tree
Hide file tree
Showing 39 changed files with 1,931 additions and 107 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/ai-proxy-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CD / AI Proxy

on:
pull_request:
branches:
- "master"
paths:
- "go/ai-proxy/**"
push:
tags:
- 'v*.*.*'

permissions:
contents: read

env:
GOPATH: /home/runner/go
GOBIN: /home/runner/go/bin
GOPROXY: "https://proxy.golang.org"

jobs:
test:
name: Unit test
runs-on: ubuntu-20.04
defaults:
run:
shell: bash
working-directory: go/ai-proxy
timeout-minutes: 5
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
go-version-file: go/ai-proxy/go.mod
cache: true
- run: go mod download
- run: PATH=$PATH:$GOPATH/bin make --directory=.. tools
- run: PATH=$PATH:$GOPATH/bin make test

publish-docker:
name: Build and push ai-proxy container
runs-on: ubuntu-20.04
defaults:
run:
shell: bash
working-directory: go/ai-proxy
needs: [ test ]
permissions:
contents: 'read'
id-token: 'write'
packages: 'write'
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/pluralsh/ai-proxy
gcr.io/pluralsh/ai-proxy
docker.io/pluralsh/ai-proxy
tags: |
type=sha
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}},priority=1000
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: google-github-actions/auth@v1
with:
workload_identity_provider: 'projects/${{ secrets.GOOGLE_PROJECT_ID }}/locations/global/workloadIdentityPools/github/providers/github'
service_account: '[email protected]'
token_format: 'access_token'
create_credentials_file: true
- uses: google-github-actions/[email protected]
- run: gcloud auth configure-docker -q
- uses: docker/login-action@v3
with:
username: mjgpluralsh
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- uses: docker/setup-qemu-action@v3
- uses: docker/[email protected]
- uses: docker/[email protected]
with:
context: "./go/ai-proxy"
file: "./go/ai-proxy/Dockerfile"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
GIT_COMMIT=${{ github.sha }}
VERSION=${{ steps.meta.outputs.version }}
59 changes: 59 additions & 0 deletions .github/workflows/ai-proxy-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI / AI Proxy

on:
push:
branches:
- "master"
paths:
- ".github/workflows/ai-proxy-ci.yaml"
- "go/ai-proxy/**"
pull_request:
branches:
- "**"
paths:
- ".github/workflows/ai-proxy-ci.yaml"
- "go/ai-proxy/**"
-
permissions:
contents: read

env:
GOPATH: /home/runner/go/
GOPROXY: "https://proxy.golang.org"

jobs:
build:
name: Build
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: go/ai-proxy
timeout-minutes: 5
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
go-version-file: go/ai-proxy/go.mod
cache: true
- run: go mod download
- run: PATH=$PATH:$GOPATH/bin make --directory=.. tools
- run: PATH=$PATH:$GOPATH/bin make build

check:
name: Check
runs-on: ubuntu-20.04
defaults:
run:
shell: bash
working-directory: go/ai-proxy
timeout-minutes: 5
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
go-version-file: go/ai-proxy/go.mod
cache: true
- run: go mod download
- run: PATH=$PATH:$GOPATH/bin make --directory=.. tools
- run: PATH=$PATH:$GOPATH/bin make check
23 changes: 23 additions & 0 deletions charts/ai-proxy/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/ai-proxy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: ai-proxy
description: A Helm chart for ai-proxy

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v1.0.0"
62 changes: 62 additions & 0 deletions charts/ai-proxy/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ai-proxy.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "ai-proxy.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "ai-proxy.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "ai-proxy.labels" -}}
helm.sh/chart: {{ include "ai-proxy.chart" . }}
{{ include "ai-proxy.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "ai-proxy.selectorLabels" -}}
app.kubernetes.io/name: {{ include "ai-proxy.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "ai-proxy.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "ai-proxy.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
94 changes: 94 additions & 0 deletions charts/ai-proxy/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ai-proxy.fullname" . }}
labels:
{{- include "ai-proxy.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "ai-proxy.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "ai-proxy.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- --provider={{ .Values.config.provider }}
- --provider-host={{ .Values.config.providerHost }}
{{- with .Values.args }}
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
{{- with .Values.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}

{{- with .Values.livenessProbe }}
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}

resources:
{{- toYaml .Values.resources | nindent 12 }}

env:
{{- toYaml .Values.env | nindent 12 }}

envFrom:
- secretRef:
name: {{ include "ai-proxy.fullname" . }}-env
{{- with .Values.envFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}

{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}

{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}

{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}

{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}

{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
32 changes: 32 additions & 0 deletions charts/ai-proxy/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "ai-proxy.fullname" . }}
labels:
{{- include "ai-proxy.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "ai-proxy.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Loading

0 comments on commit 7401ede

Please sign in to comment.