diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..b84f89c3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive", + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 55f3d4d9..0eba811e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ FROM openjdk:8-jdk-alpine WORKDIR /app COPY ./target/*.jar /app.jar -CMD ["java", "-jar", "app.jar"] \ No newline at end of file +CMD [ "java", "-jar", "app.jar" ] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index d664b07d..e2f1a6b4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,106 +7,105 @@ pipeline{ 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') + 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 Application', defaultValue: 'emmaochai') } - stages{ - - stage('Git Checkout'){ - when { expression { params.action == 'create' } } + stages{ + + stage("Git Checkout"){ + when { expression { params.action == 'create' } } + steps{ gitCheckout( - branch: "main", - url: "https://github.com/vikash-kumar01/mrdevops_java_app.git" - ) + branch: "devops", + url: "https://github.com/EmmanuelAudu/java_ap.git" + ) + } } - stage('Unit Test maven'){ - - when { expression { params.action == 'create' } } + stage("Unit Test Maven"){ + when { expression { params.action == 'create' } } + steps{ + script{ + mvnTest() + } + } + } + stage("Integration Test Maven"){ + when { expression { params.action == 'create' } } steps{ - script{ - - mvnTest() - } + script{ + mvnIntegrationTest() + } } - } - stage('Integration Test maven'){ - when { expression { params.action == 'create' } } + } + stage("Static code analysis: Sonarqube"){ + when { expression { params.action == 'create' } } steps{ - script{ - - mvnIntegrationTest() - } - } - } - stage('Static code analysis: Sonarqube'){ - when { expression { params.action == 'create' } } - steps{ - script{ - - def SonarQubecredentialsId = 'sonarqube-api' + script{ + + def SonarQubecredentialsId = 'sonar-api' statiCodeAnalysis(SonarQubecredentialsId) - } + } } - } - stage('Quality Gate Status Check : Sonarqube'){ - when { expression { params.action == 'create' } } + } + stage("Quality Gate Status Check: Sonarqube"){ + when { expression { params.action == 'create' } } steps{ - script{ - - def SonarQubecredentialsId = 'sonarqube-api' + script{ + + def SonarQubecredentialsId = 'sonar-api' QualityGateStatus(SonarQubecredentialsId) - } + } } - } - stage('Maven Build : maven'){ - when { expression { params.action == 'create' } } + } + stage("Maven Build: maven"){ + when { expression { params.action == 'create' } } steps{ - script{ - - mvnBuild() - } + script{ + + mvnBuild() + } } - } - stage('Docker Image Build'){ - when { expression { params.action == 'create' } } + } + stage("Docker Image Build"){ + when { expression { params.action == 'create' } } steps{ - script{ - - dockerBuild("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } + script{ + + dockerBuild("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + } } - } - stage('Docker Image Scan: trivy '){ - when { expression { params.action == 'create' } } + } + stage("Docker Image Scan: trivy"){ + when { expression { params.action == 'create' } } steps{ - script{ - - dockerImageScan("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } + script{ + + dockerImageScan("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + } } - } - stage('Docker Image Push : DockerHub '){ - when { expression { params.action == 'create' } } + } + stage("Docker Image Push: DockerHub"){ + when { expression { params.action == 'create' } } steps{ - script{ - - dockerImagePush("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } + script{ + + dockerImagePush("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + } } - } - stage('Docker Image Cleanup : DockerHub '){ - when { expression { params.action == 'create' } } + } + stage("Docker Image Cleanup: DockerHub"){ + when { expression { params.action == 'create' } } steps{ - script{ - - dockerImageCleanup("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } + script{ + + dockerImageCleanup("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + } } - } + } } -} \ No newline at end of file +} diff --git a/Jenkinsfile-ECR b/Jenkinsfile-ECR index cfde210c..e24fd4ed 100644 --- a/Jenkinsfile-ECR +++ b/Jenkinsfile-ECR @@ -7,166 +7,105 @@ pipeline{ 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') + string(name: 'aws_account_id', description: 'AWS Account ID', defaultValue: '964164841833') + string(name: 'Region', description: 'Region of ECR', defaultValue: 'us-east-1') + string(name: 'ECR_REPO_NAME', description: 'name of the ECR', defaultValue: 'emmydevops') } - environment{ - ACCESS_KEY = credentials('AWS_ACCESS_KEY_ID') - SECRET_KEY = credentials('AWS_SECRET_KEY_ID') - } + stages{ + + stage("Git Checkout"){ + when { expression { params.action == 'create' } } - stages{ - - stage('Git Checkout'){ - when { expression { params.action == 'create' } } steps{ gitCheckout( - branch: "main", - url: "https://github.com/vikash-kumar01/mrdevops_java_app.git" - ) + branch: "devops", + url: "https://github.com/EmmanuelAudu/java_ap.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' } } + stage("Unit Test Maven"){ + when { expression { params.action == 'create' } } + steps{ + script{ + mvnTest() + } + } + } + stage("Integration Test Maven"){ + 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 - """ - } + mvnIntegrationTest() } } - } - stage('Connect to EKS '){ - when { expression { params.action == 'create' } } - steps{ + } + stage("Static code analysis: Sonarqube"){ + when { expression { params.action == 'create' } } + steps{ + script{ - script{ + def SonarQubecredentialsId = 'sonar-api' + statiCodeAnalysis(SonarQubecredentialsId) + } + } + } + stage("Quality Gate Status Check: Sonarqube"){ + 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} - """ + def SonarQubecredentialsId = 'sonar-api' + QualityGateStatus(SonarQubecredentialsId) + } + } + } + stage("Maven Build: maven"){ + when { expression { params.action == 'create' } } + steps{ + script{ + + mvnBuild() + } } } - } - stage('Deployment on EKS Cluster'){ - when { expression { params.action == 'create' } } + stage("Docker Image Build: ECR"){ + 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 . - """ - } + + 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.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + // } + // } + // } + 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}") + } + } + } } -} \ No newline at end of file +} diff --git a/deployment.yaml b/deployment.yaml deleted file mode 100644 index 22ff7e8a..00000000 --- a/deployment.yaml +++ /dev/null @@ -1,33 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: myjavaapp-deployment -spec: - replicas: 3 - selector: - matchLabels: - app: myjavaapp - template: - metadata: - labels: - app: myjavaapp - spec: - containers: - - name: myjavaapp - image: 496157679619.dkr.ecr.us-east-1.amazonaws.com/vikashashoke:latest - ports: - - containerPort: 8080 - ---- -apiVersion: v1 -kind: Service -metadata: - name: myjavaapp-service -spec: - selector: - app: myjavaapp - ports: - - name: http - port: 80 - targetPort: 8080 - type: LoadBalancer 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 = < org.projectlombok lombok - 1.18.4 + 1.18.26 provided diff --git a/target/classes/application.yml b/target/classes/application.yml new file mode 100644 index 00000000..c8c07287 --- /dev/null +++ b/target/classes/application.yml @@ -0,0 +1,12 @@ +management: + endpoint: + web: + exposure: + inculde: info, refresh, keepalive, health +logging: + level: + org.springframework.cloud.kubernetes: DEBUG + +spring: + application: + name: minikube-sample diff --git a/target/classes/bootstrap.yml b/target/classes/bootstrap.yml new file mode 100644 index 00000000..2b2c9a25 --- /dev/null +++ b/target/classes/bootstrap.yml @@ -0,0 +1,17 @@ +spring: + cloud: + kubernetes: + config: + enabled: true + sources: + - namespace: default + name: minikube-sample + reload: + enabled: true + mode: event + strategy: refresh + +management: + endpoint: + restart: + enabled: true \ No newline at end of file diff --git a/target/classes/com/minikube/sample/MinikubeSampleApplication.class b/target/classes/com/minikube/sample/MinikubeSampleApplication.class new file mode 100644 index 00000000..b8325642 Binary files /dev/null and b/target/classes/com/minikube/sample/MinikubeSampleApplication.class differ diff --git a/target/classes/com/minikube/sample/properties/PropertiesConfig.class b/target/classes/com/minikube/sample/properties/PropertiesConfig.class new file mode 100644 index 00000000..f6db8b64 Binary files /dev/null and b/target/classes/com/minikube/sample/properties/PropertiesConfig.class differ diff --git a/target/classes/com/minikube/sample/rest/controller/HomeResource$ResponseData.class b/target/classes/com/minikube/sample/rest/controller/HomeResource$ResponseData.class new file mode 100644 index 00000000..0bf4ae5f Binary files /dev/null and b/target/classes/com/minikube/sample/rest/controller/HomeResource$ResponseData.class differ diff --git a/target/classes/com/minikube/sample/rest/controller/HomeResource.class b/target/classes/com/minikube/sample/rest/controller/HomeResource.class new file mode 100644 index 00000000..fd46c87a Binary files /dev/null and b/target/classes/com/minikube/sample/rest/controller/HomeResource.class differ diff --git a/target/kubernetes-configmap-reload-0.0.1-SNAPSHOT.jar b/target/kubernetes-configmap-reload-0.0.1-SNAPSHOT.jar new file mode 100644 index 00000000..15780a53 Binary files /dev/null and b/target/kubernetes-configmap-reload-0.0.1-SNAPSHOT.jar differ diff --git a/target/kubernetes-configmap-reload-0.0.1-SNAPSHOT.jar.original b/target/kubernetes-configmap-reload-0.0.1-SNAPSHOT.jar.original new file mode 100644 index 00000000..b79d8399 Binary files /dev/null and b/target/kubernetes-configmap-reload-0.0.1-SNAPSHOT.jar.original differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 00000000..a1f993ff --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +groupId=com.minikube.sample +artifactId=kubernetes-configmap-reload +version=0.0.1-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 00000000..76068c83 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,4 @@ +com\minikube\sample\rest\controller\HomeResource$ResponseData.class +com\minikube\sample\MinikubeSampleApplication.class +com\minikube\sample\properties\PropertiesConfig.class +com\minikube\sample\rest\controller\HomeResource.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 00000000..178dfc1d --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +C:\Users\User\workspace\java_ap\src\main\java\com\minikube\sample\properties\PropertiesConfig.java +C:\Users\User\workspace\java_ap\src\main\java\com\minikube\sample\MinikubeSampleApplication.java +C:\Users\User\workspace\java_ap\src\main\java\com\minikube\sample\rest\controller\HomeResource.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 00000000..833d734c --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com\minikube\sample\MinikubeSampleApplicationTests.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 00000000..f3feff9a --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +C:\Users\User\workspace\java_ap\src\test\java\com\minikube\sample\MinikubeSampleApplicationTests.java diff --git a/target/surefire-reports/TEST-com.minikube.sample.MinikubeSampleApplicationTests.xml b/target/surefire-reports/TEST-com.minikube.sample.MinikubeSampleApplicationTests.xml new file mode 100644 index 00000000..25408997 --- /dev/null +++ b/target/surefire-reports/TEST-com.minikube.sample.MinikubeSampleApplicationTests.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/com.minikube.sample.MinikubeSampleApplicationTests.txt b/target/surefire-reports/com.minikube.sample.MinikubeSampleApplicationTests.txt new file mode 100644 index 00000000..fe2a9ef7 --- /dev/null +++ b/target/surefire-reports/com.minikube.sample.MinikubeSampleApplicationTests.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.minikube.sample.MinikubeSampleApplicationTests +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 24.911 s - in com.minikube.sample.MinikubeSampleApplicationTests diff --git a/target/test-classes/com/minikube/sample/MinikubeSampleApplicationTests.class b/target/test-classes/com/minikube/sample/MinikubeSampleApplicationTests.class new file mode 100644 index 00000000..5892ba7d Binary files /dev/null and b/target/test-classes/com/minikube/sample/MinikubeSampleApplicationTests.class differ