From 5b05f9572879b0d9b939f0fbd2cd1eddc07fdb05 Mon Sep 17 00:00:00 2001 From: Dolpher Du Date: Thu, 18 Jul 2024 09:14:06 +0000 Subject: [PATCH] Add CodeTrans helm chart Signed-off-by: Dolpher Du --- helm-charts/codetrans/.helmignore | 23 +++++++ helm-charts/codetrans/Chart.yaml | 16 +++++ helm-charts/codetrans/README.md | 45 ++++++++++++ helm-charts/codetrans/gaudi-values.yaml | 59 ++++++++++++++++ helm-charts/codetrans/templates/_helpers.tpl | 62 +++++++++++++++++ .../codetrans/templates/deployment.yaml | 68 +++++++++++++++++++ helm-charts/codetrans/templates/service.yaml | 18 +++++ .../codetrans/templates/tests/test-pod.yaml | 24 +++++++ helm-charts/codetrans/values.yaml | 53 +++++++++++++++ 9 files changed, 368 insertions(+) create mode 100644 helm-charts/codetrans/.helmignore create mode 100644 helm-charts/codetrans/Chart.yaml create mode 100644 helm-charts/codetrans/README.md create mode 100644 helm-charts/codetrans/gaudi-values.yaml create mode 100644 helm-charts/codetrans/templates/_helpers.tpl create mode 100644 helm-charts/codetrans/templates/deployment.yaml create mode 100644 helm-charts/codetrans/templates/service.yaml create mode 100644 helm-charts/codetrans/templates/tests/test-pod.yaml create mode 100644 helm-charts/codetrans/values.yaml diff --git a/helm-charts/codetrans/.helmignore b/helm-charts/codetrans/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/helm-charts/codetrans/.helmignore @@ -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/ diff --git a/helm-charts/codetrans/Chart.yaml b/helm-charts/codetrans/Chart.yaml new file mode 100644 index 00000000..b6082615 --- /dev/null +++ b/helm-charts/codetrans/Chart.yaml @@ -0,0 +1,16 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v2 +name: codetrans +description: The Helm chart to deploy CodeTrans +type: application +dependencies: + - name: tgi + version: 0.8.0 + repository: "file://../common/tgi" + - name: llm-uservice + version: 0.8.0 + repository: "file://../common/llm-uservice" +version: 0.8.0 +appVersion: "1.0.0" diff --git a/helm-charts/codetrans/README.md b/helm-charts/codetrans/README.md new file mode 100644 index 00000000..b55ab0eb --- /dev/null +++ b/helm-charts/codetrans/README.md @@ -0,0 +1,45 @@ +# CodeTrans + +Helm chart for deploying CodeTrans service. + +CodeTrans depends on LLM microservice, refer to llm-uservice for more config details. + +## Installing the Chart + +To install the chart, run the following: + +```console +cd GenAIInfra/helm-charts/ +./update_dependency.sh +helm dependency update codetrans +export HFTOKEN="insert-your-huggingface-token-here" +export MODELDIR="/mnt/opea-models" +export MODELNAME="HuggingFaceH4/mistral-7b-grok" +helm install codetrans codetrans --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set global.modelUseHostPath=${MODELDIR} --set tgi.LLM_MODEL_ID=${MODELNAME} +# To use Gaudi device +# helm install codetrans codetrans --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --values codetrans/gaudi-values.yaml +``` + +## Verify + +To verify the installation, run the command `kubectl get pod` to make sure all pods are running. + +Then run the command `kubectl port-forward svc/codetrans 7777:7777` to expose the CodeTrans service for access. + +Open another terminal and run the following command to verify the service if working: + +```console +curl http://localhost:7777/v1/codetrans \ + -H 'Content-Type: application/json' \ + -d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}' +``` + +## Values + +| Key | Type | Default | Description | +| ------------------------------- | ------ | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| image.repository | string | `"opea/codetrans:latest"` | | +| service.port | string | `"7777"` | | +| global.HUGGINGFACEHUB_API_TOKEN | string | `""` | Your own Hugging Face API token | +| global.modelUseHostPath | string | `"/mnt/opea-models"` | Cached models directory, tgi will not download if the model is cached here. The host path "modelUseHostPath" will be mounted to container as /data directory | +| tgi.LLM_MODEL_ID | string | `"HuggingFaceH4/mistral-7b-grok"` | Models id from https://huggingface.co/, or predownloaded model directory | diff --git a/helm-charts/codetrans/gaudi-values.yaml b/helm-charts/codetrans/gaudi-values.yaml new file mode 100644 index 00000000..39f141d0 --- /dev/null +++ b/helm-charts/codetrans/gaudi-values.yaml @@ -0,0 +1,59 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# Default values for codetrans. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 +LLM_SERVICE_HOST_IP: "" + +image: + repository: opea/codetrans:latest + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + # tag: "1.0" + +port: 7777 +service: + type: ClusterIP + port: 7777 + +securityContext: + readOnlyRootFilesystem: true + allowPrivilegeEscalation: false + runAsNonRoot: true + runAsUser: 1000 + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + +# To override values in subchart llm-uservice +llm-uservice: + image: + repository: opea/llm-tgi:latest + service: + port: 9000 +# To override values in subchart tgi +tgi: + LLM_MODEL_ID: HuggingFaceH4/mistral-7b-grok + # LLM_MODEL_ID: /data/Magicoder-S-DS-6.7B + image: + repository: ghcr.io/huggingface/tgi-gaudi + tag: "2.0.1" + resources: + limits: + habana.ai/gaudi: 1 + +global: + http_proxy: "" + https_proxy: "" + no_proxy: "" + HUGGINGFACEHUB_API_TOKEN: "insert-your-huggingface-token-here" + LANGCHAIN_TRACING_V2: false + LANGCHAIN_API_KEY: "insert-your-langchain-key-here" + # set modelUseHostPath to host directory if you want to use hostPath volume for model storage + # comment out modeluseHostPath if you want to download the model from huggingface + modelUseHostPath: /mnt/opea-models diff --git a/helm-charts/codetrans/templates/_helpers.tpl b/helm-charts/codetrans/templates/_helpers.tpl new file mode 100644 index 00000000..452ed1a9 --- /dev/null +++ b/helm-charts/codetrans/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "codetrans.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 "codetrans.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 "codetrans.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "codetrans.labels" -}} +helm.sh/chart: {{ include "codetrans.chart" . }} +{{ include "codetrans.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "codetrans.selectorLabels" -}} +app.kubernetes.io/name: {{ include "codetrans.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "codetrans.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "codetrans.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/helm-charts/codetrans/templates/deployment.yaml b/helm-charts/codetrans/templates/deployment.yaml new file mode 100644 index 00000000..e7195e98 --- /dev/null +++ b/helm-charts/codetrans/templates/deployment.yaml @@ -0,0 +1,68 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "codetrans.fullname" . }} + labels: + {{- include "codetrans.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "codetrans.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "codetrans.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Release.Name }} + env: + - name: LLM_SERVICE_HOST_IP + {{- if .Values.LLM_SERVICE_HOST_IP }} + value: {{ .Values.LLM_SERVICE_HOST_IP | quote}} + {{- else }} + value: {{ .Release.Name }}-llm-uservice + {{- end }} + #- name: MEGA_SERVICE_PORT + # value: {{ .Values.port }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + volumeMounts: + - mountPath: /tmp + name: tmp + ports: + - name: codetrans + containerPort: {{ .Values.port }} + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: tmp + emptyDir: {} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/helm-charts/codetrans/templates/service.yaml b/helm-charts/codetrans/templates/service.yaml new file mode 100644 index 00000000..bf3d1ecb --- /dev/null +++ b/helm-charts/codetrans/templates/service.yaml @@ -0,0 +1,18 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v1 +kind: Service +metadata: + name: {{ include "codetrans.fullname" . }} + labels: + {{- include "codetrans.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.port }} + protocol: TCP + name: codetrans + selector: + {{- include "codetrans.selectorLabels" . | nindent 4 }} diff --git a/helm-charts/codetrans/templates/tests/test-pod.yaml b/helm-charts/codetrans/templates/tests/test-pod.yaml new file mode 100644 index 00000000..780d1f11 --- /dev/null +++ b/helm-charts/codetrans/templates/tests/test-pod.yaml @@ -0,0 +1,24 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "codetrans.fullname" . }}-testpod" + labels: + {{- include "codetrans.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test + #"helm.sh/hook-delete-policy": "hook-succeeded, hook-failure" +spec: + containers: + - name: curl + image: alpine/curl + #image: python:3.10.14 + command: ['sh', '-c'] + args: + - | + curl http://{{ include "codetrans.fullname" . }}:{{ .Values.service.port }}/v1/codetrans -sS --fail-with-body \ + -H 'Content-Type: application/json' \ + -d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}' + restartPolicy: Never diff --git a/helm-charts/codetrans/values.yaml b/helm-charts/codetrans/values.yaml new file mode 100644 index 00000000..1bbd97bd --- /dev/null +++ b/helm-charts/codetrans/values.yaml @@ -0,0 +1,53 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# Default values for codetrans. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 +LLM_SERVICE_HOST_IP: "" + +image: + repository: opea/codetrans:latest + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + # tag: "1.0" + +port: 7777 +service: + type: ClusterIP + port: 7777 + +securityContext: + readOnlyRootFilesystem: true + allowPrivilegeEscalation: false + runAsNonRoot: true + runAsUser: 1000 + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + +# To override values in subchart llm-uservice +llm-uservice: + image: + repository: opea/llm-tgi:latest + service: + port: 9000 +# To override values in subchart tgi +tgi: + LLM_MODEL_ID: HuggingFaceH4/mistral-7b-grok + # LLM_MODEL_ID: /data/OpenCodeInterpreter-DS-6.7B + +global: + http_proxy: "" + https_proxy: "" + no_proxy: "" + HUGGINGFACEHUB_API_TOKEN: "insert-your-huggingface-token-here" + LANGCHAIN_TRACING_V2: false + LANGCHAIN_API_KEY: "insert-your-langchain-key-here" + # set modelUseHostPath to host directory if you want to use hostPath volume for model storage + # comment out modeluseHostPath if you want to download the model from huggingface + modelUseHostPath: /mnt/opea-models