From a0db3d362366ebe3147b217d74e03c3633446fcd Mon Sep 17 00:00:00 2001 From: abolfazl1381 Date: Mon, 28 Oct 2024 10:43:18 +0330 Subject: [PATCH] add a prompt to generate a helm project --- app/__pycache__/main.cpython-311.pyc | Bin 4324 -> 5030 bytes app/__pycache__/models.cpython-311.pyc | Bin 2310 -> 2584 bytes .../prompt_generators.cpython-311.pyc | Bin 3218 -> 4151 bytes app/__pycache__/services.cpython-311.pyc | Bin 2593 -> 2636 bytes .../directory_generator.py | 98 ------------------ app/directory_generators/helm_generator.py | 82 +++++++++++++++ .../terraform_generator.py | 88 ++++++++++++++++ app/main.py | 18 +++- app/media/MyHelm/.github/workflows/ci.yml | 36 +++++++ app/media/MyHelm/Chart.yaml | 4 + app/media/MyHelm/values.yaml | 12 +++ .../{terraform.yml => terraform-ci.yml} | 11 +- app/media/MyTerraform/main.tf | 12 +++ app/media/MyTerraform/terraform/main.tf | 10 -- .../MyTerraform/terraform/modules/ec2/main.tf | 12 --- app/media/MyTerraform/terraform/outputs.tf | 3 - app/media/MyTerraform/terraform/variables.tf | 10 -- app/media/MyTerraform/variables.tf | 17 +++ app/models.py | 5 +- app/prompt_generators.py | 19 +++- app/services.py | 12 +-- app/test_services.py | 6 -- 22 files changed, 302 insertions(+), 153 deletions(-) delete mode 100644 app/directory_generators/directory_generator.py create mode 100644 app/directory_generators/helm_generator.py create mode 100644 app/directory_generators/terraform_generator.py create mode 100644 app/media/MyHelm/.github/workflows/ci.yml create mode 100644 app/media/MyHelm/Chart.yaml create mode 100644 app/media/MyHelm/values.yaml rename app/media/MyTerraform/.github/workflows/{terraform.yml => terraform-ci.yml} (62%) create mode 100644 app/media/MyTerraform/main.tf delete mode 100644 app/media/MyTerraform/terraform/main.tf delete mode 100644 app/media/MyTerraform/terraform/modules/ec2/main.tf delete mode 100644 app/media/MyTerraform/terraform/outputs.tf delete mode 100644 app/media/MyTerraform/terraform/variables.tf create mode 100644 app/media/MyTerraform/variables.tf delete mode 100644 app/test_services.py diff --git a/app/__pycache__/main.cpython-311.pyc b/app/__pycache__/main.cpython-311.pyc index 8f4f4af28653d232753d1ca65e2967f5dbefd24c..40186295028ecd347657d652d342d44dc90c8c58 100644 GIT binary patch delta 1766 zcmcIkOKclO7~b(dJhAJwoy4#B-Ly8Qijz{(BnovvselU73Q-iaqB3rFZCt!wGrOgP zOAsJYiBme49ubG22oOA_qK@k!{s>DC**dc9iz^vw<|1tk# zzWHZ=$!`_qF9HD{2jjQ7Y~x4&rW{8%H;XS^)n!FSoGPedE2xK*kRDdT`lvGM>ZI0~ zKCX-d&#B&4M2{*_J*LF;xDwYBN^;w$UM`N4! z%3@|9&^#)O*`d?`DL0h91}Q(3_R(nGr^%{c^VbD+{A1yv1jk|LBug;OsgW%N$zk?~ z8r4qJJ!55lZ?9E>sgKzMK= z1zbrW5m@>$M8>fgBn!l3adWvG$;0YIF4UH*SFbnf&G)JYk()-FoCI4IqLt}8QVvbh zThceBgSb&J_2Wv6drVw<&6^U7V0?mp>b(fwjyLCH2l)u*{^z%ZS3D}BvNyA#0<+}- z&|&rm;;fMY&v7dMm2ebb08zZ?j9D5XwYov{LD2?r{44912WpamAS4Z>B$628T{OLn z!;H9P%SZ8`4o>?{fprF^xk}N;U^#)3m14CehX`gRGN9ddL4A zdWyD>MX#KJz1tqL2#bT)jJBn20=iPcal(&q!K8$<@)@z!gmRqHfK2qZTy8D;wLfxb*MvtzVP&2*3Ig!|8W z0KGv>;{FcY_v}7Cx1ZfhWo0{jt^>ArmS{5*^Q?}+d2T2Mf9 vAY>!0M?yvW)N^|rtl!t&<&gZ&bDlKpqP5V5z^?6Yo3x)g delta 1141 zcmbtTO=uHA6wYRMlWA&p^Z(a0+1Q$&N>im)v5JR^NIg_gvAQ5Jb~hoon+>yDYDJK$ zcL{^ggNL44i=v0>$%}U{3G}qklOFVB!JAU?%{E0^Z#pn<-tYImeKWgS_?#2g{C=Mc zR%SR;|JK(Q63k?~a8YJl3a9Xzpo_Ao2jqYrl!K1XqlNUa90uK`c(sTgm7{u0j_GkZ zt|#P#lY_LRoOHWXaTS1HQgmm@DK)h+(C&uYpUQl?r;`#><_Gr-1B}d`@eYhE7!s6_ zpG;^lqULIDCHjOrfP1)?blj!HRvBmsdv_^urzG)L$&iAsx=Km%)@?C7DY4hcGj@{U zNQb>mrn!&hFw|p~3XY0?5bG?C!(j*NYE#8kOI0c@Z0Icur^ysQ!AlT~kq7(^N`Y45 zaD*&*!sS6QOo}8)63)VDN2jajD|hDWwZ^?l536A`@esr^P+un79*N13p!ZFwhZKd- zE*lTkC>y*Vmwff6`6J*j5FeU>>YGUN(XNkSe}7IMa#zUgA(3472%g>PkzXi2%)D~% z9~caUoxy3^U;spk$1$?wO9%(LE%goh3J@QIZC)lX`bI`pVqH|+M8ys&ZlP2cr8iN! zgVI}KbooX{%y-57rkL-bJkD*b^)E0?k!1ZDe}Hxh(M~Kbl1u(<(ixFoF&3JdQB^9n zhNj{PNH|R%`R~Sapxqb8w1#PoDh;g8Sq5Ij7Z@4u39z=L1!44vRQXwO2v6pKhRm-Q06uD9KHxX`U99x$?JeJbzp=(8iY_$B}q9P%Xq{ier7RkwX*!`4J@g1tG;X I`8Yha{H{kk1Ij#rl)CbNpxIoBWW|900eP6+-|3 diff --git a/app/__pycache__/prompt_generators.cpython-311.pyc b/app/__pycache__/prompt_generators.cpython-311.pyc index c0606ae424e93b60b478d2e19cec7cafc455d25c..9ffae021d6821d8c17f507c494bacd64bfa8e255 100644 GIT binary patch delta 1315 zcmb7CJxmlq6yDjNJJ{m@fdB%+BSGN|ff%t6(U@QqiZfATb4Fpjox5AJKbM&~42kA2 z(aHwg!phoM8WJT|_BIw)be2?JVqvuM&2oo#iZM>I-^@4re!lnSJv;gqI$x&KwuWo^ z>{xLxwbeOT<;b3Ej^+?g^GS~QdQSI^oZ*`})36nkrToSon=N9rd zpY3vMsC%48}gLXenZRHdju0_tgWrA)xX3%|MiDQgtSFjeH78tmr3vT z8~qzer_hXd#I`&gy)#D#I@L{=f^Gz%BLMK8=!-c-1|!>gLi)Bhts&B%#y`7yD1Nhh zp8zr(eNJ2>ebJ_MY5RWiqCwKpjy-;|C7|-|U#5#IlKEwiO14sD0pnDLoR39D>gI4C zn&ed-jb-3LeP2hSY;xep3*#YqK(JclD!q<&cC=uQRma%&ER}{La#K@p0sELH9T%}dlOGH@Q~9CmG{CB#7jEKe}N4A`uYyG+15 z+=}ZGv(u30j@laX#O&?nDAiv&_rnxiFAlI6_hp^>9-M$R>Q$JSQOs`khO)=7IuK0a zqlwUGvZVAotUxQC#LDXZjpNY3`6JTA!F$C`zp_79Y6O~wBf66qsR{@=tgf!^-=78+ zNWR`8CPVl!9J$sZ$BW$oHBN^O?>PQFho6{4*wAWbM`w4<*3Qg-np>)+6ww-RWaDye zNbBg?$Z|F8S2G>aN@}FalSpt8DBdf^~^iq zkUC3@hPS=tMW@G&_E|ShOw_^s`dEiHfGWq9#|NBG%+fC<#~H87j}^9KI#A6a7hkC^l4uq3%Oz?5ceUa^h8AT>jNA ztt{hiZXASXEiVq-X3!3}7k4W8b&)YWU-@`PwuC z2-f#xWTpPrROPHB%E3}$ClEg#18pN04|LdUTthp^mYT#SE$G=j>Pw=!RFhu*bN6po z4f8wlLPTEL9LZHG3A@N>-Yv6@>;6CGo=Ys~hLq(tBIn@aWAv+xzN zFVAT2@QlX4NnvXd=G`8+YD)a4lEOB>q*5&L7wQC&?o0fG8q;eSOzTa;zp9fL4vQA_ z?jHHY$VN9%+*sNS2#;&jF6I*as&*TX@f~eUVP{}Y{z=PF;;V&n$)=2rf#l}{pqcaHrmxjdq`In z_?qrMnBQCVLi2re^h{UJczWhQR=2KsR%#FaRH~1TJlB=yyhAuA;VZ3kX$!TjKzfR_ zPYtExq#aivj|Y9F>K0256HmcL1f2)+wL;EubCn`fgft|GUpE4(cqcZ^myOdn$*abb PNE-K05dV)^2=4v?pmnJ% delta 613 zcmX>jvQUI~IWI340}#wrkxQ@N$jip!$Oz&>0UMBJ2I9|6Kw>&W36fk2V+zwUCI*Jp zKnww<47H3kj0+eiE3&CfZeTHIVfL%ipS+tz(kUggC^fkxzo;@kJvA@2C=tliE2zB1 zSgy%*izUAxHSZQ{c~NFbDv--vP+5|ZpBJB;pOSiuB`q^2wHRc=_d#yR)S-GEQF0rpnA%$2j>ao6_X}Y#NjG*+nHe{HjC~3kvje zQ&Tb%^?fTtQj3Zb)AEaQCkL@7aGFD$YpekBrxESElG`sm;~~1kv>pD4~UC50f`2N8@wtFZg<%^TguyOn`$S7U1XQJ z!Y=cHfrHg|auY{MkoQFnpDP?b7dU+Gvaq#yUf^@T$l`H@#p41D6^jGSS*-5J&2W&L z%Tb&8ps1ju8uLLlRv=rG`xa|yNoG!Q5hz@WBteA6TZlX-=wLk@4gOoW1g%j2{@d8L^RIO#o9CpfUge diff --git a/app/directory_generators/directory_generator.py b/app/directory_generators/directory_generator.py deleted file mode 100644 index 92e7a28a..00000000 --- a/app/directory_generators/directory_generator.py +++ /dev/null @@ -1,98 +0,0 @@ -import os - -project_name = "MyTerraform" -base_dir = "app/media/" -terraform_dir = os.path.join(base_dir, project_name, "terraform") -modules_dir = os.path.join(terraform_dir, "modules") -ci_dir = os.path.join(base_dir, project_name, ".github", "workflows") - -os.makedirs(terraform_dir, exist_ok=True) -os.makedirs(modules_dir, exist_ok=True) -os.makedirs(ci_dir, exist_ok=True) - -# Create main.tf -with open(os.path.join(terraform_dir, "main.tf"), 'w') as f: - f.write(f'''provider "aws" {{ - region = "us-west-2" -}} - -module "ec2_instance" {{ - source = "./modules/ec2" - - instance_type = "t2.micro" - ami = "ami-0c55b159cbfafe1f0" # Update with a valid AMI ID -}} -''') - -# Create variables.tf -with open(os.path.join(terraform_dir, "variables.tf"), 'w') as f: - f.write('''variable "instance_type" { - description = "Type of EC2 instance" - type = string - default = "t2.micro" -} - -variable "ami" { - description = "AMI ID for the EC2 instance" - type = string -} -''') - -# Create outputs.tf -with open(os.path.join(terraform_dir, "outputs.tf"), 'w') as f: - f.write('''output "instance_id" { - value = module.ec2_instance.instance_id -} -''') - -# Create EC2 module directory -ec2_module_dir = os.path.join(modules_dir, "ec2") -os.makedirs(ec2_module_dir, exist_ok=True) - -# Create ec2/main.tf for the module -with open(os.path.join(ec2_module_dir, "main.tf"), 'w') as f: - f.write('''resource "aws_instance" "this" { - ami = var.ami - instance_type = var.instance_type - - tags = { - Name = "TerraformEC2Instance" - } -} - -output "instance_id" { - value = aws_instance.this.id -} -''') - -# Create CI pipeline file -with open(os.path.join(ci_dir, "terraform.yml"), 'w') as f: - f.write('''name: Terraform - -on: - push: - branches: - - main - -jobs: - terraform: - runs-on: ubuntu-latest - - steps: - - name: Checkout Code - uses: actions/checkout@v2 - - - name: Set up Terraform - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: 1.0.0 - - - name: Terraform Init - run: terraform init - - - name: Terraform Plan - run: terraform plan - - - name: Terraform Apply - run: terraform apply -auto-approve -''') \ No newline at end of file diff --git a/app/directory_generators/helm_generator.py b/app/directory_generators/helm_generator.py new file mode 100644 index 00000000..a9e125cd --- /dev/null +++ b/app/directory_generators/helm_generator.py @@ -0,0 +1,82 @@ +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 +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 + 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 +""") \ No newline at end of file diff --git a/app/directory_generators/terraform_generator.py b/app/directory_generators/terraform_generator.py new file mode 100644 index 00000000..ae23fedb --- /dev/null +++ b/app/directory_generators/terraform_generator.py @@ -0,0 +1,88 @@ +import os + +project_name = "app/media/MyTerraform" +base_directory = project_name.replace("/", os.sep) +modules_directory = os.path.join(base_directory, "modules") +ci_directory = os.path.join(base_directory, ".github", "workflows") + +os.makedirs(modules_directory, exist_ok=True) +os.makedirs(ci_directory, exist_ok=True) + +terraform_main = f"""provider "aws" {{ + region = "us-east-1" +}} + +resource "aws_instance" "web" {{ + ami = "ami-0c55b159cbfafe1f0" + instance_type = "t2.micro" + + tags = {{ + Name = "MyEC2Instance" + }} +}} +""" + +terraform_variables = """variable "region" {{ + description = "AWS region" + type = string + default = "us-east-1" +}} + +variable "instance_type" {{ + description = "EC2 Instance type" + type = string + default = "t2.micro" +}} + +variable "ami" {{ + description = "AMI ID" + type = string + default = "ami-0c55b159cbfafe1f0" +}} +""" + +github_actions = """name: Terraform CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + terraform: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v1 + with: + terraform_version: 1.0.0 + + - name: Terraform Init + run: terraform init + + - name: Terraform Plan + run: terraform plan + + - name: Terraform Apply + run: terraform apply -auto-approve + env: + TF_VAR_region: ${{ secrets.AWS_REGION }} + TF_VAR_instance_type: ${{ secrets.AWS_INSTANCE_TYPE }} + TF_VAR_ami: ${{ secrets.AWS_AMI }} +""" + +with open(os.path.join(base_directory, "main.tf"), "w") as f: + f.write(terraform_main) + +with open(os.path.join(base_directory, "variables.tf"), "w") as f: + f.write(terraform_variables) + +with open(os.path.join(ci_directory, "terraform-ci.yml"), "w") as f: + f.write(github_actions) \ No newline at end of file diff --git a/app/main.py b/app/main.py index 0f9cface..56372f14 100644 --- a/app/main.py +++ b/app/main.py @@ -7,14 +7,15 @@ from .models import (IaCBasicInput, IaCBugfixInput, Output, - IaCInstallationInput,IaCTemplateGeneration) + IaCInstallationInput,IaCTemplateGeneration,HelmTemplateGeneration) from fastapi import FastAPI, HTTPException,Response from fastapi.responses import FileResponse from .prompt_generators import (IaC_basics_generator, IaC_bugfix_generator, IaC_installation_generator, - IaC_template_generator) + IaC_template_generator,helm_template_generator) + import os app = FastAPI() @@ -49,8 +50,17 @@ async def IaC_template_generation(request:IaCTemplateGeneration) -> Output: generated_prompt = IaC_template_generator(request) output = gpt_service(generated_prompt) - edit_directory_generator(output) - execute_pythonfile() + edit_directory_generator("terraform_generator",output) + execute_pythonfile("MyTerraform","terraform_generator") + return Output(output='output') + +@app.post("/Helm-template/") +async def Helm_template_generation(request:HelmTemplateGeneration) -> Output: + + generated_prompt = helm_template_generator(request) + output = gpt_service(generated_prompt) + edit_directory_generator("helm_generator",output) + execute_pythonfile("MyHelm","helm_generator") return Output(output='output') diff --git a/app/media/MyHelm/.github/workflows/ci.yml b/app/media/MyHelm/.github/workflows/ci.yml new file mode 100644 index 00000000..6f41b6c7 --- /dev/null +++ b/app/media/MyHelm/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +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 diff --git a/app/media/MyHelm/Chart.yaml b/app/media/MyHelm/Chart.yaml new file mode 100644 index 00000000..e4501d66 --- /dev/null +++ b/app/media/MyHelm/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v2 +name: myhelm +description: A Helm chart for Kubernetes +version: 0.1.0 diff --git a/app/media/MyHelm/values.yaml b/app/media/MyHelm/values.yaml new file mode 100644 index 00000000..0739cc7c --- /dev/null +++ b/app/media/MyHelm/values.yaml @@ -0,0 +1,12 @@ +# Default values for myhelm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: + repository: myimage + pullPolicy: IfNotPresent + tag: "" +service: + name: myservice + type: ClusterIP + port: 80 diff --git a/app/media/MyTerraform/.github/workflows/terraform.yml b/app/media/MyTerraform/.github/workflows/terraform-ci.yml similarity index 62% rename from app/media/MyTerraform/.github/workflows/terraform.yml rename to app/media/MyTerraform/.github/workflows/terraform-ci.yml index 6e433644..8c6e977e 100644 --- a/app/media/MyTerraform/.github/workflows/terraform.yml +++ b/app/media/MyTerraform/.github/workflows/terraform-ci.yml @@ -1,16 +1,19 @@ -name: Terraform +name: Terraform CI on: push: branches: - main + pull_request: + branches: + - main jobs: terraform: runs-on: ubuntu-latest steps: - - name: Checkout Code + - name: Checkout code uses: actions/checkout@v2 - name: Set up Terraform @@ -26,3 +29,7 @@ jobs: - name: Terraform Apply run: terraform apply -auto-approve + env: + TF_VAR_region: ${{ secrets.AWS_REGION }} + TF_VAR_instance_type: ${{ secrets.AWS_INSTANCE_TYPE }} + TF_VAR_ami: ${{ secrets.AWS_AMI }} diff --git a/app/media/MyTerraform/main.tf b/app/media/MyTerraform/main.tf new file mode 100644 index 00000000..71842c53 --- /dev/null +++ b/app/media/MyTerraform/main.tf @@ -0,0 +1,12 @@ +provider "aws" { + region = "us-east-1" +} + +resource "aws_instance" "web" { + ami = "ami-0c55b159cbfafe1f0" + instance_type = "t2.micro" + + tags = { + Name = "MyEC2Instance" + } +} diff --git a/app/media/MyTerraform/terraform/main.tf b/app/media/MyTerraform/terraform/main.tf deleted file mode 100644 index b80468fe..00000000 --- a/app/media/MyTerraform/terraform/main.tf +++ /dev/null @@ -1,10 +0,0 @@ -provider "aws" { - region = "us-west-2" -} - -module "ec2_instance" { - source = "./modules/ec2" - - instance_type = "t2.micro" - ami = "ami-0c55b159cbfafe1f0" # Update with a valid AMI ID -} diff --git a/app/media/MyTerraform/terraform/modules/ec2/main.tf b/app/media/MyTerraform/terraform/modules/ec2/main.tf deleted file mode 100644 index 32f2548f..00000000 --- a/app/media/MyTerraform/terraform/modules/ec2/main.tf +++ /dev/null @@ -1,12 +0,0 @@ -resource "aws_instance" "this" { - ami = var.ami - instance_type = var.instance_type - - tags = { - Name = "TerraformEC2Instance" - } -} - -output "instance_id" { - value = aws_instance.this.id -} diff --git a/app/media/MyTerraform/terraform/outputs.tf b/app/media/MyTerraform/terraform/outputs.tf deleted file mode 100644 index 32d38a1d..00000000 --- a/app/media/MyTerraform/terraform/outputs.tf +++ /dev/null @@ -1,3 +0,0 @@ -output "instance_id" { - value = module.ec2_instance.instance_id -} diff --git a/app/media/MyTerraform/terraform/variables.tf b/app/media/MyTerraform/terraform/variables.tf deleted file mode 100644 index 74042d15..00000000 --- a/app/media/MyTerraform/terraform/variables.tf +++ /dev/null @@ -1,10 +0,0 @@ -variable "instance_type" { - description = "Type of EC2 instance" - type = string - default = "t2.micro" -} - -variable "ami" { - description = "AMI ID for the EC2 instance" - type = string -} diff --git a/app/media/MyTerraform/variables.tf b/app/media/MyTerraform/variables.tf new file mode 100644 index 00000000..e3b293c4 --- /dev/null +++ b/app/media/MyTerraform/variables.tf @@ -0,0 +1,17 @@ +variable "region" {{ + description = "AWS region" + type = string + default = "us-east-1" +}} + +variable "instance_type" {{ + description = "EC2 Instance type" + type = string + default = "t2.micro" +}} + +variable "ami" {{ + description = "AMI ID" + type = string + default = "ami-0c55b159cbfafe1f0" +}} diff --git a/app/models.py b/app/models.py index 63d95a7c..b3561532 100644 --- a/app/models.py +++ b/app/models.py @@ -25,7 +25,10 @@ class IaCTemplateGeneration(BaseModel): CI_integration:bool = True base_config:str = 'ec2' service:str = 'terraform' - + +class HelmTemplateGeneration(BaseModel): + CI_integration:bool = True + class Output(BaseModel): diff --git a/app/prompt_generators.py b/app/prompt_generators.py index 2ff89dfd..b0355450 100644 --- a/app/prompt_generators.py +++ b/app/prompt_generators.py @@ -1,6 +1,6 @@ from .models import (IaCBasicInput, IaCBugfixInput, - IaCInstallationInput, IaCTemplateGeneration) + IaCInstallationInput, IaCTemplateGeneration,HelmTemplateGeneration) def IaC_basics_generator(input : IaCBasicInput) -> str: @@ -53,5 +53,22 @@ def IaC_template_generator(input : IaCTemplateGeneration) -> str: the final terraform template must work very well without any error! + """ + return prompt + +def helm_template_generator(input : HelmTemplateGeneration) -> str: + + prompt = f""" + generate a correct python code to generate a helm project structure (project name: app/media/MyHelm) + based on the latest version of helm chart. + just generate a code to generate a folder as project template. don't consider base_dir + + CI integrated (using github actions) = {input.CI_integration}. + consider these directories : [charts/, crds/, templates/] + consider these files : Chart.yaml & values.yaml + + please set a something default in chart.yaml and values.yaml + + just Generate a python code without any additional notes or ```python3 entry """ return prompt \ No newline at end of file diff --git a/app/services.py b/app/services.py index 868cc423..d7d43569 100644 --- a/app/services.py +++ b/app/services.py @@ -34,17 +34,17 @@ def write_installation(request,output): save_to_mongo(data, index=['os','service'], collection = 'installation') -def edit_directory_generator(python_code): +def edit_directory_generator(gen_file,python_code): - with open('app/directory_generators/directory_generator.py', 'w') as file: + with open(f"app/directory_generators/{gen_file}.py", 'w') as file: file.write(python_code) -def execute_pythonfile(): - folder = 'app/media/MyTerraform' +def execute_pythonfile(folder,gen_file): + folder = f"app/media/{folder}" if os.path.isdir(folder): try: @@ -53,5 +53,5 @@ def execute_pythonfile(): except Exception as e: raise HTTPException(status_code=400, detail='please try again') - os.system('python3 app/directory_generators/directory_generator.py') - os.system('python3 app/directory_generators/directory_generator.py') + os.system(f"python3 app/directory_generators/{gen_file}.py") + os.system(f"python3 app/directory_generators/{gen_file}.py") diff --git a/app/test_services.py b/app/test_services.py deleted file mode 100644 index a05cbb3d..00000000 --- a/app/test_services.py +++ /dev/null @@ -1,6 +0,0 @@ -from .utils import save_QA_to_mongo - -def test_mongo_save(): - save_QA_to_mongo('q','a') - -