Skip to content

Commit 6005ce6

Browse files
authored
feature: Merge pull request #15 from abolfazl8131/feature/heml_prompt
add a prompt to generate a helm project
2 parents dd4ac9f + a0db3d3 commit 6005ce6

22 files changed

Lines changed: 302 additions & 153 deletions
706 Bytes
Binary file not shown.
274 Bytes
Binary file not shown.
933 Bytes
Binary file not shown.
43 Bytes
Binary file not shown.

app/directory_generators/directory_generator.py

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
3+
# Define the project structure
4+
project_name = "app/media/MyHelm"
5+
directories = ["charts", "crds", "templates"]
6+
files = ["Chart.yaml", "values.yaml"]
7+
8+
# Define default content for Chart.yaml and values.yaml
9+
chart_yaml_content = """apiVersion: v2
10+
name: myhelm
11+
description: A Helm chart for Kubernetes
12+
version: 0.1.0
13+
"""
14+
values_yaml_content = """# Default values for myhelm.
15+
# This is a YAML-formatted file.
16+
# Declare variables to be passed into your templates.
17+
replicaCount: 1
18+
image:
19+
repository: myimage
20+
pullPolicy: IfNotPresent
21+
tag: ""
22+
service:
23+
name: myservice
24+
type: ClusterIP
25+
port: 80
26+
"""
27+
28+
# Create the project structure
29+
os.makedirs(project_name, exist_ok=True)
30+
31+
for directory in directories:
32+
os.makedirs(os.path.join(project_name, directory), exist_ok=True)
33+
34+
for file in files:
35+
file_path = os.path.join(project_name, file)
36+
with open(file_path, 'w') as f:
37+
if file == "Chart.yaml":
38+
f.write(chart_yaml_content)
39+
elif file == "values.yaml":
40+
f.write(values_yaml_content)
41+
42+
# Create a basic GitHub Actions workflow file
43+
github_actions_dir = os.path.join(project_name, ".github/workflows")
44+
os.makedirs(github_actions_dir, exist_ok=True)
45+
with open(os.path.join(github_actions_dir, "ci.yml"), 'w') as f:
46+
f.write("""name: CI
47+
48+
on:
49+
push:
50+
branches:
51+
- main
52+
pull_request:
53+
branches:
54+
- main
55+
56+
jobs:
57+
build:
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v2
63+
64+
- name: Set up Docker Buildx
65+
uses: docker/setup-buildx-action@v1
66+
67+
- name: Cache Docker layers
68+
uses: actions/cache@v2
69+
with:
70+
path: /tmp/.buildx-cache
71+
key: ${{ runner.os }}-buildx-${{ github.sha }}
72+
restore-keys: |
73+
${{ runner.os }}-buildx-
74+
75+
- name: Build and push Docker image
76+
uses: docker/build-push-action@v2
77+
with:
78+
context: .
79+
file: Dockerfile
80+
push: true
81+
tags: myimage:latest
82+
""")
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import os
2+
3+
project_name = "app/media/MyTerraform"
4+
base_directory = project_name.replace("/", os.sep)
5+
modules_directory = os.path.join(base_directory, "modules")
6+
ci_directory = os.path.join(base_directory, ".github", "workflows")
7+
8+
os.makedirs(modules_directory, exist_ok=True)
9+
os.makedirs(ci_directory, exist_ok=True)
10+
11+
terraform_main = f"""provider "aws" {{
12+
region = "us-east-1"
13+
}}
14+
15+
resource "aws_instance" "web" {{
16+
ami = "ami-0c55b159cbfafe1f0"
17+
instance_type = "t2.micro"
18+
19+
tags = {{
20+
Name = "MyEC2Instance"
21+
}}
22+
}}
23+
"""
24+
25+
terraform_variables = """variable "region" {{
26+
description = "AWS region"
27+
type = string
28+
default = "us-east-1"
29+
}}
30+
31+
variable "instance_type" {{
32+
description = "EC2 Instance type"
33+
type = string
34+
default = "t2.micro"
35+
}}
36+
37+
variable "ami" {{
38+
description = "AMI ID"
39+
type = string
40+
default = "ami-0c55b159cbfafe1f0"
41+
}}
42+
"""
43+
44+
github_actions = """name: Terraform CI
45+
46+
on:
47+
push:
48+
branches:
49+
- main
50+
pull_request:
51+
branches:
52+
- main
53+
54+
jobs:
55+
terraform:
56+
runs-on: ubuntu-latest
57+
58+
steps:
59+
- name: Checkout code
60+
uses: actions/checkout@v2
61+
62+
- name: Set up Terraform
63+
uses: hashicorp/setup-terraform@v1
64+
with:
65+
terraform_version: 1.0.0
66+
67+
- name: Terraform Init
68+
run: terraform init
69+
70+
- name: Terraform Plan
71+
run: terraform plan
72+
73+
- name: Terraform Apply
74+
run: terraform apply -auto-approve
75+
env:
76+
TF_VAR_region: ${{ secrets.AWS_REGION }}
77+
TF_VAR_instance_type: ${{ secrets.AWS_INSTANCE_TYPE }}
78+
TF_VAR_ami: ${{ secrets.AWS_AMI }}
79+
"""
80+
81+
with open(os.path.join(base_directory, "main.tf"), "w") as f:
82+
f.write(terraform_main)
83+
84+
with open(os.path.join(base_directory, "variables.tf"), "w") as f:
85+
f.write(terraform_variables)
86+
87+
with open(os.path.join(ci_directory, "terraform-ci.yml"), "w") as f:
88+
f.write(github_actions)

