Skip to content

Commit

Permalink
Merge pull request #39 from abolfazl8131/Abolfazl/models-update
Browse files Browse the repository at this point in the history
Abolfazl/models update
  • Loading branch information
mohammadll authored Nov 7, 2024
2 parents 50564eb + b5e168d commit 90cad8a
Show file tree
Hide file tree
Showing 18 changed files with 275 additions and 97 deletions.
17 changes: 13 additions & 4 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ doc:
- changed-files:
- any-glob-to-any-file: '**/*.md'

unit-test:
- changed-files:
- any-glob-to-any-file: 'app/tests/*.py'

docker-compose:
- changed-files:
- any-glob-to-any-file: '**/docker-compose.yml'
Expand All @@ -25,17 +29,22 @@ requirements:

gpt:
- changed-files:
- any-glob-to-any-file: '**/app/gpt_services.py'
- any-glob-to-any-file: 'app/gpt_services.py'

services:
- changed-files:
- any-glob-to-any-file: '**/app/services.py'
- any-glob-to-any-file: 'app/services.py'

fastapi:
- changed-files:
- any-glob-to-any-file: '**/app/main.py'
- any-glob-to-any-file: 'app/main.py'

prompt:
- changed-files:
- any-glob-to-any-file: '**/app/prompt_generators.py'
- any-glob-to-any-file: 'app/prompt_generators.py'

directory-generators:
- 'app/directory_generators/**'

pydantic-models:
- 'app/models/**'
Binary file modified app/__pycache__/prompt_generators.cpython-311.pyc
Binary file not shown.
112 changes: 62 additions & 50 deletions app/directory_generators/helm_generator.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import os

project_name = "app/media/MyHelm"
def create_helm_project_structure(base_path):
project_path = os.path.join(base_path, 'app/media/MyHelm')
os.makedirs(os.path.join(project_path, 'charts'), exist_ok=True)
os.makedirs(os.path.join(project_path, 'templates', 'web'), exist_ok=True)

# Define the directory structure and file content
directories = [
"charts",
"templates/web"
]

