diff --git a/Dockerfile b/Dockerfile index 30cae8b..4d4b80b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ FROM tomcat:8.0.20-jre8 ### Good stuff -COPY target/*.war /usr/local/tomcat/webapps/wfapp.war +COPY target/*.war /usr/local/tomcat/webapps/tesla.war +#if prefix isn't taken out use target/*.war diff --git a/JenkinsFile3 b/JenkinsFile3 new file mode 100644 index 0000000..7a36d6f --- /dev/null +++ b/JenkinsFile3 @@ -0,0 +1,53 @@ +pipeline{ + agent{ + label 'Ansible' + } + tools{ + maven 'Maven' + } + + stages{ + + stage ('Clone Git Repo'){ + steps{ + sh "echo 'Cloning Git Repo'" + git 'https://github.com/Ohubabs/tesla-app.git' + } + } + + stage ('Build Webapp'){ + steps{ + sh "echo 'Clean Source Code and Build Webapp'" + sh "mvn clean package" + } + } + + stage ('Transfer to Docker and Build Image'){ + steps{ + sh "echo 'Transfer to Docker and Build Image'" + sh "ansible-playbook princebabs-build.yml" + } + } + + stage ('login to DockerHub and Push Image'){ + steps{ + sh "echo 'login to DockerHub and Push Image'" + sh "ansible-playbook princebabs-push.yml" + } + } + + stage ('Copy Deployment file to EKS server'){ + steps{ + sh "echo 'Deploy to Cluster'" + sh "ansible-playbook princebabs-copy.yml" + } + } + + stage ('Deploy App'){ + steps{ + sh "echo 'Deploy to Cluster'" + sh 'ansible eks -a "kubectl apply -f princebabs.yml"' + } + } + } +} diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..67654cf --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,74 @@ +#For Master-Slave Architecture, you need SSH Agent and SSH Publisher Plugins. Then configure their ssh server settings in Configure Systems. + +#To configure Ansible and Docker Nodes, you need to go to Manage Clouds and Nodes to input the details of your servers. + + +#Use SSH Publisher syntax to transfer war files and Dockerfile to your Docker server. Then in exec command, input " docker build -t " and docker push +but used the "variable"/withcredentials beforehand to setup docker credentials and then refer to the variable when inputting the exec command for better security. +Fill out ssh publisher with the following credentials: + +SSH Server +Name: Docker +Advanced > Transfers > Transfer Set + +Source files= target/*war +Remove prefix +#Do not remove prefix unless you change Dockerfile to just copy /*war instead of target/*war +Remote directory: //home//ubuntu// # "//" is crucial or the file won't be copied into the right location/be found when executing your commands. +Exec command +? +All of the transfer fields (except for Exec timeout) support substitution of Jenkins environment variables +Advanced + +Transfer Set +Source files: Dockerfile +Remove prefix +? +Remote directory: //home//ubuntu +Exec command: docker build -t princebabs/tesla . + + +pipeline{ + agent{ + label 'Ansible' + } + tools{ + maven 'maven3.9.0' + } + + stages{ + + stage ('Clone Git Repo'){ + steps{ + sh "echo 'Cloning Git Repo'" + git 'https://github.com/Ohubabs/tesla-app.git' + } + } + + stage ('Build Webapp'){ + steps{ + sh "echo 'Clean Source Code and Build Webapp'" + sh "mvn clean package" + } + } + + stage ('Quality Testing'){ + steps{ + sh "echo 'Clean Source Code and Build Webapp'" + sh "mvn sonar:sonar" + } + } + + stage ('Transfer to Docker and Build Image'){ + steps{ + sshPublisher(publishers: [sshPublisherDesc(configName: 'Docker', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '//home//ubuntu//', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'target/*war'), sshTransfer(cleanRemote: false, excludes: '', execCommand: 'docker build -t princebabs/tesla .', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '//home//ubuntu', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'Dockerfile')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)]) + } + } + + stage ('Deploy wfapp'){ + steps{ + sh "ansible-playbook princebabs-deploy.yml -i tesla-host" + } + } + } +} diff --git a/Jenkinsfile2 b/Jenkinsfile2 new file mode 100644 index 0000000..f995607 --- /dev/null +++ b/Jenkinsfile2 @@ -0,0 +1,82 @@ +pipeline{ + agent{ + label 'Ansible' + } + tools{ + maven 'maven3.9.0' + } + + stages{ + + stage ('Clone Git Repo'){ + steps{ + sh "echo 'Cloning Git Repo'" + git 'https://github.com/Ohubabs/tesla-app.git' + } + } + + stage ('Build Webapp'){ + steps{ + sh "echo 'Clean Source Code and Build Webapp'" + sh "mvn clean package" + } + } + + stage ('Start SonarQube'){ + steps{ + sh "ansible-playbook sonarstart.yml -i tesla-host" + } + } + + stage ('Quality Testing'){ + steps{ + sh "echo 'Clean Source Code and Build Webapp'" + sh "mvn sonar:sonar" + } + } + + stage ('Backup Artifact'){ + steps{ + sh "echo 'Backup to Nexus'" + sh "mvn deploy" + } + } + + stage ('Transfer to Docker and Build Image'){ + steps{ + sh "echo 'Transfer to Docker and Build Image" + sshPublisher(publishers: [sshPublisherDesc(configName: 'Ansible', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '//home//ansible//auto', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'target/*war'), sshTransfer(cleanRemote: false, excludes: '', execCommand: 'ansible-playbook princebabs-build.yml -i tesla-host', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '//home//ansible//auto', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'Dockerfile')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)]) + } + } + + stage ('Log into DockerHub and Push Image'){ + steps{ + sh "echo 'Log into DockerHub and Push Image'" + withCredentials([usernamePassword(credentialsId: 'DockerHub-Credentials', passwordVariable: 'DOCKERHUB_PASSWORD', usernameVariable: 'DOCKERHUB_USERNAME')]) { + sshPublisher(publishers: [sshPublisherDesc(configName: 'Docker', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''docker login -u DOCKERHUB_USERNAME -p DOCKERHUB_PASSWORD +docker push princebabs/tesla''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)]) + } + } + } + + + stage ('Deploy App to EKS Cluster'){ + steps{ + sh "echo 'Deploy App to EKS Cluster'" + sh "ansible-playbook princebabs-deploy.yml -i tesla-host" + } + } + } +} + +#Side note + $node(POD_LABEL) { + # stage('Get a Maven project') { + # git 'https://github.com/jenkinsci/kubernetes-plugin.git' + # container('maven') { + # stage('Build a Maven project') { + # sh 'mvn -B -ntp clean install' + # } + # } + #} + #ref: https://plugins.jenkins.io/kubernetes/ diff --git a/Jenkinsfile_konoha b/Jenkinsfile_konoha new file mode 100644 index 0000000..5815679 --- /dev/null +++ b/Jenkinsfile_konoha @@ -0,0 +1,37 @@ +pipeline{ + agent { + label 'docker' + } + tools{ + maven 'maven' + } + stages{ + //stage('Clone Code'){ + // steps{ + // sh "echo cloning code" + // sh "echo clone code complete" + // git 'https://github.com/Ohubabs/tesla-app.git' + // } + //} + stage ('Build Webapp'){ + steps{ + sh "echo 'Clean Source Code and Build Webapp'" + sh "mvn clean package" + sh "mvn sonar:sonar" + } + } + stage('Build Image'){ + steps{ + sh "echo build image" + sh 'docker build -t princebabs/konoha:v1 .' + } + } + stage('Push to DockerHub'){ + steps{ + sh "echo 'Push Image'" + sh 'docker push princebabs/konoha:v1' + + } + } + } +} diff --git a/Jenkinsfile_konoha_1 b/Jenkinsfile_konoha_1 new file mode 100644 index 0000000..c980b62 --- /dev/null +++ b/Jenkinsfile_konoha_1 @@ -0,0 +1,28 @@ +pipeline{ + agent { + label 'terra' + } + stages{ + //stage('Clone Code'){ + // steps{ + // sh "echo cloning code" + // sh "echo clone code complete" + // git 'https://github.com/Ohubabs/tesla-app.git' + // } + //} + stage('Initialize Terraform'){ + steps{ + sh "echo 'Deploy Tesla To Cluster'" + sh "terraform init" + } + } + stage('Deploy Tesla To EKS'){ + steps{ + sh "echo 'Deploy Tesla To Cluster'" + sh "terraform validate" + sh "terraform plan" + sh "terraform apply --auto-approve" //Swap "apply" with "destroy" when deleting resources + } + } + } +} diff --git a/Jenkinsfile_konoha_2 b/Jenkinsfile_konoha_2 new file mode 100644 index 0000000..152b504 --- /dev/null +++ b/Jenkinsfile_konoha_2 @@ -0,0 +1,14 @@ +pipeline{ + agent { + label 'terra' + } + stages{ + stage('Destroy Konoha Web Server Today'){ + steps{ + sh "echo 'Deploy Tesla To Cluster'" + sh "terraform init" + sh "terraform destroy --auto-approve" + } + } + } +} diff --git a/deploy-app.yml b/deploy-app.yml index 5303fa0..5b11ee3 100644 --- a/deploy-app.yml +++ b/deploy-app.yml @@ -1,7 +1,7 @@ -- hosts: k8s +- hosts: eks tasks: - name: copy deployment manifest files - copy: src=app.yml dest=/home/ubuntu/myapp.yml + copy: src=app.yml dest=/home/eks/myapp.yml - name: deploy the web application - shell: kubectl apply -f /home/ubuntu/myapp.yml + shell: kubectl apply -f /home/eks/myapp.yml diff --git a/konoha-app.tf b/konoha-app.tf new file mode 100644 index 0000000..6fec470 --- /dev/null +++ b/konoha-app.tf @@ -0,0 +1,52 @@ +resource "kubernetes_deployment_v1" "konoha-deploy" { + metadata { + name = "konoha" + } + + spec { + replicas = 2 + strategy { + type = "RollingUpdate" + rolling_update { + max_surge = 1 + max_unavailable = 1 + } + } + min_ready_seconds = 30 + selector { + match_labels = { + app = "konoha" + } + } + + template { + metadata { + labels = { + app = "konoha" + } + } + + spec { + container { + image = "princebabs/konoha:v1" + name = "konoha-pod" + + port { + container_port = 80 + } + + resources { + limits = { + cpu = ".5" + memory = "512Mi" + } + requests = { + cpu = "250m" + memory = "50Mi" + } + } + } + } + } + } +} diff --git a/konoha_ingress.tf b/konoha_ingress.tf new file mode 100644 index 0000000..e742f29 --- /dev/null +++ b/konoha_ingress.tf @@ -0,0 +1,79 @@ +##NGINX + +resource "kubernetes_ingress_v1" "konoha-ingress" { + wait_for_load_balancer = true + metadata { + name = "konoha" + namespace = "default" + annotations = { + "cert-manager.io/cluster-issuer" = "konoha-issuer" + } + } + spec { + ingress_class_name = "nginx" + tls { + secret_name = "konoha-secret" + hosts = ["konoha.devopsnetwork.net"] + } + rule { + host = "konoha.devopsnetwork.net" + http { + path { + path = "/" + backend { + service { + name = "konoha-svc" + port { + number = 80 + } + } + } + } + } + } + } +} + +##ALB + +#resource "kubernetes_ingress_v1" "konoha" { +# wait_for_load_balancer = true +# metadata { +# name = "konoha" +# namespace = "default" +# annotations = { +# "alb.ingress.kubernetes.io/load-balancer-name" = "konoha" +# "alb.ingress.kubernetes.io/scheme" = "internet-facing" +# "alb.ingress.kubernetes.io/target-type" = "ip" +# "alb.ingress.kubernetes.io/certificate-arn" = "arn:aws:acm:us-west-2:083772204804:certificate/069afb91-11fb-41e9-9044-7b0daf2cb6a1" +# } +# } +# spec { +# ingress_class_name = "alb" +# default_backend { +# service { +# name = "konoha-svc" +# port { +# number = 80 +# } +# } +# } +# rule { +# host = "konoha.devopsnetwork.net" +# http { +# path { +# path = "/" +# path_type = "Exact" +# backend { +# service { +# name = "konoha-svc" +# port { +# number = 80 +# } +# } +# } +# } +# } +# } +# } +#} diff --git a/konoha_svc.tf b/konoha_svc.tf new file mode 100644 index 0000000..c168fb3 --- /dev/null +++ b/konoha_svc.tf @@ -0,0 +1,16 @@ +resource "kubernetes_service_v1" "konoha-svc" { + metadata { + name = "konoha-svc" + } + spec { + selector = { + app = "konoha" + } + port { + port = 80 + target_port = 80 + } + + type = "NodePort" + } +} diff --git a/pom.xml b/pom.xml index a163c4f..ebbe89d 100644 --- a/pom.xml +++ b/pom.xml @@ -20,9 +20,9 @@ 5.1.2.RELEASE 4.11 1.2.17 - http://54.176.76.14:9000/ - admin - admin + https://apptest.devopsnetwork.net/ + admin + Arsenal UTF-8 UTF-8 @@ -95,14 +95,16 @@ nexus - Landmark Technologies Releases Nexus Repository - http://52.53.227.31:8191/landmark/repository/tesla-fe-releases/ + tesla + http://nexus.devopsnetwork.net/repository/tesla-release/ + nexus - Landmark Technologies Snapshot Nexus Repository - http://52.53.227.31:8191/landmark/repository/tesla-fe-snapshots/ + tesla-Snapshot + http://nexus.devopsnetwork.net/repository/tesla-snapshot/ + diff --git a/princebabs-build.yml b/princebabs-build.yml new file mode 100644 index 0000000..919f8ab --- /dev/null +++ b/princebabs-build.yml @@ -0,0 +1,13 @@ +- hosts: docker + tasks: + - name: Copy webapp to Docker server + copy: src=target/ dest=/home/docker/ #assuming Ansible user has been added on server and configured to be the root in the Ansible host file #changed from ansible on 03/21/23 + - name: Copy Dockerfile to Docker Server + copy: src=Dockerfile dest=/home/docker/ #changed from ansible on 03/21/23 + - name: Build Image + command: "docker build -t princebabs/tesla ." + + #Updated on 06/07/23 + + + diff --git a/princebabs-copy.yml b/princebabs-copy.yml new file mode 100644 index 0000000..8e57a50 --- /dev/null +++ b/princebabs-copy.yml @@ -0,0 +1,7 @@ +- hosts: eks + become: true + tasks: + - name: copy deployment manifest files + copy: src=princebabs.yml dest=/home/ubuntu/princebabs.yml + + diff --git a/princebabs-deploy.yml b/princebabs-deploy.yml new file mode 100644 index 0000000..3d2fce0 --- /dev/null +++ b/princebabs-deploy.yml @@ -0,0 +1,7 @@ +- hosts: eks + become: true + tasks: + - name: copy deployment manifest files + copy: src=princebabs.yml dest=/home/ubuntu/princebabs.yml + - name: deploy the web application + shell: kubectl apply -f princebabs.yml diff --git a/princebabs-destroy.yml b/princebabs-destroy.yml new file mode 100644 index 0000000..6daed2b --- /dev/null +++ b/princebabs-destroy.yml @@ -0,0 +1,5 @@ +--- +- hosts: eks + tasks: + - name: Delete all k8s objects + command: "kubectl delete -f /home/eks/princebabs.yml" diff --git a/princebabs-push.yml b/princebabs-push.yml new file mode 100644 index 0000000..c9831ef --- /dev/null +++ b/princebabs-push.yml @@ -0,0 +1,9 @@ +--- +- hosts: docker + become: true + tasks: + - name: Login in to Docker and Push Image + command: docker login -u princebabs -p + + - name: Push Image to DockerHub + command: docker push princebabs/tesla diff --git a/princebabs.yml b/princebabs.yml new file mode 100644 index 0000000..74e9845 --- /dev/null +++ b/princebabs.yml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: princebabs +spec: + selector: + matchLabels: + app: princebabs-app + replicas: 2 + template: + metadata: + name: princebabs-apppod + labels: + app: princebabs-app + spec: + containers: + - name: princebabs-container + image: princebabs/tesla + ports: + - containerPort: 8080 + +--- +apiVersion: v1 +kind: Service +metadata: + name: princebabs-app-svc +spec: + selector: + app: princebabs-app + type: LoadBalancer + ports: + - targetPort: 8080 + port: 80 diff --git a/provider.tf b/provider.tf new file mode 100644 index 0000000..0bf3872 --- /dev/null +++ b/provider.tf @@ -0,0 +1,22 @@ +terraform { + required_version = "~> 1.0" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.0" + } + + kubernetes = { + source = "hashicorp/kubernetes" + version = ">= 2.10" + } + } +} + +provider "aws" { + region = "us-west-2" +} + +provider "kubernetes" { + config_path = "/home/terra/.kube/config" + } diff --git a/sonarstart.yml b/sonarstart.yml new file mode 100644 index 0000000..88a3165 --- /dev/null +++ b/sonarstart.yml @@ -0,0 +1,7 @@ +--- +- hosts: sonar + tasks: + - name: Start sonar service + shell: /home/sonar/opt/sonarqube-9.1.0.47736/bin/linux-x86-64/sonar.sh start + - name: Display sonar service status + shell: /home/sonar/opt/sonarqube-9.1.0.47736/bin/linux-x86-64/sonar.sh status diff --git a/src/main/webapp/jsps/home.jsp b/src/main/webapp/jsps/home.jsp index cfc0fc6..bc1ea4f 100644 --- a/src/main/webapp/jsps/home.jsp +++ b/src/main/webapp/jsps/home.jsp @@ -9,11 +9,10 @@ -

Landmark Technology - Leaders in Software Delivery and DevOps Automation

-

Welcome to Landmark Technology.......We have a demo on DevOps E Degree with Linux and AWS on Sunday Oct 9, 2022 at 3PM EST for our new batch. - Landmark Technology Tesla web application project2. +

KONOHAGURE

+

Welcome to Konoha...The Village Hidden In The Leaves.

-

DevOps is good. JESUS IS LORD. I AM BLESSED. Production

+

Hope You're Excited To Start Your Journey To Become A Hidden Leaf Ninja. Production


diff --git a/tesla-host b/tesla-host new file mode 100644 index 0000000..13bed92 --- /dev/null +++ b/tesla-host @@ -0,0 +1,14 @@ +[eks] +3.85.122.240 ansible_user=eks + +[docker] +52.10.255.64 ansible_user=docker + +[sonar] +34.207.159.39 ansible_user=sonar + +[nexus] +3.83.190.132 ansible_user=nexus + +[jenkins] +3.89.133.171 ansible_user=ec2-user ansible_ssh_private_key_file=Class29key2.pem