app/main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
from .models import (IaCBasicInput,
88
IaCBugfixInput,
99
Output,
10-
IaCInstallationInput,IaCTemplateGeneration)
10+
IaCInstallationInput,IaCTemplateGeneration,HelmTemplateGeneration)
1111

1212
from fastapi import FastAPI, HTTPException,Response
1313
from fastapi.responses import FileResponse
1414
from .prompt_generators import (IaC_basics_generator,
1515
IaC_bugfix_generator,
1616
IaC_installation_generator,
17-
IaC_template_generator)
17+
IaC_template_generator,helm_template_generator)
18+
1819
import os
1920
app = FastAPI()
2021

@@ -49,8 +50,17 @@ async def IaC_template_generation(request:IaCTemplateGeneration) -> Output:
4950

5051
generated_prompt = IaC_template_generator(request)
5152
output = gpt_service(generated_prompt)
52-
edit_directory_generator(output)
53-
execute_pythonfile()
53+
edit_directory_generator("terraform_generator",output)
54+
execute_pythonfile("MyTerraform","terraform_generator")
55+
return Output(output='output')
56+
57+
@app.post("/Helm-template/")
58+
async def Helm_template_generation(request:HelmTemplateGeneration) -> Output:
59+
60+
generated_prompt = helm_template_generator(request)
61+
output = gpt_service(generated_prompt)
62+
edit_directory_generator("helm_generator",output)
63+
execute_pythonfile("MyHelm","helm_generator")
5464
return Output(output='output')
5565

5666

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v1
21+
22+
- name: Cache Docker layers
23+
uses: actions/cache@v2
24+
with:
25+
path: /tmp/.buildx-cache
26+
key: ${{ runner.os }}-buildx-${{ github.sha }}
27+
restore-keys: |
28+
${{ runner.os }}-buildx-
29+
30+
- name: Build and push Docker image
31+
uses: docker/build-push-action@v2
32+
with:
33+
context: .
34+
file: Dockerfile
35+
push: true
36+
tags: myimage:latest

app/media/MyHelm/Chart.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v2
2+
name: myhelm
3+
description: A Helm chart for Kubernetes
4+
version: 0.1.0

0 commit comments

Comments
 (0)