diff --git a/app/__pycache__/prompt_generators.cpython-311.pyc b/app/__pycache__/prompt_generators.cpython-311.pyc index 293f866c..d7ef85ba 100644 Binary files a/app/__pycache__/prompt_generators.cpython-311.pyc and b/app/__pycache__/prompt_generators.cpython-311.pyc differ diff --git a/app/directory_generators/helm_generator.py b/app/directory_generators/helm_generator.py index c1b1cd16..878fef9a 100644 --- a/app/directory_generators/helm_generator.py +++ b/app/directory_generators/helm_generator.py @@ -1,43 +1,26 @@ import os -# Define the project structure -project_name = "MyHelm" -base_path = f"app/media/{project_name}" +project_name = "app/media/MyHelm" +# Define the directory structure and file content directories = [ - "charts/", - "templates/web/" + "charts", + "templates/web" ] -files = [ - "Chart.yaml", - "values.yaml", - "templates/web/service.yaml", - "templates/web/deployment.yaml", - "templates/web/secret.yaml" # Only if there are environment variables -] - -# Create the directories -for directory in directories: - os.makedirs(os.path.join(base_path, directory), exist_ok=True) - -# Create the Chart.yaml file -chart_yaml_content = """apiVersion: v2 -name: mychart +files = { + "Chart.yaml": """apiVersion: v2 +name: my-helm description: A Helm chart for Kubernetes version: 0.1.0 -""" -with open(os.path.join(base_path, "Chart.yaml"), "w") as chart_file: - chart_file.write(chart_yaml_content) - -# Create the values.yaml file -values_yaml_content = """web: +appVersion: "1.0" +""", + "values.yaml": """web: image: nginx service: - targetPort: 80 + port: 80 replicas: 1 persistence: - enabled: true size: 1Gi accessModes: - ReadWriteOnce @@ -47,72 +30,71 @@ ingress: enabled: false host: www.example.com -""" -with open(os.path.join(base_path, "values.yaml"), "w") as values_file: - values_file.write(values_yaml_content) - -# Create service.yaml file -service_yaml_content = """apiVersion: v1 +""", + "templates/web/service.yaml": """apiVersion: v1 kind: Service metadata: - name: web + name: {{ include \"my-helm.fullname\" . }} spec: type: ClusterIP ports: - - port: 80 - targetPort: {{ .Values.web.service.targetPort }} + - port: {{ .Values.web.service.port }} selector: - app: {{ .Release.Name }} -""" - -with open(os.path.join(base_path, "templates/web/service.yaml"), "w") as service_file: - service_file.write(service_yaml_content) - -# Create deployment.yaml file -deployment_yaml_content = """apiVersion: apps/v1 + app: {{ include \"my-helm.name\" . }} +""", + "templates/web/deployment.yaml": """apiVersion: apps/v1 kind: Deployment metadata: - name: web + name: {{ include \"my-helm.fullname\" . }} spec: replicas: {{ .Values.web.replicas }} selector: matchLabels: - app: {{ .Release.Name }} + app: {{ include \"my-helm.name\" . }} template: metadata: labels: - app: {{ .Release.Name }} + app: {{ include \"my-helm.name\" . }} spec: containers: - - name: web + - name: {{ include \"my-helm.name\" . }} image: {{ .Values.web.image }} ports: - - containerPort: {{ .Values.web.service.targetPort }} + - containerPort: {{ .Values.web.service.port }} env: - name: ENV1 - value: {{ .Values.web.env[0].value }} - volumeClaimTemplates: - - metadata: - name: web-pvc - spec: - accessModes: {{ .Values.web.persistence.accessModes | toYaml }} - resources: - requests: - storage: {{ .Values.web.persistence.size }} -""" - -with open(os.path.join(base_path, "templates/web/deployment.yaml"), "w") as deployment_file: - deployment_file.write(deployment_yaml_content) - -# Create secret.yaml file -secret_yaml_content = """apiVersion: v1 + value: Hi +""", + "templates/web/secret.yaml": """apiVersion: v1 kind: Secret metadata: - name: web-secret + name: {{ include \"my-helm.fullname\" . }}-secret type: Opaque data: - ENV1: aGl + ENV1: {{ .Values.web.env[0].value | b64enc | quote }} +""", + "templates/web/helpers.tpl": """{{/* +Helper Template +*/}} +{{- define "my-helm.name" -}} +{{- .Chart.Name | replace \"-\" \"_\" | quote -}} +{{- end -}} + +{{- define "my-helm.fullname" -}} +{{- if .Chart.Name -}} +{{- .Release.Name | default \"my-release\" | lower | quote }}-{{ .Chart.Name | lower | quote }} +{{- else -}} +{{- .Release.Name | default \"my-release\" | lower | quote }} +{{- end -}} +{{- end -}} """ +} + +# Create directories +for directory in directories: + os.makedirs(os.path.join(project_name, directory), exist_ok=True) -with open(os.path.join(base_path, "templates/web/secret.yaml"), "w") as secret_file: - secret_file.write(secret_yaml_content) \ No newline at end of file +# Create files +for file_path, content in files.items(): + with open(os.path.join(project_name, file_path), 'w') as f: + f.write(content) \ No newline at end of file diff --git a/app/media/MyHelm/Chart.yaml b/app/media/MyHelm/Chart.yaml index 59be7b67..e56efcc9 100644 --- a/app/media/MyHelm/Chart.yaml +++ b/app/media/MyHelm/Chart.yaml @@ -1,4 +1,5 @@ apiVersion: v2 -name: mychart +name: my-helm description: A Helm chart for Kubernetes version: 0.1.0 +appVersion: "1.0" diff --git a/app/media/MyHelm/templates/web/deployment.yaml b/app/media/MyHelm/templates/web/deployment.yaml index 4fcb5006..046146f3 100644 --- a/app/media/MyHelm/templates/web/deployment.yaml +++ b/app/media/MyHelm/templates/web/deployment.yaml @@ -1,30 +1,22 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: web + name: {{ include "my-helm.fullname" . }} spec: replicas: {{ .Values.web.replicas }} selector: matchLabels: - app: {{ .Release.Name }} + app: {{ include "my-helm.name" . }} template: metadata: labels: - app: {{ .Release.Name }} + app: {{ include "my-helm.name" . }} spec: containers: - - name: web + - name: {{ include "my-helm.name" . }} image: {{ .Values.web.image }} ports: - - containerPort: {{ .Values.web.service.targetPort }} + - containerPort: {{ .Values.web.service.port }} env: - name: ENV1 - value: {{ .Values.web.env[0].value }} - volumeClaimTemplates: - - metadata: - name: web-pvc - spec: - accessModes: {{ .Values.web.persistence.accessModes | toYaml }} - resources: - requests: - storage: {{ .Values.web.persistence.size }} + value: Hi diff --git a/app/media/MyHelm/templates/web/helpers.tpl b/app/media/MyHelm/templates/web/helpers.tpl new file mode 100644 index 00000000..b7925c78 --- /dev/null +++ b/app/media/MyHelm/templates/web/helpers.tpl @@ -0,0 +1,14 @@ +{{/* +Helper Template +*/}} +{{- define "my-helm.name" -}} +{{- .Chart.Name | replace "-" "_" | quote -}} +{{- end -}} + +{{- define "my-helm.fullname" -}} +{{- if .Chart.Name -}} +{{- .Release.Name | default "my-release" | lower | quote }}-{{ .Chart.Name | lower | quote }} +{{- else -}} +{{- .Release.Name | default "my-release" | lower | quote }} +{{- end -}} +{{- end -}} diff --git a/app/media/MyHelm/templates/web/secret.yaml b/app/media/MyHelm/templates/web/secret.yaml index 3ee4696a..e6fc69da 100644 --- a/app/media/MyHelm/templates/web/secret.yaml +++ b/app/media/MyHelm/templates/web/secret.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Secret metadata: - name: web-secret + name: {{ include "my-helm.fullname" . }}-secret type: Opaque data: - ENV1: aGl + ENV1: {{ .Values.web.env[0].value | b64enc | quote }} diff --git a/app/media/MyHelm/templates/web/service.yaml b/app/media/MyHelm/templates/web/service.yaml index 6da1df95..5ba7ba8b 100644 --- a/app/media/MyHelm/templates/web/service.yaml +++ b/app/media/MyHelm/templates/web/service.yaml @@ -1,11 +1,10 @@ apiVersion: v1 kind: Service metadata: - name: web + name: {{ include "my-helm.fullname" . }} spec: type: ClusterIP ports: - - port: 80 - targetPort: {{ .Values.web.service.targetPort }} + - port: {{ .Values.web.service.port }} selector: - app: {{ .Release.Name }} + app: {{ include "my-helm.name" . }} diff --git a/app/media/MyHelm/values.yaml b/app/media/MyHelm/values.yaml index 55a59996..4d261b0d 100644 --- a/app/media/MyHelm/values.yaml +++ b/app/media/MyHelm/values.yaml @@ -1,10 +1,9 @@ web: image: nginx service: - targetPort: 80 + port: 80 replicas: 1 persistence: - enabled: true size: 1Gi accessModes: - ReadWriteOnce diff --git a/app/prompt_generators.py b/app/prompt_generators.py index 0f75637d..205fa1c0 100644 --- a/app/prompt_generators.py +++ b/app/prompt_generators.py @@ -29,7 +29,7 @@ def IaC_installation_generator(input : IaCInstallationInput) -> str: prompt = f""" generate a clear shell acript about installation {input.service} in {input.os} based on {input.service} document. - without any additional note. just script for installation. + without any additional note. just script for installation. please consider new lines with out any additional comment. """ return prompt @@ -95,6 +95,8 @@ def helm_template_generator(input : HelmTemplateGeneration) -> str: creating secret.yaml based on environemt variables in the {envs} in the template is very important. creating deployment.yaml based on our pods in the template is very important. please set a something default in chart.yaml and values.yaml based on the requirement. + + in the final stage, put helpers.tpl in all templates and set the content based on information given. just Generate a python code without any additional notes or ```python3 entry """