AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(rnd, infra): Add deployment for backend (#7612)
Aarushi3d54a9103ce3
diff --git a/rnd/autogpt_server/autogpt_server/server/server.py b/rnd/autogpt_server/autogpt_server/server/server.pyindex b9dc12e951..31d5afaaad 100644--- a/rnd/autogpt_server/autogpt_server/server/server.py+++ b/rnd/autogpt_server/autogpt_server/server/server.py@@ -15,7 +15,6 @@ from fastapi import ()from fastapi.middleware.cors import CORSMiddlewarefrom fastapi.responses import JSONResponse-from fastapi.staticfiles import StaticFilesimport autogpt_server.server.ws_apifrom autogpt_server.data import block, db@@ -34,7 +33,6 @@ from autogpt_server.server.model import (SetGraphActiveVersion,WsMessage,)-from autogpt_server.util.data import get_frontend_pathfrom autogpt_server.util.lock import KeyedMutexfrom autogpt_server.util.service import AppService, expose, get_service_clientfrom autogpt_server.util.settings import Settings@@ -191,12 +189,6 @@ class AgentServer(AppService):app.add_exception_handler(500, self.handle_internal_error) # type: ignore- app.mount(- path="/frontend",- app=StaticFiles(directory=get_frontend_path(), html=True),- name="example_files",- )-app.include_router(router)@app.websocket("/ws")diff --git a/rnd/autogpt_server/autogpt_server/util/service.py b/rnd/autogpt_server/autogpt_server/util/service.pyindex 4d19225a86..d43bcc41c3 100644--- a/rnd/autogpt_server/autogpt_server/util/service.py+++ b/rnd/autogpt_server/autogpt_server/util/service.py@@ -11,11 +11,14 @@ from tenacity import retry, stop_after_delay, wait_exponentialfrom autogpt_server.data import dbfrom autogpt_server.util.process import AppProcess+from autogpt_server.util.settings import Configlogger = logging.getLogger(__name__)conn_retry = retry(stop=stop_after_delay(5), wait=wait_exponential(multiplier=0.1))T = TypeVar("T")+pyro_host = Config().pyro_host+def expose(func: Callable) -> Callable:def wrapper(*args, **kwargs):@@ -33,7 +36,7 @@ class PyroNameServer(AppProcess):def run(self):try:print("Starting NameServer loop")- nameserver.start_ns_loop()+ nameserver.start_ns_loop(host=pyro_host, port=9090)except KeyboardInterrupt:print("Shutting down NameServer")@@ -79,8 +82,8 @@ class AppService(AppProcess):@conn_retrydef __start_pyro(self):- daemon = pyro.Daemon()- ns = pyro.locate_ns()+ daemon = pyro.Daemon(host=pyro_host)+ ns = pyro.locate_ns(host=pyro_host, port=9090)uri = daemon.register(self)ns.register(self.service_name, uri)logger.warning(f"Service [{self.service_name}] Ready. Object URI = {uri}")diff --git a/rnd/autogpt_server/autogpt_server/util/settings.py b/rnd/autogpt_server/autogpt_server/util/settings.pyindex 6c00c25271..b9be013113 100644--- a/rnd/autogpt_server/autogpt_server/util/settings.py+++ b/rnd/autogpt_server/autogpt_server/util/settings.py@@ -53,6 +53,10 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):le=100,description="Maximum number of workers to use for node execution within a single graph.",)+ pyro_host: str = Field(+ default="localhost",+ description="The default hostname of the Pyro server.",+ )# Add more configuration fields as neededmodel_config = SettingsConfigDict(diff --git a/rnd/infra/helm/autogpt-server/.helmignore b/rnd/infra/helm/autogpt-server/.helmignorenew file mode 100644index 0000000000..0e8a0eb36f--- /dev/null+++ b/rnd/infra/helm/autogpt-server/.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/rnd/infra/helm/autogpt-server/Chart.yaml b/rnd/infra/helm/autogpt-server/Chart.yamlnew file mode 100644index 0000000000..5dd24327d4--- /dev/null+++ b/rnd/infra/helm/autogpt-server/Chart.yaml@@ -0,0 +1,10 @@+apiVersion: v2+name: autogpt-server+description: A Helm chart for AutoGPT on Kubernetes++type: application+++version: 0.1.0++appVersion: "1.0.0"diff --git a/rnd/infra/helm/autogpt-server/templates/NOTES.txt b/rnd/infra/helm/autogpt-server/templates/NOTES.txtnew file mode 100644index 0000000000..2b660011ad--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/NOTES.txt@@ -0,0 +1,22 @@+1. Get the application URL by running these commands:+{{- if .Values.ingress.enabled }}+{{- range $host := .Values.ingress.hosts }}+ {{- range .paths }}+ http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}+ {{- end }}+{{- end }}+{{- else if contains "NodePort" .Values.service.type }}+ export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "autogpt-server.fullname" . }})+ export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")+ echo http://$NODE_IP:$NODE_PORT+{{- else if contains "LoadBalancer" .Values.service.type }}+ NOTE: It may take a few minutes for the LoadBalancer IP to be available.+ You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "autogpt-server.fullname" . }}'+ export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "autogpt-server.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")+ echo http://$SERVICE_IP:{{ .Values.service.port }}+{{- else if contains "ClusterIP" .Values.service.type }}+ export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "autogpt-server.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")+ export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")+ echo "Visit http://127.0.0.1:8080 to use your application"+ kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT+{{- end }}diff --git a/rnd/infra/helm/autogpt-server/templates/_helpers.tpl b/rnd/infra/helm/autogpt-server/templates/_helpers.tplnew file mode 100644index 0000000000..2ff84f3d72--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/_helpers.tpl@@ -0,0 +1,62 @@+{{/*+Expand the name of the chart.+*/}}+{{- define "autogpt-server.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 "autogpt-server.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 "autogpt-server.chart" -}}+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}+{{- end }}++{{/*+Common labels+*/}}+{{- define "autogpt-server.labels" -}}+helm.sh/chart: {{ include "autogpt-server.chart" . }}+{{ include "autogpt-server.selectorLabels" . }}+{{- if .Chart.AppVersion }}+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}+{{- end }}+app.kubernetes.io/managed-by: {{ .Release.Service }}+{{- end }}++{{/*+Selector labels+*/}}+{{- define "autogpt-server.selectorLabels" -}}+app.kubernetes.io/name: {{ include "autogpt-server.name" . }}+app.kubernetes.io/instance: {{ .Release.Name }}+{{- end }}++{{/*+Create the name of the service account to use+*/}}+{{- define "autogpt-server.serviceAccountName" -}}+{{- if .Values.serviceAccount.create }}+{{- default (include "autogpt-server.fullname" .) .Values.serviceAccount.name }}+{{- else }}+{{- default "default" .Values.serviceAccount.name }}+{{- end }}+{{- end }}diff --git a/rnd/infra/helm/autogpt-server/templates/configmap.yaml b/rnd/infra/helm/autogpt-server/templates/configmap.yamlnew file mode 100644index 0000000000..f5b5eeae1b--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/configmap.yaml@@ -0,0 +1,10 @@+apiVersion: v1+kind: ConfigMap+metadata:+ name: {{ include "autogpt-server.fullname" . }}-config+ labels:+ {{- include "autogpt-server.labels" . | nindent 4 }}+data:+ {{- range $key, $value := .Values.env }}+ {{ $key }}: {{ $value | quote }}+ {{- end }}\ No newline at end of filediff --git a/rnd/infra/helm/autogpt-server/templates/deployment.yaml b/rnd/infra/helm/autogpt-server/templates/deployment.yamlnew file mode 100644index 0000000000..8c337e5729--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/deployment.yaml@@ -0,0 +1,80 @@+apiVersion: apps/v1+kind: Deployment+metadata:+ name: {{ include "autogpt-server.fullname" . }}+ labels:+ {{- include "autogpt-server.labels" . | nindent 4 }}+spec:+ {{- if not .Values.autoscaling.enabled }}+ replicas: {{ .Values.replicaCount }}+ {{- end }}+ selector:+ matchLabels:+ {{- include "autogpt-server.selectorLabels" . | nindent 6 }}+ template:+ metadata:+ {{- with .Values.podAnnotations }}+ annotations:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ labels:+ {{- include "autogpt-server.labels" . | nindent 8 }}+ {{- with .Values.podLabels }}+ {{- toYaml . | nindent 8 }}+ {{- end }}+ spec:+ {{- with .Values.imagePullSecrets }}+ imagePullSecrets:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ serviceAccountName: {{ include "autogpt-server.serviceAccountName" . }}+ securityContext:+ {{- toYaml .Values.podSecurityContext | nindent 8 }}+ containers:+ - name: {{ .Chart.Name }}+ envFrom:+ - configMapRef:+ name: {{ include "autogpt-server.fullname" . }}-config+ securityContext:+ {{- toYaml .Values.securityContext | nindent 12 }}+ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"+ imagePullPolicy: {{ .Values.image.pullPolicy }}+ ports:+ - name: http+ containerPort: {{ .Values.service.port }}+ protocol: TCP+ livenessProbe:+ {{- toYaml .Values.livenessProbe | nindent 12 }}+ readinessProbe:+ {{- toYaml .Values.readinessProbe | nindent 12 }}+ resources:+ {{- toYaml .Values.resources | nindent 12 }}+ {{- with .Values.volumeMounts }}+ volumeMounts:+ {{- toYaml . | nindent 12 }}+ {{- end }}+ - name: cloud-sql-proxy+ image: "{{ .Values.cloudSqlProxy.image.repository }}:{{ .Values.cloudSqlProxy.image.tag }}"+ args:+ - "--structured-logs"+ {{- if .Values.cloudSqlProxy.usePrivateIp }}+ - "--private-ip"+ {{- end }}+ - "--port={{ .Values.cloudSqlProxy.port }}"+ - "{{ .Values.cloudSqlProxy.instanceConnectionName }}"+ {{- 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 }}diff --git a/rnd/infra/helm/autogpt-server/templates/hpa.yaml b/rnd/infra/helm/autogpt-server/templates/hpa.yamlnew file mode 100644index 0000000000..f2e1af78ae--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/hpa.yaml@@ -0,0 +1,32 @@+{{- if .Values.autoscaling.enabled }}+apiVersion: autoscaling/v2+kind: HorizontalPodAutoscaler+metadata:+ name: {{ include "autogpt-server.fullname" . }}+ labels:+ {{- include "autogpt-server.labels" . | nindent 4 }}+spec:+ scaleTargetRef:+ apiVersion: apps/v1+ kind: Deployment+ name: {{ include "autogpt-server.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 }}diff --git a/rnd/infra/helm/autogpt-server/templates/ingress.yaml b/rnd/infra/helm/autogpt-server/templates/ingress.yamlnew file mode 100644index 0000000000..115d67031c--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/ingress.yaml@@ -0,0 +1,61 @@+{{- if .Values.ingress.enabled -}}+{{- $fullName := include "autogpt-server.fullname" . -}}+{{- $svcPort := .Values.service.port -}}+{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}+ {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}+ {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}+ {{- end }}+{{- end }}+{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}+apiVersion: networking.k8s.io/v1+{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}+apiVersion: networking.k8s.io/v1beta1+{{- else -}}+apiVersion: extensions/v1beta1+{{- end }}+kind: Ingress+metadata:+ name: {{ $fullName }}+ labels:+ {{- include "autogpt-server.labels" . | nindent 4 }}+ {{- with .Values.ingress.annotations }}+ annotations:+ {{- toYaml . | nindent 4 }}+ {{- end }}+spec:+ {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}+ ingressClassName: {{ .Values.ingress.className }}+ {{- end }}+ {{- if .Values.ingress.tls }}+ tls:+ {{- range .Values.ingress.tls }}+ - hosts:+ {{- range .hosts }}+ - {{ . | quote }}+ {{- end }}+ secretName: {{ .secretName }}+ {{- end }}+ {{- end }}+ rules:+ {{- range .Values.ingress.hosts }}+ - host: {{ .host | quote }}+ http:+ paths:+ {{- range .paths }}+ - path: {{ .path }}+ {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}+ pathType: {{ .pathType }}+ {{- end }}+ backend:+ {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}+ service:+ name: {{ $fullName }}+ port:+ number: {{ $svcPort }}+ {{- else }}+ serviceName: {{ $fullName }}+ servicePort: {{ $svcPort }}+ {{- end }}+ {{- end }}+ {{- end }}+{{- end }}diff --git a/rnd/infra/helm/autogpt-server/templates/managedcert.yaml b/rnd/infra/helm/autogpt-server/templates/managedcert.yamlnew file mode 100644index 0000000000..97fe878f20--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/managedcert.yaml@@ -0,0 +1,7 @@+apiVersion: networking.gke.io/v1+kind: ManagedCertificate+metadata:+ name: {{ include "autogpt-server.fullname" . }}-cert+spec:+ domains:+ - {{ .Values.domain }}\ No newline at end of filediff --git a/rnd/infra/helm/autogpt-server/templates/service.yaml b/rnd/infra/helm/autogpt-server/templates/service.yamlnew file mode 100644index 0000000000..53d970dbc9--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/service.yaml@@ -0,0 +1,19 @@+apiVersion: v1+kind: Service+metadata:+ name: {{ include "autogpt-server.fullname" . }}+ labels:+ {{- include "autogpt-server.labels" . | nindent 4 }}+ {{- with .Values.service.annotations }}+ annotations:+ {{- toYaml . | nindent 4 }}+ {{- end }}+spec:+ type: {{ .Values.service.type }}+ ports:+ - port: {{ .Values.service.port }}+ targetPort: http+ protocol: TCP+ name: http+ selector:+ {{- include "autogpt-server.selectorLabels" . | nindent 4 }}diff --git a/rnd/infra/helm/autogpt-server/templates/serviceaccount.yaml b/rnd/infra/helm/autogpt-server/templates/serviceaccount.yamlnew file mode 100644index 0000000000..2a403f9c74--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/serviceaccount.yaml@@ -0,0 +1,13 @@+{{- if .Values.serviceAccount.create -}}+apiVersion: v1+kind: ServiceAccount+metadata:+ name: {{ include "autogpt-server.serviceAccountName" . }}+ labels:+ {{- include "autogpt-server.labels" . | nindent 4 }}+ {{- with .Values.serviceAccount.annotations }}+ annotations:+ {{- toYaml . | nindent 4 }}+ {{- end }}+automountServiceAccountToken: {{ .Values.serviceAccount.automount }}+{{- end }}diff --git a/rnd/infra/helm/autogpt-server/templates/tests/test-connection.yaml b/rnd/infra/helm/autogpt-server/templates/tests/test-connection.yamlnew file mode 100644index 0000000000..0f0d4593f2--- /dev/null+++ b/rnd/infra/helm/autogpt-server/templates/tests/test-connection.yaml@@ -0,0 +1,15 @@+apiVersion: v1+kind: Pod+metadata:+ name: "{{ include "autogpt-server.fullname" . }}-test-connection"+ labels:+ {{- include "autogpt-server.labels" . | nindent 4 }}+ annotations:+ "helm.sh/hook": test+spec:+ containers:+ - name: wget+ image: busybox+ command: ['wget']+ args: ['{{ include "autogpt-server.fullname" . }}:{{ .Values.service.port }}']+ restartPolicy: Neverdiff --git a/rnd/infra/helm/autogpt-server/values.dev.yaml b/rnd/infra/helm/autogpt-server/values.dev.yamlnew file mode 100644index 0000000000..cd55dbd73e--- /dev/null+++ b/rnd/infra/helm/autogpt-server/values.dev.yaml@@ -0,0 +1,83 @@+# dev values, overwrite base values as needed.++image:+ repository: us-east1-docker.pkg.dev/agpt-dev/agpt-server-dev/agpt-server-dev+ pullPolicy: Always+ tag: "latest"++serviceAccount:+ annotations:+ iam.gke.io/gcp-service-account: "[email protected]"+ name: "dev-agpt-server-sa"++service:+ type: ClusterIP+ port: 8000+ targetPort: 8000+ annotations:+ cloud.google.com/neg: '{"ingress": true}'++ingress:+ enabled: true+ className: "gce"+ annotations:+ kubernetes.io/ingress.class: gce+ kubernetes.io/ingress.global-static-ip-name: "agpt-dev-agpt-server-ip"+ networking.gke.io/managed-certificates: "autogpt-server-cert"+ kubernetes.io/ingress.allow-http: "true"+ hosts:+ - host: dev-server.agpt.co+ paths:+ - path: /+ pathType: Prefix+ backend:+ service:+ name: autogpt-server+ port: 8000+ defaultBackend:+ service:+ name: autogpt-server+ port:+ number: 8000++resources:+ requests:+ cpu: 100m+ memory: 128Mi+ limits:+ cpu: 500m+ memory: 512Mi++livenessProbe:+ httpGet:+ path: /docs+ port: 8000+ initialDelaySeconds: 30+ periodSeconds: 10+ timeoutSeconds: 5+ failureThreshold: 6+readinessProbe:+ httpGet:+ path: /docs+ port: 8000+ initialDelaySeconds: 30+ periodSeconds: 10+ timeoutSeconds: 5+ failureThreshold: 6++domain: "dev-server.agpt.co"++cloudSqlProxy:+ image:+ repository: gcr.io/cloud-sql-connectors/cloud-sql-proxy+ tag: 2.11.4+ instanceConnectionName: "agpt-dev:us-central1:agpt-server-dev"+ port: 5432+ resources:+ requests:+ memory: "2Gi"+ cpu: "1"++env:+ APP_ENV: "dev"+ PYRO_HOST: "0.0.0.0"\ No newline at end of filediff --git a/rnd/infra/helm/autogpt-server/values.yaml b/rnd/infra/helm/autogpt-server/values.yamlnew file mode 100644index 0000000000..3bdfd8515a--- /dev/null+++ b/rnd/infra/helm/autogpt-server/values.yaml@@ -0,0 +1,87 @@+# base values, environment specific variables should be specified/overwritten in environment values++replicaCount: 1++image:+ repository: us-east1-docker.pkg.dev/agpt-dev/agpt-server-dev/agpt-server-dev+ pullPolicy: IfNotPresent+ tag: "latest"++imagePullSecrets: []+nameOverride: ""+fullnameOverride: ""++serviceAccount:+ create: true+ automount: true+ annotations: {}+ name: ""++podAnnotations: {}+podLabels: {}++podSecurityContext: {}++securityContext: {}++service:+ type: ClusterIP+ port: 80++ingress:+ enabled: false+ className: ""+ annotations: {}+ hosts:+ - host: chart-example.local+ paths:+ - path: /+ pathType: ImplementationSpecific+ tls: []+++resources:+ requests:+ cpu: 100m+ memory: 128Mi+ limits:+ cpu: 500m+ memory: 512Mi++livenessProbe:+ httpGet:+ path: /+ port: http+readinessProbe:+ httpGet:+ path: /+ port: http++autoscaling:+ enabled: false+ minReplicas: 1+ maxReplicas: 100+ targetMemoryUtilizationPercentage: 80++volumes: []++volumeMounts: []++nodeSelector: {}++tolerations: []++affinity: {}++domain: ""++cloudSqlProxy:+ image:+ repository: gcr.io/cloud-sql-connectors/cloud-sql-proxy+ tag: 2.11.4+ instanceConnectionName: ""+ port: 5432+ resources:+ requests:+ memory: "2Gi"+ cpu: "1"diff --git a/rnd/infra/terraform/environments/dev.tfvars b/rnd/infra/terraform/environments/dev.tfvarsindex cbcc69ccd8..c66283019d 100644--- a/rnd/infra/terraform/environments/dev.tfvars+++ b/rnd/infra/terraform/environments/dev.tfvars@@ -10,3 +10,46 @@ node_pool_name = "dev-main-pool"machine_type = "e2-medium"disk_size_gb = 100static_ip_names = ["agpt-server-ip", "agpt-builder-ip", "auth-ip"]+++service_accounts = {+ "dev-agpt-server-sa" = {+ display_name = "AutoGPT Dev Server Account"+ description = "Service account for agpt dev server"+ }+}++workload_identity_bindings = {+ "dev-agpt-server-workload-identity" = {+ service_account_name = "dev-agpt-server-sa"+ namespace = "dev-agpt"+ ksa_name = "dev-agpt-server-sa"+ }+}++role_bindings = {+ "roles/container.developer" = [+ "serviceAccount:[email protected]"+ ],+ "roles/cloudsql.client" = [+ "serviceAccount:[email protected]"+ ],+ "roles/cloudsql.editor" = [+ "serviceAccount:[email protected]"+ ],+ "roles/cloudsql.instanceUser" = [+ "serviceAccount:[email protected]"+ ],+ "roles/iam.workloadIdentityUser" = [+ "serviceAccount:[email protected]"+ ]+ "roles/compute.networkUser" = [+ "serviceAccount:[email protected]"+ ],+ "roles/container.hostServiceAgentUser" = [+ "serviceAccount:[email protected]"+ ]+}++pods_ip_cidr_range = "10.1.0.0/16"+services_ip_cidr_range = "10.2.0.0/20"\ No newline at end of filediff --git a/rnd/infra/terraform/main.tf b/rnd/infra/terraform/main.tfindex 856372e10c..495130b6a0 100644--- a/rnd/infra/terraform/main.tf+++ b/rnd/infra/terraform/main.tf@@ -6,10 +6,12 @@ terraform {version = "~> 4.0"}}+backend "gcs" {bucket = "agpt-dev-terraform"prefix = "terraform/state"}+}provider "google" {@@ -28,11 +30,13 @@ module "static_ips" {module "networking" {source = "./modules/networking"- project_id = var.project_id- region = var.region- network_name = var.network_name- subnet_name = var.subnet_name- subnet_cidr = var.subnet_cidr+ project_id = var.project_id+ region = var.region+ network_name = var.network_name+ subnet_name = var.subnet_name+ subnet_cidr = var.subnet_cidr+ pods_ip_cidr_range = var.pods_ip_cidr_range+ services_ip_cidr_range = var.services_ip_cidr_range}module "gke_cluster" {@@ -49,3 +53,12 @@ module "gke_cluster" {subnetwork = module.networking.subnet_self_linkenable_autopilot = var.enable_autopilot}++module "iam" {+ source = "./modules/iam"++ project_id = var.project_id+ service_accounts = var.service_accounts+ workload_identity_bindings = var.workload_identity_bindings+ role_bindings = var.role_bindings+}\ No newline at end of filediff --git a/rnd/infra/terraform/modules/gke_cluster/main.tf b/rnd/infra/terraform/modules/gke_cluster/main.tfindex c646a14030..66d1b2b76d 100644--- a/rnd/infra/terraform/modules/gke_cluster/main.tf+++ b/rnd/infra/terraform/modules/gke_cluster/main.tf@@ -2,6 +2,11 @@ resource "google_container_cluster" "primary" {name = var.cluster_namelocation = var.zone+ workload_identity_config {+ workload_pool = "${var.project_id}.svc.id.goog"+ }++dynamic "node_pool" {for_each = var.enable_autopilot ? [] : [1]content {@@ -11,11 +16,20 @@ resource "google_container_cluster" "primary" {node_config {machine_type = var.machine_typedisk_size_gb = var.disk_size_gb++ workload_metadata_config {+ mode = "GKE_METADATA"+ }}}}network = var.networksubnetwork = var.subnetwork++ ip_allocation_policy {+ cluster_secondary_range_name = "pods"+ services_secondary_range_name = "services"+ }}diff --git a/rnd/infra/terraform/modules/iam/main.tf b/rnd/infra/terraform/modules/iam/main.tfnew file mode 100644index 0000000000..3a07d69264--- /dev/null+++ b/rnd/infra/terraform/modules/iam/main.tf@@ -0,0 +1,26 @@+resource "google_service_account" "service_accounts" {+ for_each = var.service_accounts+ account_id = each.key+ display_name = each.value.display_name+ description = each.value.description+}++# IAM policy binding for Workload Identity+resource "google_service_account_iam_binding" "workload_identity_binding" {+ for_each = var.workload_identity_bindings+ service_account_id = google_service_account.service_accounts[each.value.service_account_name].name+ role = "roles/iam.workloadIdentityUser"++ members = [+ "serviceAccount:${var.project_id}.svc.id.goog[${each.value.namespace}/${each.value.ksa_name}]"+ ]+}++# Role bindings grouped by role+resource "google_project_iam_binding" "role_bindings" {+ for_each = var.role_bindings+ project = var.project_id+ role = each.key++ members = each.value+}\ No newline at end of filediff --git a/rnd/infra/terraform/modules/iam/outputs.tf b/rnd/infra/terraform/modules/iam/outputs.tfnew file mode 100644index 0000000000..b503414873--- /dev/null+++ b/rnd/infra/terraform/modules/iam/outputs.tf@@ -0,0 +1,4 @@+output "service_account_emails" {+ description = "The emails of the created service accounts"+ value = { for k, v in google_service_account.service_accounts : k => v.email }+}\ No newline at end of filediff --git a/rnd/infra/terraform/modules/iam/variables.tf b/rnd/infra/terraform/modules/iam/variables.tfnew file mode 100644index 0000000000..61637a7187--- /dev/null+++ b/rnd/infra/terraform/modules/iam/variables.tf@@ -0,0 +1,29 @@+variable "project_id" {+ description = "The ID of the project"+ type = string+}++variable "service_accounts" {+ description = "Map of service accounts to create"+ type = map(object({+ display_name = string+ description = string+ }))+ default = {}+}++variable "workload_identity_bindings" {+ description = "Map of Workload Identity bindings to create"+ type = map(object({+ service_account_name = string+ namespace = string+ ksa_name = string+ }))+ default = {}+}++variable "role_bindings" {+ description = "Map of roles to list of members"+ type = map(list(string))+ default = {}+}\ No newline at end of filediff --git a/rnd/infra/terraform/modules/networking/main.tf b/rnd/infra/terraform/modules/networking/main.tfindex 64aac3a77d..823fd6b89e 100644--- a/rnd/infra/terraform/modules/networking/main.tf+++ b/rnd/infra/terraform/modules/networking/main.tf@@ -8,5 +8,15 @@ resource "google_compute_subnetwork" "subnet" {ip_cidr_range = var.subnet_cidrregion = var.regionnetwork = google_compute_network.vpc_network.self_link++ secondary_ip_range {+ range_name = "pods"+ ip_cidr_range = var.pods_ip_cidr_range+ }++ secondary_ip_range {+ range_name = "services"+ ip_cidr_range = var.services_ip_cidr_range+ }}diff --git a/rnd/infra/terraform/modules/networking/variables.tf b/rnd/infra/terraform/modules/networking/variables.tfindex 3989bddff0..aa4d409f02 100644--- a/rnd/infra/terraform/modules/networking/variables.tf+++ b/rnd/infra/terraform/modules/networking/variables.tf@@ -18,4 +18,12 @@ variable "subnet_cidr" {description = "The CIDR range for the subnet"}+variable "pods_ip_cidr_range" {+ description = "The IP address range for pods"+ default = "10.1.0.0/16"+}+variable "services_ip_cidr_range" {+ description = "The IP address range for services"+ default = "10.2.0.0/20"+}diff --git a/rnd/infra/terraform/modules/static_ip/main.tf b/rnd/infra/terraform/modules/static_ip/main.tfindex 4b6d073541..877b4bf30e 100644--- a/rnd/infra/terraform/modules/static_ip/main.tf+++ b/rnd/infra/terraform/modules/static_ip/main.tf@@ -1,6 +1,5 @@-resource "google_compute_address" "static_ip" {+resource "google_compute_global_address" "static_ip" {count = length(var.ip_names)name = "${var.project_id}-${var.ip_names[count.index]}"- region = var.regionaddress_type = "EXTERNAL"}\ No newline at end of filediff --git a/rnd/infra/terraform/modules/static_ip/outputs.tf b/rnd/infra/terraform/modules/static_ip/outputs.tfindex 2b03fe3623..27a9aa5804 100644--- a/rnd/infra/terraform/modules/static_ip/outputs.tf+++ b/rnd/infra/terraform/modules/static_ip/outputs.tf@@ -1,9 +1,9 @@output "ip_addresses" {description = "Map of created static IP addresses"- value = { for i, ip in google_compute_address.static_ip : var.ip_names[i] => ip.address }+ value = { for i, ip in google_compute_global_address.static_ip : var.ip_names[i] => ip.address }}output "ip_names" {description = "List of full names of the created static IP addresses"- value = google_compute_address.static_ip[*].name+ value = google_compute_global_address.static_ip[*].name}\ No newline at end of filediff --git a/rnd/infra/terraform/variables.tf b/rnd/infra/terraform/variables.tfindex 66c35e7ad6..76da68cce5 100644--- a/rnd/infra/terraform/variables.tf+++ b/rnd/infra/terraform/variables.tf@@ -74,3 +74,40 @@ variable "static_ip_names" {type = list(string)default = ["ip-1", "ip-2", "ip-3"]}++variable "service_accounts" {+ description = "Map of service accounts to create"+ type = map(object({+ display_name = string+ description = string+ }))+ default = {}+}++variable "workload_identity_bindings" {+ description = "Map of Workload Identity bindings to create"+ type = map(object({+ service_account_name = string+ namespace = string+ ksa_name = string+ }))+ default = {}+}++variable "role_bindings" {+ description = "Map of roles to list of members"+ type = map(list(string))+ default = {}+}++variable "pods_ip_cidr_range" {+ description = "The IP address range for pods"+ type = string+ default = "10.1.0.0/16"+}++variable "services_ip_cidr_range" {+ description = "The IP address range for services"+ type = string+ default = "10.2.0.0/20"+}\ No newline at end of file