Skip to content

Commit

Permalink
update helmchart generator
Browse files Browse the repository at this point in the history
  • Loading branch information
abolfazl8131 committed Oct 30, 2024
1 parent e007015 commit 3d4d12d
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 125 deletions.
Binary file modified app/__pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file modified app/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified app/__pycache__/prompt_generators.cpython-311.pyc
Binary file not shown.
Binary file modified app/__pycache__/services.cpython-311.pyc
Binary file not shown.
107 changes: 30 additions & 77 deletions app/directory_generators/helm_generator.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,35 @@
import os

# Define the project structure
project_name = "app/media/MyHelm"
directories = ["charts", "crds", "templates"]
files = ["Chart.yaml", "values.yaml"]

# Define default content for Chart.yaml and values.yaml
chart_yaml_content = """apiVersion: v2
name: myhelm
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_content = """# Default values for myhelm.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: myimage
""",
"values.yaml": """image:
repository: rembg
tag: latest
pullPolicy: IfNotPresent
tag: ""
service:
name: myservice
type: ClusterIP
port: 80
"""

# Create the project structure
os.makedirs(project_name, exist_ok=True)

for directory in directories:
os.makedirs(os.path.join(project_name, directory), exist_ok=True)

for file in files:
file_path = os.path.join(project_name, file)
with open(file_path, 'w') as f:
if file == "Chart.yaml":
f.write(chart_yaml_content)
elif file == "values.yaml":
f.write(values_yaml_content)

# Create a basic GitHub Actions workflow file
github_actions_dir = os.path.join(project_name, ".github/workflows")
os.makedirs(github_actions_dir, exist_ok=True)
with open(os.path.join(github_actions_dir, "ci.yml"), 'w') as f:
f.write("""name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: true
tags: myimage:latest
""")
""",
}

# Create project structure
os.makedirs(project_path, exist_ok=True)
for d in dirs:
os.makedirs(d, exist_ok=True)

# 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)
36 changes: 0 additions & 36 deletions app/media/MyHelm/.github/workflows/ci.yml

This file was deleted.

4 changes: 2 additions & 2 deletions app/media/MyHelm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v2
name: myhelm
apiVersion: v1
name: MyHelm
description: A Helm chart for Kubernetes
version: 0.1.0
12 changes: 2 additions & 10 deletions app/media/MyHelm/values.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# Default values for myhelm.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: myimage
repository: rembg
tag: latest
pullPolicy: IfNotPresent
tag: ""
service:
name: myservice
type: ClusterIP
port: 80
5 changes: 5 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class IaCTemplateGeneration(BaseModel):

class HelmTemplateGeneration(BaseModel):
CI_integration:bool = True
api_version:int = 1
templates:list[str]
images:list[str]





Expand Down
3 changes: 3 additions & 0 deletions app/prompt_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def helm_template_generator(input : HelmTemplateGeneration) -> str:
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}.
set the api_version in the Chart.yaml : v{input.api_version}.
initialize values.yaml based on these docker images : {input.images}
please set a something default in chart.yaml and values.yaml
Expand Down

0 comments on commit 3d4d12d

Please sign in to comment.