diff --git a/app/directory_generators/helm_generator.py b/app/directory_generators/helm_generator.py index 4b8dde49..dae15e12 100644 --- a/app/directory_generators/helm_generator.py +++ b/app/directory_generators/helm_generator.py @@ -1,116 +1,122 @@ import os project_name = "app/media/MyHelm" -charts_dir = os.path.join(project_name, "charts") -templates_dir = os.path.join(project_name, "templates") -web_dir = os.path.join(templates_dir, "web") +directories = ["charts", "templates", "templates/web"] +files = ["Chart.yaml", "values.yaml"] +template_files = ["service.yaml", "deployment.yaml", "secrets.yaml", "helpers.tpl"] +ingress_enabled = False +stateless_enabled = True +persistence = True -# Create project directories -os.makedirs(charts_dir, exist_ok=True) -os.makedirs(templates_dir, exist_ok=True) -os.makedirs(web_dir, exist_ok=True) +os.makedirs(project_name, exist_ok=True) + +for directory in directories: + os.makedirs(os.path.join(project_name, directory), exist_ok=True) -# Create Chart.yaml with open(os.path.join(project_name, "Chart.yaml"), "w") as chart_file: chart_file.write("apiVersion: v2\n") chart_file.write("name: MyHelm\n") chart_file.write("description: A Helm chart for Kubernetes\n") chart_file.write("version: 0.1.0\n") -# Create values.yaml with open(os.path.join(project_name, "values.yaml"), "w") as values_file: values_file.write("web:\n") values_file.write(" image: nginx\n") values_file.write(" targetPort: 80\n") values_file.write(" replicas: 1\n") - values_file.write(" persistence:\n") - values_file.write(" size: 1Gi\n") - values_file.write(" accessModes:\n") - values_file.write(" - ReadWriteOnce\n") + if persistence: + values_file.write(" persistence:\n") + values_file.write(" size: 1Gi\n") + values_file.write(" accessModes: \n") + values_file.write(" - ReadWriteOnce\n") + if ingress_enabled: + values_file.write(" ingress:\n") + values_file.write(" enabled: true\n") + values_file.write(" host: www.example.com\n") + values_file.write(" stateless:\n") + values_file.write(" enabled: true\n") values_file.write(" env:\n") values_file.write(" - name: ENV1\n") values_file.write(" value: Hi\n") - values_file.write(" ingress:\n") - values_file.write(" enabled: false\n") - values_file.write(" host: www.example.com\n") - values_file.write(" stateless:\n") - values_file.write(" enabled: false\n") -# Create service.yaml -with open(os.path.join(web_dir, "service.yaml"), "w") as service_file: - service_file.write("apiVersion: v1\n") - service_file.write("kind: Service\n") - service_file.write("metadata:\n") - service_file.write(" name: web-service\n") - service_file.write("spec:\n") - service_file.write(" type: ClusterIP\n") - service_file.write(" ports:\n") - service_file.write(" - port: 80\n") - service_file.write(" targetPort: {{ .Values.web.targetPort }}\n") - service_file.write(" selector:\n") - service_file.write(" app: web\n") +for template in template_files: + with open(os.path.join(project_name, "templates", template), "w") as template_file: + if template == "service.yaml": + template_file.write("apiVersion: v1\n") + template_file.write("kind: Service\n") + template_file.write("metadata:\n") + template_file.write(" name: {{ .Release.Name }}-web\n") + template_file.write("spec:\n") + template_file.write(" ports:\n") + template_file.write(" - port: 80\n") + template_file.write(" targetPort: {{ .Values.web.targetPort }}\n") + template_file.write(" selector:\n") + template_file.write(" app: {{ .Release.Name }}-web\n") + + if stateless_enabled and template == "deployment.yaml": + template_file.write("apiVersion: apps/v1\n") + template_file.write("kind: Deployment\n") + template_file.write("metadata:\n") + template_file.write(" name: {{ .Release.Name }}-web\n") + template_file.write("spec:\n") + template_file.write(" replicas: {{ .Values.web.replicas }}\n") + template_file.write(" selector:\n") + template_file.write(" matchLabels:\n") + template_file.write(" app: {{ .Release.Name }}-web\n") + template_file.write(" template:\n") + template_file.write(" metadata:\n") + template_file.write(" labels:\n") + template_file.write(" app: {{ .Release.Name }}-web\n") + template_file.write(" spec:\n") + template_file.write(" containers:\n") + template_file.write(" - name: web\n") + template_file.write(" image: {{ .Values.web.image }}\n") + template_file.write(" ports:\n") + template_file.write(" - containerPort: {{ .Values.web.targetPort }}\n") + template_file.write(" env:\n") + template_file.write(" - name: {{ .Values.env[0].name }}\n") + template_file.write(" value: {{ .Values.env[0].value }}\n") -# Create statefulset.yaml (since stateless is false) -with open(os.path.join(web_dir, "statefulset.yaml"), "w") as statefulset_file: - statefulset_file.write("apiVersion: apps/v1\n") - statefulset_file.write("kind: StatefulSet\n") - statefulset_file.write("metadata:\n") - statefulset_file.write(" name: web\n") - statefulset_file.write("spec:\n") - statefulset_file.write(" serviceName: web-service\n") - statefulset_file.write(" replicas: {{ .Values.web.replicas }}\n") - statefulset_file.write(" selector:\n") - statefulset_file.write(" matchLabels:\n") - statefulset_file.write(" app: web\n") - statefulset_file.write(" template:\n") - statefulset_file.write(" metadata:\n") - statefulset_file.write(" labels:\n") - statefulset_file.write(" app: web\n") - statefulset_file.write(" spec:\n") - statefulset_file.write(" containers:\n") - statefulset_file.write(" - name: web\n") - statefulset_file.write(" image: {{ .Values.web.image }}\n") - statefulset_file.write(" ports:\n") - statefulset_file.write(" - containerPort: {{ .Values.web.targetPort }}\n") - statefulset_file.write(" env:\n") - statefulset_file.write(" - name: {{ .Values.web.env[0].name }}\n") - statefulset_file.write(" value: {{ .Values.web.env[0].value }}\n") - statefulset_file.write(" volumeClaimTemplates:\n") - statefulset_file.write(" - metadata:\n") - statefulset_file.write(" name: web-pvc\n") - statefulset_file.write(" spec:\n") - statefulset_file.write(" accessModes:\n") - statefulset_file.write(" - {{ .Values.web.persistence.accessModes[0] }}\n") - statefulset_file.write(" resources:\n") - statefulset_file.write(" requests:\n") - statefulset_file.write(" storage: {{ .Values.web.persistence.size }}\n") + if template == "secrets.yaml": + template_file.write("apiVersion: v1\n") + template_file.write("kind: Secret\n") + template_file.write("metadata:\n") + template_file.write(" name: {{ .Release.Name }}-secret\n") + template_file.write("type: Opaque\n") + template_file.write("data:\n") + template_file.write(" # Insert your base64 encoded secrets here\n") -# Create pvc.yaml -with open(os.path.join(web_dir, "pvc.yaml"), "w") as pvc_file: - pvc_file.write("apiVersion: v1\n") - pvc_file.write("kind: PersistentVolumeClaim\n") - pvc_file.write("metadata:\n") - pvc_file.write(" name: web-pvc\n") - pvc_file.write("spec:\n") - pvc_file.write(" accessModes:\n") - pvc_file.write(" - {{ .Values.web.persistence.accessModes[0] }}\n") - pvc_file.write(" resources:\n") - pvc_file.write(" requests:\n") - pvc_file.write(" storage: {{ .Values.web.persistence.size }}\n") + if template == "helpers.tpl": + template_file.write("{{/* Add your helper functions here */}}\n") -# Create secrets.yaml -with open(os.path.join(web_dir, "secrets.yaml"), "w") as secrets_file: - secrets_file.write("apiVersion: v1\n") - secrets_file.write("kind: Secret\n") - secrets_file.write("metadata:\n") - secrets_file.write(" name: web-secrets\n") - secrets_file.write("type: Opaque\n") - secrets_file.write("data:\n") - secrets_file.write(" # Add your base64 encoded secrets here\n") +if persistence: + with open(os.path.join(project_name, "templates", "pvc.yaml"), "w") as pvc_file: + pvc_file.write("apiVersion: v1\n") + pvc_file.write("kind: PersistentVolumeClaim\n") + pvc_file.write("metadata:\n") + pvc_file.write(" name: {{ .Release.Name }}-web-pvc\n") + pvc_file.write("spec:\n") + pvc_file.write(" accessModes:\n") + pvc_file.write(" - {{ .Values.web.persistence.accessModes | first }}\n") + pvc_file.write(" resources:\n") + pvc_file.write(" requests:\n") + pvc_file.write(" storage: {{ .Values.web.persistence.size }}\n") -# Create helpers.tpl -with open(os.path.join(web_dir, "helpers.tpl"), "w") as helpers_file: - helpers_file.write("# Define any helpers here\n") - helpers_file.write("define \"web.fullname\" \n") - helpers_file.write(" {{ .Release.Name }}-{{ .Values.web.name }} \n") - helpers_file.write("end\n") \ No newline at end of file +if ingress_enabled: + with open(os.path.join(project_name, "templates", "ingress.yaml"), "w") as ingress_file: + ingress_file.write("apiVersion: networking.k8s.io/v1\n") + ingress_file.write("kind: Ingress\n") + ingress_file.write("metadata:\n") + ingress_file.write(" name: {{ .Release.Name }}-web-ingress\n") + ingress_file.write("spec:\n") + ingress_file.write(" rules:\n") + ingress_file.write(" - host: {{ .Values.web.ingress.host }}\n") + ingress_file.write(" http:\n") + ingress_file.write(" paths:\n") + ingress_file.write(" - path: /\n") + ingress_file.write(" pathType: Prefix\n") + ingress_file.write(" backend:\n") + ingress_file.write(" service:\n") + ingress_file.write(" name: {{ .Release.Name }}-web\n") + ingress_file.write(" port:\n") + ingress_file.write(" number: 80\n") \ No newline at end of file diff --git a/app/directory_generators/jcasc_generator.py b/app/directory_generators/jcasc_generator.py new file mode 100644 index 00000000..e7e3bf15 --- /dev/null +++ b/app/directory_generators/jcasc_generator.py @@ -0,0 +1,37 @@ +import os +project_name = "app/media/MyJcasc" +jcasc_dir = os.path.join(project_name, "jcasc") +os.makedirs(jcasc_dir, exist_ok=True) + +jcasc_content = """ +systemMessage: "Welcome to Jenkins configured via JCasC" +author: + name: "admin" + password: "password" +allowSignup: true +allowAnonymousRead: true +cache_size: 1 +executors: 1 +required_plugins: + - "string" +views: + - list: + name: "All" +authorizationStrategy: + projectMatrix: + grantedPermissions: + - "Overall/Administer:admin" + - "Job/Read:developer" + - "Job/Build:developer" +tools: + git: + installations: + - name: "Default" + home: "/usr/bin/git" +security: + globalJobDslSecurityConfiguration: + useScriptSecurity: false +""" + +with open(os.path.join(jcasc_dir, "config.yaml"), "w") as f: + f.write(jcasc_content.strip()) \ No newline at end of file diff --git a/app/directory_generators/terraform_generator.py b/app/directory_generators/terraform_generator.py index 6a5a4eb5..f0c511a9 100644 --- a/app/directory_generators/terraform_generator.py +++ b/app/directory_generators/terraform_generator.py @@ -1,210 +1,196 @@ import os project_name = "app/media/MyTerraform" modules_dir = os.path.join(project_name, "modules") -argocd_dir = os.path.join(modules_dir, "argocd") +docker_dir = os.path.join(modules_dir, "docker") # Create project directories -os.makedirs(argocd_dir, exist_ok=True) +os.makedirs(docker_dir, exist_ok=True) # Create main.tf with open(os.path.join(project_name, "main.tf"), "w") as main_file: - main_file.write(''' -provider "argocd" { - server_addr = var.argocd_instance_info["server_addr"] - username = var.argocd_instance_info["username"] - password = var.argocd_instance_info["password"] - insecure = var.argocd_instance_info["insecure"] -} - -module "argocd" { - source = "./modules/argocd" - - repository_create = var.repository_create - argocd_repository_info = var.argocd_repository_info - application_create = var.application_create - argocd_application = var.argocd_application - argocd_sync_options = var.argocd_sync_options + main_file.write('''provider "docker" { + host = "unix:///var/run/docker.sock" } -''') -# Create variables.tf -with open(os.path.join(project_name, "variables.tf"), "w") as vars_file: - vars_file.write(''' -variable "argocd_instance_info" { - type = object({ - server_addr = string - username = string - password = string - insecure = bool - }) +module "docker" { + source = "./modules/docker" + + create_image = var.create_image + image_name = var.image_name + image_force_remove = var.image_force_remove + image_build = var.image_build + + create_container = var.create_container + container_image = var.container_image + container_name = var.container_name + container_hostname = var.container_hostname + container_restart = var.container_restart } +''') -variable "repository_create" { +# Create variables.tf +with open(os.path.join(project_name, "variables.tf"), "w") as variables_file: + variables_file.write('''variable "create_image" { type = bool } -variable "argocd_repository_info" { - type = map(string) +variable "image_name" { + type = string } -variable "application_create" { +variable "image_force_remove" { type = bool } -variable "argocd_application" { - type = map(string) +variable "image_build" { + type = object({ + context = string + tag = list(string) + }) +} + +variable "create_container" { + type = bool } -variable "argocd_sync_options" { - type = list(string) +variable "container_image" { + type = string } -''') -# Create terraform.tfvars -with open(os.path.join(project_name, "terraform.tfvars"), "w") as tfvars_file: - tfvars_file.write(''' -argocd_instance_info = { - server_addr = "ARGOCD_DOMAIN" - username = "admin" - password = "ARGOCD_ADMIN_PASS" - insecure = true +variable "container_name" { + type = string } -repository_create = false -argocd_repository_info = { - repo = "https://YOUR_REPO.git" - username = "USERNAME" - password = "CHANGE_ME_WITH_TOKEN" +variable "container_hostname" { + type = string } -application_create = true -argocd_application = { - name = "APPLICATION_NAME" - destination_server = "https://kubernetes.default.svc" - destination_namespace = "DESTINATION_NAMESPACE" - source_repo_url = "https://YOUR_REPO.git" - source_path = "SOURCE_PATH" - source_target_revision = "SOURCE_TARGET_REVISION" +variable "container_restart" { + type = string } +''') -argocd_sync_options = ["CreateNamespace=true", "ApplyOutOfSyncOnly=true", "FailOnSharedResource=true"] +# Create terraform.tfvars +with open(os.path.join(project_name, "terraform.tfvars"), "w") as tfvars_file: + tfvars_file.write('''create_image = true +image_name = "my-image" +image_force_remove = true +image_build = { + context = "./" + tag = ["my-image:latest"] +} + +create_container = false +container_image = "my-image" +container_name = "my-container" +container_hostname = "my-host" +container_restart = "always" ''') # Create versions.tf with open(os.path.join(project_name, "versions.tf"), "w") as versions_file: - versions_file.write(''' -terraform { + versions_file.write('''terraform { required_version = ">= 1.0" required_providers { - argocd = { - source = "oboukili/argocd" - version = ">= 6.0.2" + docker = { + source = "kreuzwerker/docker" + version = ">= 2.8.0" } } } ''') # Create module main.tf -with open(os.path.join(argocd_dir, "main.tf"), "w") as module_main_file: - module_main_file.write(''' -resource "argocd_repository" "repository" { - count = var.repository_create ? 1 : 0 - repo = var.argocd_repository_info["repo"] - username = var.argocd_repository_info["username"] - password = var.argocd_repository_info["password"] -} - -resource "argocd_application" "application" { - count = var.application_create ? 1 : 0 - depends_on = [argocd_repository.repository] - - metadata { - name = var.argocd_application["name"] - namespace = "argocd" - labels = { - using_sync_policy_options = "true" - } +with open(os.path.join(docker_dir, "main.tf"), "w") as module_main_file: + module_main_file.write('''resource "docker_image" "image" { + count = var.create_image ? 1 : 0 + name = var.image_name + force_remove = var.image_force_remove + + build { + context = var.image_build.context + tag = var.image_build.tag } +} - spec { - destination { - server = var.argocd_application["destination_server"] - namespace = var.argocd_application["destination_namespace"] - } - source { - repo_url = var.argocd_application["source_repo_url"] - path = var.argocd_application["source_path"] - target_revision = var.argocd_application["source_target_revision"] - } - sync_policy { - automated { - prune = false - self_heal = false - } - sync_options = var.argocd_sync_options - } - } +resource "docker_container" "container" { + count = var.create_container ? 1 : 0 + image = var.container_image + name = var.container_name + hostname = var.container_hostname + restart = var.container_restart } ''') # Create module variables.tf -with open(os.path.join(argocd_dir, "variables.tf"), "w") as module_vars_file: - module_vars_file.write(''' -variable "repository_create" { +with open(os.path.join(docker_dir, "variables.tf"), "w") as module_variables_file: + module_variables_file.write('''variable "create_image" { + type = bool +} + +variable "image_name" { + type = string +} + +variable "image_force_remove" { type = bool } -variable "argocd_repository_info" { - type = map(string) +variable "image_build" { + type = object({ + context = string + tag = list(string) + }) } -variable "application_create" { +variable "create_container" { type = bool } -variable "argocd_application" { - type = map(string) +variable "container_image" { + type = string +} + +variable "container_name" { + type = string +} + +variable "container_hostname" { + type = string } -variable "argocd_sync_options" { - type = list(string) +variable "container_restart" { + type = string } ''') # Create module terraform.tfvars -with open(os.path.join(argocd_dir, "terraform.tfvars"), "w") as module_tfvars_file: - module_tfvars_file.write(''' -repository_create = false -argocd_repository_info = { - repo = "https://YOUR_REPO.git" - username = "USERNAME" - password = "CHANGE_ME_WITH_TOKEN" -} - -application_create = true -argocd_application = { - name = "APPLICATION_NAME" - destination_server = "https://kubernetes.default.svc" - destination_namespace = "DESTINATION_NAMESPACE" - source_repo_url = "https://YOUR_REPO.git" - source_path = "SOURCE_PATH" - source_target_revision = "SOURCE_TARGET_REVISION" -} - -argocd_sync_options = ["CreateNamespace=true", "ApplyOutOfSyncOnly=true", "FailOnSharedResource=true"] +with open(os.path.join(docker_dir, "terraform.tfvars"), "w") as module_tfvars_file: + module_tfvars_file.write('''create_image = true +image_name = "my-image" +image_force_remove = true +image_build = { + context = "./" + tag = ["my-image:latest"] +} + +create_container = false +container_image = "my-image" +container_name = "my-container" +container_hostname = "my-host" +container_restart = "always" ''') # Create module versions.tf -with open(os.path.join(argocd_dir, "versions.tf"), "w") as module_versions_file: - module_versions_file.write(''' -terraform { +with open(os.path.join(docker_dir, "versions.tf"), "w") as module_versions_file: + module_versions_file.write('''terraform { required_version = ">= 1.0" required_providers { - argocd = { - source = "oboukili/argocd" - version = ">= 6.0.2" + docker = { + source = "kreuzwerker/docker" + version = ">= 2.8.0" } } } diff --git a/app/media/MyHelm/templates/_helpers.tpl b/app/media/MyHelm/templates/_helpers.tpl deleted file mode 100644 index 34090fa1..00000000 --- a/app/media/MyHelm/templates/_helpers.tpl +++ /dev/null @@ -1,6 +0,0 @@ -{{/* -Common template helpers -*/}} -{{- define "my-helm.fullname" -}} -{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/app/media/MyHelm/templates/deployment.yaml b/app/media/MyHelm/templates/deployment.yaml index cbf7a2f9..055e46c5 100644 --- a/app/media/MyHelm/templates/deployment.yaml +++ b/app/media/MyHelm/templates/deployment.yaml @@ -1,25 +1,22 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "myhelm.fullname" . }} + name: {{ .Release.Name }}-web spec: replicas: {{ .Values.web.replicas }} selector: matchLabels: - app: {{ include "myhelm.name" . }} + app: {{ .Release.Name }}-web template: metadata: labels: - app: {{ include "myhelm.name" . }} + app: {{ .Release.Name }}-web spec: containers: - - name: {{ .Values.web.image }} - image: {{ .Values.web.image }}:latest + - name: web + image: {{ .Values.web.image }} ports: - containerPort: {{ .Values.web.targetPort }} env: - {{- range .Values.web.env }} - - name: {{ .name }} - value: {{ .value }} - {{- end }} - \ No newline at end of file + - name: {{ .Values.env[0].name }} + value: {{ .Values.env[0].value }} diff --git a/app/media/MyHelm/templates/helpers.tpl b/app/media/MyHelm/templates/helpers.tpl index 4bb7cfc7..17772ced 100644 --- a/app/media/MyHelm/templates/helpers.tpl +++ b/app/media/MyHelm/templates/helpers.tpl @@ -1,14 +1 @@ -{{/* -Helper template functions -*/}} -{{- define "myhelm.name" -}} -{{- if .Chart.Name -}} -{{ .Chart.Name | quote }} -{{- else -}} -"" -{{- end -}} -{{- end -}} - -{{- define "myhelm.fullname" -}} -{{- .Release.Name | replace "-" "" }}-{{ include "myhelm.name" . }} -{{- end -}} +{{/* Add your helper functions here */}} diff --git a/app/media/MyHelm/templates/web/pvc.yaml b/app/media/MyHelm/templates/pvc.yaml similarity index 62% rename from app/media/MyHelm/templates/web/pvc.yaml rename to app/media/MyHelm/templates/pvc.yaml index 94f1548e..3a1063e3 100644 --- a/app/media/MyHelm/templates/web/pvc.yaml +++ b/app/media/MyHelm/templates/pvc.yaml @@ -1,10 +1,10 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: web-pvc + name: {{ .Release.Name }}-web-pvc spec: accessModes: - - {{ .Values.web.persistence.accessModes[0] }} + - {{ .Values.web.persistence.accessModes | first }} resources: requests: storage: {{ .Values.web.persistence.size }} diff --git a/app/media/MyHelm/templates/secrets.yaml b/app/media/MyHelm/templates/secrets.yaml index 47303d63..d5f704b8 100644 --- a/app/media/MyHelm/templates/secrets.yaml +++ b/app/media/MyHelm/templates/secrets.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Secret metadata: - name: {{ include "myhelm.fullname" . }}-secret + name: {{ .Release.Name }}-secret type: Opaque data: - # Add your secret data here + # Insert your base64 encoded secrets here diff --git a/app/media/MyHelm/templates/service.yaml b/app/media/MyHelm/templates/service.yaml index 63ab7b76..2440b8f5 100644 --- a/app/media/MyHelm/templates/service.yaml +++ b/app/media/MyHelm/templates/service.yaml @@ -1,11 +1,10 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "myhelm.fullname" . }} + name: {{ .Release.Name }}-web spec: - type: ClusterIP ports: - - port: {{ .Values.web.targetPort }} + - port: 80 targetPort: {{ .Values.web.targetPort }} selector: - app: {{ include "myhelm.name" . }} + app: {{ .Release.Name }}-web diff --git a/app/media/MyHelm/templates/web/helpers.tpl b/app/media/MyHelm/templates/web/helpers.tpl deleted file mode 100644 index 506945bd..00000000 --- a/app/media/MyHelm/templates/web/helpers.tpl +++ /dev/null @@ -1,4 +0,0 @@ -# Define any helpers here -define "web.fullname" - {{ .Release.Name }}-{{ .Values.web.name }} -end diff --git a/app/media/MyHelm/templates/web/ingress.yaml b/app/media/MyHelm/templates/web/ingress.yaml deleted file mode 100644 index e369b50e..00000000 --- a/app/media/MyHelm/templates/web/ingress.yaml +++ /dev/null @@ -1,17 +0,0 @@ - -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: web-ingress -spec: - rules: - - host: 123.com - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: web - port: - number: 80 diff --git a/app/media/MyHelm/templates/web/secrets.yaml b/app/media/MyHelm/templates/web/secrets.yaml deleted file mode 100644 index 4f1b6f8f..00000000 --- a/app/media/MyHelm/templates/web/secrets.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: web-secrets -type: Opaque -data: - # Add your base64 encoded secrets here diff --git a/app/media/MyHelm/templates/web/service.yaml b/app/media/MyHelm/templates/web/service.yaml deleted file mode 100644 index ced154e4..00000000 --- a/app/media/MyHelm/templates/web/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: web-service -spec: - type: ClusterIP - ports: - - port: 80 - targetPort: {{ .Values.web.targetPort }} - selector: - app: web diff --git a/app/media/MyHelm/templates/web/statefulset.yaml b/app/media/MyHelm/templates/web/statefulset.yaml deleted file mode 100644 index 6b98c7d2..00000000 --- a/app/media/MyHelm/templates/web/statefulset.yaml +++ /dev/null @@ -1,32 +0,0 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: web -spec: - serviceName: web-service - replicas: {{ .Values.web.replicas }} - selector: - matchLabels: - app: web - template: - metadata: - labels: - app: web - spec: - containers: - - name: web - image: {{ .Values.web.image }} - ports: - - containerPort: {{ .Values.web.targetPort }} - env: - - name: {{ .Values.web.env[0].name }} - value: {{ .Values.web.env[0].value }} - volumeClaimTemplates: - - metadata: - name: web-pvc - spec: - accessModes: - - {{ .Values.web.persistence.accessModes[0] }} - resources: - requests: - storage: {{ .Values.web.persistence.size }} diff --git a/app/media/MyHelm/values.yaml b/app/media/MyHelm/values.yaml index db28af7c..1e6f7cae 100644 --- a/app/media/MyHelm/values.yaml +++ b/app/media/MyHelm/values.yaml @@ -4,13 +4,10 @@ web: replicas: 1 persistence: size: 1Gi - accessModes: + accessModes: - ReadWriteOnce + stateless: + enabled: true env: - name: ENV1 value: Hi - ingress: - enabled: false - host: www.example.com - stateless: - enabled: false diff --git a/app/media/MyHelm_zip.zip b/app/media/MyHelm_zip.zip index 1e5d2815..fa238736 100644 Binary files a/app/media/MyHelm_zip.zip and b/app/media/MyHelm_zip.zip differ diff --git a/app/media/MyJcasc/jcasc/config.yaml b/app/media/MyJcasc/jcasc/config.yaml new file mode 100644 index 00000000..bbd9e88b --- /dev/null +++ b/app/media/MyJcasc/jcasc/config.yaml @@ -0,0 +1,27 @@ +systemMessage: "Welcome to Jenkins configured via JCasC" +author: + name: "admin" + password: "password" +allowSignup: true +allowAnonymousRead: true +cache_size: 1 +executors: 1 +required_plugins: + - "string" +views: + - list: + name: "All" +authorizationStrategy: + projectMatrix: + grantedPermissions: + - "Overall/Administer:admin" + - "Job/Read:developer" + - "Job/Build:developer" +tools: + git: + installations: + - name: "Default" + home: "/usr/bin/git" +security: + globalJobDslSecurityConfiguration: + useScriptSecurity: false \ No newline at end of file diff --git a/app/media/MyTerraform/main.tf b/app/media/MyTerraform/main.tf index 3deb6501..30e4c065 100644 --- a/app/media/MyTerraform/main.tf +++ b/app/media/MyTerraform/main.tf @@ -1,17 +1,18 @@ - -provider "argocd" { - server_addr = var.argocd_instance_info["server_addr"] - username = var.argocd_instance_info["username"] - password = var.argocd_instance_info["password"] - insecure = var.argocd_instance_info["insecure"] +provider "docker" { + host = "unix:///var/run/docker.sock" } -module "argocd" { - source = "./modules/argocd" - - repository_create = var.repository_create - argocd_repository_info = var.argocd_repository_info - application_create = var.application_create - argocd_application = var.argocd_application - argocd_sync_options = var.argocd_sync_options +module "docker" { + source = "./modules/docker" + + create_image = var.create_image + image_name = var.image_name + image_force_remove = var.image_force_remove + image_build = var.image_build + + create_container = var.create_container + container_image = var.container_image + container_name = var.container_name + container_hostname = var.container_hostname + container_restart = var.container_restart } diff --git a/app/media/MyTerraform/modules/argocd/main.tf b/app/media/MyTerraform/modules/argocd/main.tf deleted file mode 100644 index 38762cdb..00000000 --- a/app/media/MyTerraform/modules/argocd/main.tf +++ /dev/null @@ -1,39 +0,0 @@ - -resource "argocd_repository" "repository" { - count = var.repository_create ? 1 : 0 - repo = var.argocd_repository_info["repo"] - username = var.argocd_repository_info["username"] - password = var.argocd_repository_info["password"] -} - -resource "argocd_application" "application" { - count = var.application_create ? 1 : 0 - depends_on = [argocd_repository.repository] - - metadata { - name = var.argocd_application["name"] - namespace = "argocd" - labels = { - using_sync_policy_options = "true" - } - } - - spec { - destination { - server = var.argocd_application["destination_server"] - namespace = var.argocd_application["destination_namespace"] - } - source { - repo_url = var.argocd_application["source_repo_url"] - path = var.argocd_application["source_path"] - target_revision = var.argocd_application["source_target_revision"] - } - sync_policy { - automated { - prune = false - self_heal = false - } - sync_options = var.argocd_sync_options - } - } -} diff --git a/app/media/MyTerraform/modules/argocd/terraform.tfvars b/app/media/MyTerraform/modules/argocd/terraform.tfvars deleted file mode 100644 index 56d589ee..00000000 --- a/app/media/MyTerraform/modules/argocd/terraform.tfvars +++ /dev/null @@ -1,19 +0,0 @@ - -repository_create = false -argocd_repository_info = { - repo = "https://YOUR_REPO.git" - username = "USERNAME" - password = "CHANGE_ME_WITH_TOKEN" -} - -application_create = true -argocd_application = { - name = "APPLICATION_NAME" - destination_server = "https://kubernetes.default.svc" - destination_namespace = "DESTINATION_NAMESPACE" - source_repo_url = "https://YOUR_REPO.git" - source_path = "SOURCE_PATH" - source_target_revision = "SOURCE_TARGET_REVISION" -} - -argocd_sync_options = ["CreateNamespace=true", "ApplyOutOfSyncOnly=true", "FailOnSharedResource=true"] diff --git a/app/media/MyTerraform/modules/argocd/variables.tf b/app/media/MyTerraform/modules/argocd/variables.tf deleted file mode 100644 index 5d76fdc1..00000000 --- a/app/media/MyTerraform/modules/argocd/variables.tf +++ /dev/null @@ -1,20 +0,0 @@ - -variable "repository_create" { - type = bool -} - -variable "argocd_repository_info" { - type = map(string) -} - -variable "application_create" { - type = bool -} - -variable "argocd_application" { - type = map(string) -} - -variable "argocd_sync_options" { - type = list(string) -} diff --git a/app/media/MyTerraform/modules/argocd/versions.tf b/app/media/MyTerraform/modules/argocd/versions.tf deleted file mode 100644 index c2fa9111..00000000 --- a/app/media/MyTerraform/modules/argocd/versions.tf +++ /dev/null @@ -1,11 +0,0 @@ - -terraform { - required_version = ">= 1.0" - - required_providers { - argocd = { - source = "oboukili/argocd" - version = ">= 6.0.2" - } - } -} diff --git a/app/media/MyTerraform/modules/docker/main.tf b/app/media/MyTerraform/modules/docker/main.tf new file mode 100644 index 00000000..a312214a --- /dev/null +++ b/app/media/MyTerraform/modules/docker/main.tf @@ -0,0 +1,18 @@ +resource "docker_image" "image" { + count = var.create_image ? 1 : 0 + name = var.image_name + force_remove = var.image_force_remove + + build { + context = var.image_build.context + tag = var.image_build.tag + } +} + +resource "docker_container" "container" { + count = var.create_container ? 1 : 0 + image = var.container_image + name = var.container_name + hostname = var.container_hostname + restart = var.container_restart +} diff --git a/app/media/MyTerraform/modules/docker/terraform.tfvars b/app/media/MyTerraform/modules/docker/terraform.tfvars new file mode 100644 index 00000000..033c86d8 --- /dev/null +++ b/app/media/MyTerraform/modules/docker/terraform.tfvars @@ -0,0 +1,13 @@ +create_image = true +image_name = "my-image" +image_force_remove = true +image_build = { + context = "./" + tag = ["my-image:latest"] +} + +create_container = false +container_image = "my-image" +container_name = "my-container" +container_hostname = "my-host" +container_restart = "always" diff --git a/app/media/MyTerraform/modules/docker/variables.tf b/app/media/MyTerraform/modules/docker/variables.tf new file mode 100644 index 00000000..5cf1cd69 --- /dev/null +++ b/app/media/MyTerraform/modules/docker/variables.tf @@ -0,0 +1,38 @@ +variable "create_image" { + type = bool +} + +variable "image_name" { + type = string +} + +variable "image_force_remove" { + type = bool +} + +variable "image_build" { + type = object({ + context = string + tag = list(string) + }) +} + +variable "create_container" { + type = bool +} + +variable "container_image" { + type = string +} + +variable "container_name" { + type = string +} + +variable "container_hostname" { + type = string +} + +variable "container_restart" { + type = string +} diff --git a/app/media/MyTerraform/modules/docker/versions.tf b/app/media/MyTerraform/modules/docker/versions.tf new file mode 100644 index 00000000..255624a3 --- /dev/null +++ b/app/media/MyTerraform/modules/docker/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + docker = { + source = "kreuzwerker/docker" + version = ">= 2.8.0" + } + } +} diff --git a/app/media/MyTerraform/terraform.tfvars b/app/media/MyTerraform/terraform.tfvars index 163075df..033c86d8 100644 --- a/app/media/MyTerraform/terraform.tfvars +++ b/app/media/MyTerraform/terraform.tfvars @@ -1,26 +1,13 @@ - -argocd_instance_info = { - server_addr = "ARGOCD_DOMAIN" - username = "admin" - password = "ARGOCD_ADMIN_PASS" - insecure = true -} - -repository_create = false -argocd_repository_info = { - repo = "https://YOUR_REPO.git" - username = "USERNAME" - password = "CHANGE_ME_WITH_TOKEN" -} - -application_create = true -argocd_application = { - name = "APPLICATION_NAME" - destination_server = "https://kubernetes.default.svc" - destination_namespace = "DESTINATION_NAMESPACE" - source_repo_url = "https://YOUR_REPO.git" - source_path = "SOURCE_PATH" - source_target_revision = "SOURCE_TARGET_REVISION" +create_image = true +image_name = "my-image" +image_force_remove = true +image_build = { + context = "./" + tag = ["my-image:latest"] } -argocd_sync_options = ["CreateNamespace=true", "ApplyOutOfSyncOnly=true", "FailOnSharedResource=true"] +create_container = false +container_image = "my-image" +container_name = "my-container" +container_hostname = "my-host" +container_restart = "always" diff --git a/app/media/MyTerraform/variables.tf b/app/media/MyTerraform/variables.tf index 6cd53c28..5cf1cd69 100644 --- a/app/media/MyTerraform/variables.tf +++ b/app/media/MyTerraform/variables.tf @@ -1,29 +1,38 @@ +variable "create_image" { + type = bool +} + +variable "image_name" { + type = string +} -variable "argocd_instance_info" { +variable "image_force_remove" { + type = bool +} + +variable "image_build" { type = object({ - server_addr = string - username = string - password = string - insecure = bool + context = string + tag = list(string) }) } -variable "repository_create" { +variable "create_container" { type = bool } -variable "argocd_repository_info" { - type = map(string) +variable "container_image" { + type = string } -variable "application_create" { - type = bool +variable "container_name" { + type = string } -variable "argocd_application" { - type = map(string) +variable "container_hostname" { + type = string } -variable "argocd_sync_options" { - type = list(string) +variable "container_restart" { + type = string } diff --git a/app/media/MyTerraform/versions.tf b/app/media/MyTerraform/versions.tf index c2fa9111..255624a3 100644 --- a/app/media/MyTerraform/versions.tf +++ b/app/media/MyTerraform/versions.tf @@ -1,11 +1,10 @@ - terraform { required_version = ">= 1.0" required_providers { - argocd = { - source = "oboukili/argocd" - version = ">= 6.0.2" + docker = { + source = "kreuzwerker/docker" + version = ">= 2.8.0" } } } diff --git a/app/media/MyTerraform_zip.zip b/app/media/MyTerraform_zip.zip index f0cb2396..17dbb37c 100644 Binary files a/app/media/MyTerraform_zip.zip and b/app/media/MyTerraform_zip.zip differ diff --git a/app/prompt_generators.py b/app/prompt_generators.py index ecd444f8..34eaf6d1 100644 --- a/app/prompt_generators.py +++ b/app/prompt_generators.py @@ -72,7 +72,7 @@ def helm_template_generator(input : HelmTemplateGeneration) -> str: set stateless in pod based on {status}. - Based on values.yaml, create all necessary Kubernetes templates in the templates directory: + Based on values.yaml (Dont put json in .yaml files), create all necessary Kubernetes templates in the templates directory: if stateless.enabled is true, create deployment.yaml; if stateless.enabled is false, create statefulset.yaml. If a persistence block exists, include pvc.yaml. If the ingress block is defined and ingress.enabled is true, create ingress.yaml. if ingress.enabled is false, do not create ingress.yaml. Always create