From 756833884a67fa786559867e060aad2381c70b97 Mon Sep 17 00:00:00 2001 From: MT436 Date: Wed, 17 May 2023 13:28:11 +0000 Subject: [PATCH 1/2] changes to orginal file --- Dockerfile | 4 -- Jenkinsfile | 109 +++--------------------------- Jenkinsfile-ECR | 172 ------------------------------------------------ 3 files changed, 9 insertions(+), 276 deletions(-) delete mode 100644 Dockerfile delete mode 100644 Jenkinsfile-ECR diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 55f3d4d9..00000000 --- a/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM openjdk:8-jdk-alpine -WORKDIR /app -COPY ./target/*.jar /app.jar -CMD ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index d664b07d..291bff27 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,112 +1,21 @@ -@Library('my-shared-library') _ - -pipeline{ - +pipeline { agent any - - parameters{ - - choice(name: 'action', choices: 'create\ndelete', description: 'Choose create/Destroy') - string(name: 'ImageName', description: "name of the docker build", defaultValue: 'javapp') - string(name: 'ImageTag', description: "tag of the docker build", defaultValue: 'v1') - string(name: 'DockerHubUser', description: "name of the Application", defaultValue: 'vikashashoke') - } - stages{ - - stage('Git Checkout'){ - when { expression { params.action == 'create' } } - steps{ - gitCheckout( - branch: "main", - url: "https://github.com/vikash-kumar01/mrdevops_java_app.git" - ) - } - } - stage('Unit Test maven'){ - - when { expression { params.action == 'create' } } - - steps{ - script{ - - mvnTest() - } - } - } - stage('Integration Test maven'){ - when { expression { params.action == 'create' } } - steps{ - script{ - - mvnIntegrationTest() - } - } - } - stage('Static code analysis: Sonarqube'){ - when { expression { params.action == 'create' } } + stage('Integration testing : mvn'){ steps{ - script{ - - def SonarQubecredentialsId = 'sonarqube-api' - statiCodeAnalysis(SonarQubecredentialsId) - } + sh 'mvn test' } } - stage('Quality Gate Status Check : Sonarqube'){ - when { expression { params.action == 'create' } } + stage('build: unittest'){ steps{ - script{ - - def SonarQubecredentialsId = 'sonarqube-api' - QualityGateStatus(SonarQubecredentialsId) - } + sh 'mvn verify -DskipUnitTests' } } - stage('Maven Build : maven'){ - when { expression { params.action == 'create' } } + stage('build: maven'){ steps{ - script{ - - mvnBuild() - } + sh 'mvn clean package' } } - stage('Docker Image Build'){ - when { expression { params.action == 'create' } } - steps{ - script{ - - dockerBuild("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } - } - } - stage('Docker Image Scan: trivy '){ - when { expression { params.action == 'create' } } - steps{ - script{ - - dockerImageScan("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } - } - } - stage('Docker Image Push : DockerHub '){ - when { expression { params.action == 'create' } } - steps{ - script{ - - dockerImagePush("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } - } - } - stage('Docker Image Cleanup : DockerHub '){ - when { expression { params.action == 'create' } } - steps{ - script{ - - dockerImageCleanup("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } - } - } + } -} \ No newline at end of file +} diff --git a/Jenkinsfile-ECR b/Jenkinsfile-ECR deleted file mode 100644 index cfde210c..00000000 --- a/Jenkinsfile-ECR +++ /dev/null @@ -1,172 +0,0 @@ -@Library('my-shared-library') _ - -pipeline{ - - agent any - - parameters{ - - choice(name: 'action', choices: 'create\ndelete', description: 'Choose create/Destroy') - string(name: 'aws_account_id', description: " AWS Account ID", defaultValue: '496157679619') - string(name: 'Region', description: "Region of ECR", defaultValue: 'us-east-1') - string(name: 'ECR_REPO_NAME', description: "name of the ECR", defaultValue: 'vikashashoke') - string(name: 'cluster', description: "name of the EKS Cluster", defaultValue: 'demo-cluster1') - } - environment{ - - ACCESS_KEY = credentials('AWS_ACCESS_KEY_ID') - SECRET_KEY = credentials('AWS_SECRET_KEY_ID') - } - - stages{ - - stage('Git Checkout'){ - when { expression { params.action == 'create' } } - steps{ - gitCheckout( - branch: "main", - url: "https://github.com/vikash-kumar01/mrdevops_java_app.git" - ) - } - } - // stage('Unit Test maven'){ - - // when { expression { params.action == 'create' } } - - // steps{ - // script{ - - // mvnTest() - // } - // } - // } - // stage('Integration Test maven'){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ - - // mvnIntegrationTest() - // } - // } - // } - // stage('Static code analysis: Sonarqube'){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ - - // def SonarQubecredentialsId = 'sonarqube-api' - // statiCodeAnalysis(SonarQubecredentialsId) - // } - // } - // } - // stage('Quality Gate Status Check : Sonarqube'){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ - - // def SonarQubecredentialsId = 'sonarqube-api' - // QualityGateStatus(SonarQubecredentialsId) - // } - // } - // } - // stage('Maven Build : maven'){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ - - // mvnBuild() - // } - // } - // } - // stage('Docker Image Build : ECR'){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ - - // dockerBuild("${params.aws_account_id}","${params.Region}","${params.ECR_REPO_NAME}") - // } - // } - // } - // stage('Docker Image Scan: trivy '){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ - - // dockerImageScan("${params.aws_account_id}","${params.Region}","${params.ECR_REPO_NAME}") - // } - // } - // } - // stage('Docker Image Push : ECR '){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ - - // dockerImagePush("${params.aws_account_id}","${params.Region}","${params.ECR_REPO_NAME}") - // } - // } - // } - // stage('Docker Image Cleanup : ECR '){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ - - // dockerImageCleanup("${params.aws_account_id}","${params.Region}","${params.ECR_REPO_NAME}") - // } - // } - // } - stage('Create EKS Cluster : Terraform'){ - when { expression { params.action == 'create' } } - steps{ - script{ - - dir('eks_module') { - sh """ - - terraform init - terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY' -var 'region=${params.Region}' --var-file=./config/terraform.tfvars - terraform apply -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY' -var 'region=${params.Region}' --var-file=./config/terraform.tfvars --auto-approve - """ - } - } - } - } - stage('Connect to EKS '){ - when { expression { params.action == 'create' } } - steps{ - - script{ - - sh """ - aws configure set aws_access_key_id "$ACCESS_KEY" - aws configure set aws_secret_access_key "$SECRET_KEY" - aws configure set region "${params.Region}" - aws eks --region ${params.Region} update-kubeconfig --name ${params.cluster} - """ - } - } - } - stage('Deployment on EKS Cluster'){ - when { expression { params.action == 'create' } } - steps{ - script{ - - def apply = false - - try{ - input message: 'please confirm to deploy on eks', ok: 'Ready to apply the config ?' - apply = true - }catch(err){ - apply= false - currentBuild.result = 'UNSTABLE' - } - if(apply){ - - sh """ - kubectl apply -f . - """ - } - } - } - } - } -} \ No newline at end of file From a2219fc513da28c2f6eba401e50987e59b419812 Mon Sep 17 00:00:00 2001 From: MT436 Date: Thu, 18 May 2023 02:26:37 +0000 Subject: [PATCH 2/2] removed eks_modules --- eks_module/config/terraform.tfvars | 27 ----- eks_module/main.tf | 26 ----- eks_module/modules/aws_eks/main.tf | 72 ------------ eks_module/modules/aws_eks/output.tf | 3 - eks_module/modules/aws_eks/variables.tf | 14 --- eks_module/modules/aws_eks_nodegroup/main.tf | 110 ------------------ .../modules/aws_eks_nodegroup/variables.tf | 17 --- eks_module/provider.tf | 8 -- eks_module/variables.tf | 42 ------- eks_module/version.tf | 8 -- 10 files changed, 327 deletions(-) delete mode 100644 eks_module/config/terraform.tfvars delete mode 100644 eks_module/main.tf delete mode 100644 eks_module/modules/aws_eks/main.tf delete mode 100644 eks_module/modules/aws_eks/output.tf delete mode 100644 eks_module/modules/aws_eks/variables.tf delete mode 100644 eks_module/modules/aws_eks_nodegroup/main.tf delete mode 100644 eks_module/modules/aws_eks_nodegroup/variables.tf delete mode 100644 eks_module/provider.tf delete mode 100644 eks_module/variables.tf delete mode 100644 eks_module/version.tf diff --git a/eks_module/config/terraform.tfvars b/eks_module/config/terraform.tfvars deleted file mode 100644 index d7b59fde..00000000 --- a/eks_module/config/terraform.tfvars +++ /dev/null @@ -1,27 +0,0 @@ - -aws_eks_cluster_config = { - - "demo-cluster" = { - - eks_cluster_name = "demo-cluster1" - eks_subnet_ids = ["subnet-0c6265a3df91b7b61","subnet-0f9c4ff10c3526a4d","subnet-04919de8d00a175f3","subnet-080af72a4f9415d55"] - tags = { - "Name" = "demo-cluster" - } - } -} - -eks_node_group_config = { - - "node1" = { - - eks_cluster_name = "demo-cluster" - node_group_name = "mynode" - nodes_iam_role = "eks-node-group-general1" - node_subnet_ids = [subnet-0c6265a3df91b7b61","subnet-0f9c4ff10c3526a4d","subnet-04919de8d00a175f3","subnet-080af72a4f9415d55"] - - tags = { - "Name" = "node1" - } - } -} \ No newline at end of file diff --git a/eks_module/main.tf b/eks_module/main.tf deleted file mode 100644 index 6999778a..00000000 --- a/eks_module/main.tf +++ /dev/null @@ -1,26 +0,0 @@ - -module "aws_eks_cluster" { - - source = "./modules/aws_eks" - - for_each = var.aws_eks_cluster_config - - eks_cluster_name = each.value.eks_cluster_name - subnet_ids = each.value.eks_subnet_ids - tags = each.value.tags -} - -module "aws_eks_node_group" { - - source = "./modules/aws_eks_nodegroup" - - for_each = var.eks_node_group_config - - node_group_name = each.value.node_group_name - eks_cluster_name = module.aws_eks_cluster[each.value.eks_cluster_name].eks_cluster_name - subnet_ids = each.value.node_subnet_ids - nodes_iam_role = each.value.nodes_iam_role - tags = each.value.tags -} - - diff --git a/eks_module/modules/aws_eks/main.tf b/eks_module/modules/aws_eks/main.tf deleted file mode 100644 index 39f6c782..00000000 --- a/eks_module/modules/aws_eks/main.tf +++ /dev/null @@ -1,72 +0,0 @@ - -resource "aws_eks_cluster" "eks" { - # Name of the cluster. - name = var.eks_cluster_name - - # The Amazon Resource Name (ARN) of the IAM role that provides permissions for - # the Kubernetes control plane to make calls to AWS API operations on your behalf - role_arn = aws_iam_role.eks_cluster.arn - - # Desired Kubernetes master version - version = "1.24" - - vpc_config { - # Indicates whether or not the Amazon EKS private API server endpoint is enabled - endpoint_private_access = false - - # Indicates whether or not the Amazon EKS public API server endpoint is enabled - endpoint_public_access = true - - # Must be in at least two different availability zones - subnet_ids = var.subnet_ids - # subnet_ids = [ - # aws_subnet.public_1.id, - # aws_subnet.public_2.id, - # aws_subnet.private_1.id, - # aws_subnet.private_2.id - # ] - } - - # Ensure that IAM Role permissions are created before and deleted after EKS Cluster handling. - # Otherwise, EKS will not be able to properly delete EKS managed EC2 infrastructure such as Security Groups. - depends_on = [ - aws_iam_role_policy_attachment.amazon_eks_cluster_policy - ] - tags = var.tags -} - -resource "aws_iam_role" "eks_cluster" { - # The name of the role - name = "eks-cluster" - - # The policy that grants an entity permission to assume the role. - # Used to access AWS resources that you might not normally have access to. - # The role that Amazon EKS will use to create AWS resources for Kubernetes clusters - assume_role_policy = <