-
Notifications
You must be signed in to change notification settings - Fork 0
/
helmgen.py
78 lines (73 loc) · 1.71 KB
/
helmgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import yaml
def generate_chart(image_name, container_port):
# Create a chart template
chart = {
"apiVersion": "v2",
"name": "mychart",
"version": "0.1.0",
"description": "A Helm chart for deploying a Docker container",
"maintainers": [{"name": "Your Name", "email": "your@email.com"}],
"appVersion": "1.0.0",
"icon": "https://raw.githubusercontent.com/helm/chartmuseum/master/logo/logo.png",
"sources": ["https://github.com/helm/charts"],
"home": "https://github.com/helm/charts",
"keywords": ["container", "docker", "helm"],
"engine": "gotpl",
"dependencies": [],
"templates": [
{
"name": "deployment.yaml",
"data": """
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: {}
ports:
- containerPort: {}
""".format(
image_name, container_port
),
},
{
"name": "service.yaml",
"data": """
apiVersion: v1
kind: Service
metadata:
name: myapp
labels:
app: myapp
spec:
type: LoadBalancer
ports:
- port: {}
protocol: TCP
targetPort: {}
selector:
app: myapp
""".format(
container_port, container_port
),
},
],
}
# Write chart to a file
with open("mychart.yaml", "w") as chart_file:
yaml.dump(chart, chart_file)
# Example usage
generate_chart("nginx:latest", 80)