files = {
"Chart.yaml": """apiVersion: v2
name: my-helm
chart_yaml_content = """apiVersion: v2
name: MyHelm
description: A Helm chart for Kubernetes
version: 0.1.0
appVersion: "1.0"
""",
"values.yaml": """web:
"""
values_yaml_content = """web:
image: nginx
service:
port: 80
targetPort: 80
replicas: 1
persistence:
size: 1Gi
Expand All @@ -30,71 +26,87 @@
ingress:
enabled: false
host: www.example.com
""",
"templates/web/service.yaml": """apiVersion: v1
"""

service_yaml_content = """apiVersion: v1
kind: Service
metadata:
name: {{ include \"my-helm.fullname\" . }}
name: {{ include "MyHelm.fullname" . }}-web
spec:
type: ClusterIP
ports:
- port: {{ .Values.web.service.port }}
- port: {{ .Values.web.service.targetPort }}
selector:
app: {{ include \"my-helm.name\" . }}
""",
"templates/web/deployment.yaml": """apiVersion: apps/v1
app: {{ include "MyHelm.name" . }}
"""

deployment_yaml_content = """apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include \"my-helm.fullname\" . }}
name: {{ include "MyHelm.fullname" . }}-web
spec:
replicas: {{ .Values.web.replicas }}
selector:
matchLabels:
app: {{ include \"my-helm.name\" . }}
template:
metadata:
labels:
app: {{ include \"my-helm.name\" . }}
app: {{ include "MyHelm.name" . }}
spec:
containers:
- name: {{ include \"my-helm.name\" . }}
- name: web
image: {{ .Values.web.image }}
ports:
- containerPort: {{ .Values.web.service.port }}
- containerPort: {{ .Values.web.service.targetPort }}
env:
- name: ENV1
value: Hi
""",
"templates/web/secret.yaml": """apiVersion: v1
{{- range .Values.web.env }}
- name: {{ .name }}
value: {{ .value }}
{{- end }}
"""

secret_yaml_content = """apiVersion: v1
kind: Secret
metadata:
name: {{ include \"my-helm.fullname\" . }}-secret
name: {{ include "MyHelm.fullname" . }}-web-env
type: Opaque
data:
ENV1: {{ .Values.web.env[0].value | b64enc | quote }}
""",
"templates/web/helpers.tpl": """{{/*
Helper Template
ENV1: {{ .Values.web.env | toJson | b64enc | quote }}
"""

helpers_tpl_content = """{{/*
Expand the name of the chart.
*/}}
{{- define "my-helm.name" -}}
{{- .Chart.Name | replace \"-\" \"_\" | quote -}}
{{- define "MyHelm.name" -}}
{{- .Chart.Name | replace "-" "_" | lower -}}
{{- end -}}
{{- define "my-helm.fullname" -}}
{{/*
Create a default fully qualified domain name
*/}}
{{- define "MyHelm.fullname" -}}
{{- if .Chart.Name -}}
{{- .Release.Name | default \"my-release\" | lower | quote }}-{{ .Chart.Name | lower | quote }}
{{- .Release.Name | lower | replace "-" "_" | trimSuffix "-" | append (include "MyHelm.name" . | lower) | toLower -}}
{{- else -}}
{{- .Release.Name | default \"my-release\" | lower | quote }}
{{- .Release.Name | lower -}}
{{- end -}}
{{- end -}}
"""
}

# Create directories
for directory in directories:
os.makedirs(os.path.join(project_name, directory), exist_ok=True)
with open(os.path.join(project_path, 'Chart.yaml'), 'w') as file:
file.write(chart_yaml_content)

with open(os.path.join(project_path, 'values.yaml'), 'w') as file:
file.write(values_yaml_content)

with open(os.path.join(project_path, 'templates', 'web', 'service.yaml'), 'w') as file:
file.write(service_yaml_content)

with open(os.path.join(project_path, 'templates', 'web', 'deployment.yaml'), 'w') as file:
file.write(deployment_yaml_content)

with open(os.path.join(project_path, 'templates', 'web', 'secret.yaml'), 'w') as file:
file.write(secret_yaml_content)

with open(os.path.join(project_path, 'templates', 'web', 'helpers.tpl'), 'w') as file:
file.write(helpers_tpl_content)

# Create files
for file_path, content in files.items():
with open(os.path.join(project_name, file_path), 'w') as f:
f.write(content)
create_helm_project_structure('.')
1 change: 0 additions & 1 deletion app/gpt_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def gpt_service(prompt):

try:
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

chat_completion = client.chat.completions.create(
messages=[
{
Expand Down
3 changes: 1 addition & 2 deletions app/media/MyHelm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apiVersion: v2
name: my-helm
name: MyHelm
description: A Helm chart for Kubernetes
version: 0.1.0
appVersion: "1.0"
17 changes: 8 additions & 9 deletions app/media/MyHelm/templates/web/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "my-helm.fullname" . }}
name: {{ include "MyHelm.fullname" . }}-web
spec:
replicas: {{ .Values.web.replicas }}
selector:
matchLabels:
app: {{ include "my-helm.name" . }}
template:
metadata:
labels:
app: {{ include "my-helm.name" . }}
app: {{ include "MyHelm.name" . }}
spec:
containers:
- name: {{ include "my-helm.name" . }}
- name: web
image: {{ .Values.web.image }}
ports:
- containerPort: {{ .Values.web.service.port }}
- containerPort: {{ .Values.web.service.targetPort }}
env:
- name: ENV1
value: Hi
{{- range .Values.web.env }}
- name: {{ .name }}
value: {{ .value }}
{{- end }}
15 changes: 9 additions & 6 deletions app/media/MyHelm/templates/web/helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{{/*
Helper Template
Expand the name of the chart.
*/}}
{{- define "my-helm.name" -}}
{{- .Chart.Name | replace "-" "_" | quote -}}
{{- define "MyHelm.name" -}}
{{- .Chart.Name | replace "-" "_" | lower -}}
{{- end -}}

{{- define "my-helm.fullname" -}}
{{/*
Create a default fully qualified domain name
*/}}
{{- define "MyHelm.fullname" -}}
{{- if .Chart.Name -}}
{{- .Release.Name | default "my-release" | lower | quote }}-{{ .Chart.Name | lower | quote }}
{{- .Release.Name | lower | replace "-" "_" | trimSuffix "-" | append (include "MyHelm.name" . | lower) | toLower -}}
{{- else -}}
{{- .Release.Name | default "my-release" | lower | quote }}
{{- .Release.Name | lower -}}
{{- end -}}
{{- end -}}
4 changes: 2 additions & 2 deletions app/media/MyHelm/templates/web/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "my-helm.fullname" . }}-secret
name: {{ include "MyHelm.fullname" . }}-web-env
type: Opaque
data:
ENV1: {{ .Values.web.env[0].value | b64enc | quote }}
ENV1: {{ .Values.web.env | toJson | b64enc | quote }}
6 changes: 3 additions & 3 deletions app/media/MyHelm/templates/web/service.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "my-helm.fullname" . }}
name: {{ include "MyHelm.fullname" . }}-web
spec:
type: ClusterIP
ports:
- port: {{ .Values.web.service.port }}
- port: {{ .Values.web.service.targetPort }}
selector:
app: {{ include "my-helm.name" . }}
app: {{ include "MyHelm.name" . }}
2 changes: 1 addition & 1 deletion app/media/MyHelm/values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
web:
image: nginx
service:
port: 80
targetPort: 80
replicas: 1
persistence:
size: 1Gi
Expand Down
Binary file modified app/models/__pycache__/helm_models.cpython-311.pyc
Binary file not shown.
Binary file modified app/models/__pycache__/terraform_models.cpython-311.pyc
Binary file not shown.
Binary file modified app/models/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Loading

0 comments on commit 90cad8a

Please sign in to comment.