Skip to content

Commit 15b354c

Browse files
authored
fix: Merge pull request #19 from abolfazl8131/develop
update helm prompt
2 parents 4c8ec5d + b21f30c commit 15b354c

9 files changed

Lines changed: 140 additions & 43 deletions

File tree

264 Bytes
Binary file not shown.
1.03 KB
Binary file not shown.
Lines changed: 79 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,86 @@
11
import os
2+
import yaml
23

4+
# Project structure
35
project_name = "MyHelm"
46
base_dir = "app/media"
5-
project_path = os.path.join(base_dir, project_name)
6-
7-
# Define directories and files
8-
dirs = [
9-
os.path.join(project_path, "charts"),
10-
os.path.join(project_path, "crds"),
11-
os.path.join(project_path, "templates", "web"),
12-
]
13-
14-
files = {
15-
"Chart.yaml": """apiVersion: v1
16-
name: MyHelm
17-
description: A Helm chart for Kubernetes
18-
version: 0.1.0
19-
""",
20-
"values.yaml": """image:
21-
repository: rembg
22-
tag: latest
23-
pullPolicy: IfNotPresent
24-
""",
7+
project_dir = os.path.join(base_dir, project_name)
8+
9+
# Directories to create
10+
dirs = ["charts", "crds", "templates/web"]
11+
12+
# Creating the directory structure
13+
for dir in dirs:
14+
os.makedirs(os.path.join(project_dir, dir), exist_ok=True)
15+
16+
# Chart.yaml content
17+
chart_yaml = {
18+
"apiVersion": "v1",
19+
"name": project_name,
20+
"version": "0.1.0",
21+
"description": "A Helm chart for MyHelm",
22+
"maintainers": [{"name": "Your Name", "email": "youremail@example.com"}],
23+
"keywords": ["helm", "chart"],
24+
"home": "https://example.com",
25+
"sources": ["https://github.com/example/MyHelm"]
2526
}
2627

27-
# Create project structure
28-
os.makedirs(project_path, exist_ok=True)
29-
for d in dirs:
30-
os.makedirs(d, exist_ok=True)
28+
# Writing Chart.yaml
29+
with open(os.path.join(project_dir, "Chart.yaml"), 'w') as chart_file:
30+
yaml.dump(chart_yaml, chart_file)
31+
32+
# values.yaml content based on provided information
33+
values_yaml = {
34+
"web": {
35+
"image": "nginx",
36+
"service": {
37+
"enabled": True,
38+
"port": 80
39+
}
40+
}
41+
}
42+
43+
# Writing values.yaml
44+
with open(os.path.join(project_dir, "values.yaml"), 'w') as values_file:
45+
yaml.dump(values_yaml, values_file)
46+
47+
# Template files content
48+
deployment_yaml = """apiVersion: apps/v1
49+
kind: Deployment
50+
metadata:
51+
name: web
52+
spec:
53+
replicas: 1
54+
selector:
55+
matchLabels:
56+
app: web
57+
template:
58+
metadata:
59+
labels:
60+
app: web
61+
spec:
62+
containers:
63+
- name: web
64+
image: {{ .Values.web.image }}
65+
ports:
66+
- containerPort: {{ .Values.web.service.port }}
67+
"""
68+
69+
service_yaml = """apiVersion: v1
70+
kind: Service
71+
metadata:
72+
name: web
73+
spec:
74+
type: ClusterIP
75+
ports:
76+
- port: {{ .Values.web.service.port }}
77+
selector:
78+
app: web
79+
"""
80+
81+
# Creating deployment.yaml and service.yaml in templates/web
82+
with open(os.path.join(project_dir, "templates/web/deployment.yaml"), 'w') as dep_file:
83+
dep_file.write(deployment_yaml)
3184

32-
# Create files with default content
33-
for file_name, content in files.items():
34-
with open(os.path.join(project_path, file_name), 'w') as f:
35-
f.write(content)
85+
with open(os.path.join(project_dir, "templates/web/service.yaml"), 'w') as svc_file:
86+
svc_file.write(service_yaml)

app/media/MyHelm/Chart.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
apiVersion: v1
2+
description: A Helm chart for MyHelm
3+
home: https://example.com
4+
keywords:
5+
- helm
6+
- chart
7+
maintainers:
8+
- email: youremail@example.com
9+
name: Your Name
210
name: MyHelm
3-
description: A Helm chart for Kubernetes
11+
sources:
12+
- https://github.com/example/MyHelm
413
version: 0.1.0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: web
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: web
10+
template:
11+
metadata:
12+
labels:
13+
app: web
14+
spec:
15+
containers:
16+
- name: web
17+
image: {{ .Values.web.image }}
18+
ports:
19+
- containerPort: {{ .Values.web.service.port }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: web
5+
spec:
6+
type: ClusterIP
7+
ports:
8+
- port: {{ .Values.web.service.port }}
9+
selector:
10+
app: web

app/media/MyHelm/values.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
image:
2-
repository: rembg
3-
tag: latest
4-
pullPolicy: IfNotPresent
1+
web:
2+
image: nginx
3+
service:
4+
enabled: true
5+
port: 80

app/models.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pydantic import BaseModel
2-
from typing import Optional
3-
2+
from typing import List, Optional
43

54
class BasicInput(BaseModel):
65

@@ -26,12 +25,15 @@ class IaCTemplateGeneration(BaseModel):
2625
base_config:str = 'ec2'
2726
service:str = 'terraform'
2827

28+
class Pod(BaseModel):
29+
name:str
30+
image:str
31+
target_port:int
32+
2933
class HelmTemplateGeneration(BaseModel):
30-
CI_integration:bool = True
3134
api_version:int = 1
32-
templates:list[str]
33-
images:list[str]
34-
35+
pods:List[Pod]
36+
3537

3638

3739

app/prompt_generators.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ def IaC_template_generator(input : IaCTemplateGeneration) -> str:
5757
return prompt
5858

5959
def helm_template_generator(input : HelmTemplateGeneration) -> str:
60-
60+
templates = [i.name for i in input.pods]
61+
docker_images = [{i.name:i.image} for i in input.pods]
62+
target_ports = [{i.name:i.target_port} for i in input.pods]
6163
prompt = f"""
6264
generate a correct python code to generate a helm project structure (project name: app/media/MyHelm)
6365
based on the latest version of helm chart.
6466
just generate a code to generate a folder as project template. don't consider base_dir
6567
66-
CI integrated (using github actions) = {input.CI_integration}.
6768
consider these directories : [charts/, crds/, templates/]
6869
consider these files : Chart.yaml & values.yaml
69-
in the templates/ directory create these directories: {input.templates}.
70+
in the templates/ directory create these directories: {templates}.
7071
set the api_version in the Chart.yaml : v{input.api_version}.
71-
initialize values.yaml based on these docker images : {input.images}
72+
initialize values.yaml based on these dict of templates and docker images,
73+
please provide other informations related to values.yaml : {docker_images},
74+
the target port of pods in the dict format are here : {target_ports}
75+
for each template, initialize this files [deployment.yaml ,service.yaml].
76+
7277
7378
please set a something default in chart.yaml and values.yaml
7479

0 commit comments

Comments
 (0)