11import os
2+ import yaml
23
4+ # Project structure
35project_name = "MyHelm"
46base_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 )
0 commit comments