diff --git a/app/__pycache__/models.cpython-311.pyc b/app/__pycache__/models.cpython-311.pyc index 5935677b..b3bdf8fa 100644 Binary files a/app/__pycache__/models.cpython-311.pyc and b/app/__pycache__/models.cpython-311.pyc differ diff --git a/app/__pycache__/prompt_generators.cpython-311.pyc b/app/__pycache__/prompt_generators.cpython-311.pyc index 8f3329b3..0a3b73b7 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 3490c3af..a1af6ef7 100644 --- a/app/directory_generators/helm_generator.py +++ b/app/directory_generators/helm_generator.py @@ -1,35 +1,86 @@ import os +import yaml +# Project structure project_name = "MyHelm" base_dir = "app/media" -project_path = os.path.join(base_dir, project_name) - -# Define directories and files -dirs = [ - os.path.join(project_path, "charts"), - os.path.join(project_path, "crds"), - os.path.join(project_path, "templates", "web"), -] - -files = { - "Chart.yaml": """apiVersion: v1 -name: MyHelm -description: A Helm chart for Kubernetes -version: 0.1.0 -""", - "values.yaml": """image: - repository: rembg - tag: latest - pullPolicy: IfNotPresent -""", +project_dir = os.path.join(base_dir, project_name) + +# Directories to create +dirs = ["charts", "crds", "templates/web"] + +# Creating the directory structure +for dir in dirs: + os.makedirs(os.path.join(project_dir, dir), exist_ok=True) + +# Chart.yaml content +chart_yaml = { + "apiVersion": "v1", + "name": project_name, + "version": "0.1.0", + "description": "A Helm chart for MyHelm", + "maintainers": [{"name": "Your Name", "email": "youremail@example.com"}], + "keywords": ["helm", "chart"], + "home": "https://example.com", + "sources": ["https://github.com/example/MyHelm"] } -# Create project structure -os.makedirs(project_path, exist_ok=True) -for d in dirs: - os.makedirs(d, exist_ok=True) +# Writing Chart.yaml +with open(os.path.join(project_dir, "Chart.yaml"), 'w') as chart_file: + yaml.dump(chart_yaml, chart_file) + +# values.yaml content based on provided information +values_yaml = { + "web": { + "image": "nginx", + "service": { + "enabled": True, + "port": 80 + } + } +} + +# Writing values.yaml +with open(os.path.join(project_dir, "values.yaml"), 'w') as values_file: + yaml.dump(values_yaml, values_file) + +# Template files content +deployment_yaml = """apiVersion: apps/v1 +kind: Deployment +metadata: + name: web +spec: + replicas: 1 + selector: + matchLabels: + app: web + template: + metadata: + labels: + app: web + spec: + containers: + - name: web + image: {{ .Values.web.image }} + ports: + - containerPort: {{ .Values.web.service.port }} +""" + +service_yaml = """apiVersion: v1 +kind: Service +metadata: + name: web +spec: + type: ClusterIP + ports: + - port: {{ .Values.web.service.port }} + selector: + app: web +""" + +# Creating deployment.yaml and service.yaml in templates/web +with open(os.path.join(project_dir, "templates/web/deployment.yaml"), 'w') as dep_file: + dep_file.write(deployment_yaml) -# Create files with default content -for file_name, content in files.items(): - with open(os.path.join(project_path, file_name), 'w') as f: - f.write(content) \ No newline at end of file +with open(os.path.join(project_dir, "templates/web/service.yaml"), 'w') as svc_file: + svc_file.write(service_yaml) \ No newline at end of file diff --git a/app/media/MyHelm/Chart.yaml b/app/media/MyHelm/Chart.yaml index 21fe3c15..db6971eb 100644 --- a/app/media/MyHelm/Chart.yaml +++ b/app/media/MyHelm/Chart.yaml @@ -1,4 +1,13 @@ apiVersion: v1 +description: A Helm chart for MyHelm +home: https://example.com +keywords: +- helm +- chart +maintainers: +- email: youremail@example.com + name: Your Name name: MyHelm -description: A Helm chart for Kubernetes +sources: +- https://github.com/example/MyHelm version: 0.1.0 diff --git a/app/media/MyHelm/templates/web/deployment.yaml b/app/media/MyHelm/templates/web/deployment.yaml new file mode 100644 index 00000000..025864cb --- /dev/null +++ b/app/media/MyHelm/templates/web/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: web +spec: + replicas: 1 + selector: + matchLabels: + app: web + template: + metadata: + labels: + app: web + spec: + containers: + - name: web + image: {{ .Values.web.image }} + ports: + - containerPort: {{ .Values.web.service.port }} diff --git a/app/media/MyHelm/templates/web/service.yaml b/app/media/MyHelm/templates/web/service.yaml new file mode 100644 index 00000000..e0496603 --- /dev/null +++ b/app/media/MyHelm/templates/web/service.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: web +spec: + type: ClusterIP + ports: + - port: {{ .Values.web.service.port }} + selector: + app: web diff --git a/app/media/MyHelm/values.yaml b/app/media/MyHelm/values.yaml index 4c763866..bfa282c8 100644 --- a/app/media/MyHelm/values.yaml +++ b/app/media/MyHelm/values.yaml @@ -1,4 +1,5 @@ -image: - repository: rembg - tag: latest - pullPolicy: IfNotPresent +web: + image: nginx + service: + enabled: true + port: 80 diff --git a/app/models.py b/app/models.py index e37bf191..f830ed75 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,5 @@ from pydantic import BaseModel -from typing import Optional - +from typing import List, Optional class BasicInput(BaseModel): @@ -26,12 +25,15 @@ class IaCTemplateGeneration(BaseModel): base_config:str = 'ec2' service:str = 'terraform' +class Pod(BaseModel): + name:str + image:str + target_port:int + class HelmTemplateGeneration(BaseModel): - CI_integration:bool = True api_version:int = 1 - templates:list[str] - images:list[str] - + pods:List[Pod] + diff --git a/app/prompt_generators.py b/app/prompt_generators.py index 6dad1087..45107c78 100644 --- a/app/prompt_generators.py +++ b/app/prompt_generators.py @@ -57,18 +57,23 @@ def IaC_template_generator(input : IaCTemplateGeneration) -> str: return prompt def helm_template_generator(input : HelmTemplateGeneration) -> str: - + templates = [i.name for i in input.pods] + docker_images = [{i.name:i.image} for i in input.pods] + target_ports = [{i.name:i.target_port} for i in input.pods] prompt = f""" generate a correct python code to generate a helm project structure (project name: app/media/MyHelm) based on the latest version of helm chart. just generate a code to generate a folder as project template. don't consider base_dir - CI integrated (using github actions) = {input.CI_integration}. consider these directories : [charts/, crds/, templates/] consider these files : Chart.yaml & values.yaml - in the templates/ directory create these directories: {input.templates}. + in the templates/ directory create these directories: {templates}. set the api_version in the Chart.yaml : v{input.api_version}. - initialize values.yaml based on these docker images : {input.images} + initialize values.yaml based on these dict of templates and docker images, + please provide other informations related to values.yaml : {docker_images}, + the target port of pods in the dict format are here : {target_ports} + for each template, initialize this files [deployment.yaml ,service.yaml]. + please set a something default in chart.yaml and values.yaml