diff --git a/Jenkinsfile b/Jenkinsfile index 7fecd3c2b..26708ec4c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,122 +1,677 @@ +def COLOR_MAP = [ + 'SUCCESS': 'good', + 'FAILURE': 'danger', +] + pipeline { - - agent any -/* - tools { - maven "maven3" - + agent any + tools { + maven "MAVEN3" + jdk "OracleJDK17" } -*/ + environment { - NEXUS_VERSION = "nexus3" - NEXUS_PROTOCOL = "http" - NEXUS_URL = "172.31.40.209:8081" - NEXUS_REPOSITORY = "vprofile-release" - NEXUS_REPO_ID = "vprofile-release" - NEXUS_CREDENTIAL_ID = "nexuslogin" - ARTVERSION = "${env.BUILD_ID}" - } - - stages{ - - stage('BUILD'){ + SNAP_REPO = 'vprofile-snapshot' + NEXUS_USER = 'admin' + NEXUS_PASS = 'admin123' + RELEASE_REPO = 'vprofile-release' + CENTRAL_REPO = 'vpro-maven-central' + NEXUS_IP = '172.31.16.20' + NEXUS_PORT = '8081' + NEXUS_GRP_REPO = 'vpro-maven-group' + NEXUS_LOGIN = 'Nexuslogin' + SONARSERVER = 'sonarserver' + SONARSCANNER = 'sonarscanner' + } + + stages { + stage('Build'){ steps { - sh 'mvn clean install -DskipTests' + sh 'mvn -s settings.xml -DskipTests install' } post { success { - echo 'Now Archiving...' - archiveArtifacts artifacts: '**/target/*.war' + echo 'Archiving' + archiveArtifacts artifacts: '**/*.war' } } + } - stage('UNIT TEST'){ + stage('Test') { steps { - sh 'mvn test' + sh 'mvn -s settings.xml test' } } - stage('INTEGRATION TEST'){ + stage('Checkstyle Analysis') { steps { - sh 'mvn verify -DskipUnitTests' + sh 'mvn -s settings.xml checkstyle:checkstyle' } } - - stage ('CODE ANALYSIS WITH CHECKSTYLE'){ - steps { - sh 'mvn checkstyle:checkstyle' + + stage ('Sonar Analysis') { + environment { + scannerHome = tool "${SONARSCANNER}" } - post { - success { - echo 'Generated Analysis Result' + steps { + withSonarQubeEnv("${SONARSERVER}") { + sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile \ + -Dsonar.projectName=vprofile \ + -Dsonar.projectVersion=1.0 \ + -Dsonar.sources=src/ \ + -Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ \ + -Dsonar.junit.reportsPath=target/surefire-reports/ \ + -Dsonar.jacoco.reportsPath=target/jacoco.exec \ + -Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml''' } } } - stage('CODE ANALYSIS with SONARQUBE') { - - environment { - scannerHome = tool 'sonarscanner4' - } + stage ("Quality Gate") { + steps { + timeout(time:1, unit: 'HOURS') { + waitForQualityGate abortPipeline: true + } + } + } - steps { - withSonarQubeEnv('sonar-pro') { - sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile \ - -Dsonar.projectName=vprofile-repo \ - -Dsonar.projectVersion=1.0 \ - -Dsonar.sources=src/ \ - -Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ \ - -Dsonar.junit.reportsPath=target/surefire-reports/ \ - -Dsonar.jacoco.reportsPath=target/jacoco.exec \ - -Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml''' + stage ("Upload Artifact") { + steps { + nexusArtifactUploader( + nexusVersion: 'nexus3', + protocol: 'http', + nexusUrl: "${NEXUS_IP}:${NEXUS_PORT}", + groupId: 'QA', + version: "${env.BUILD_ID}-${env.BUILD_TIMESTAMP}", + repository: "${RELEASE_REPO}", + credentialsId: "${NEXUS_LOGIN}", + artifacts: [ + [artifactId: 'vproapp', + classifier: '', + file: 'target/vprofile-v2.war', + type: 'war'] + ] + ) } + } + } + post { + success{ + echo 'Slack Notifications' + slackSend channel: '#dasmanth', + color: COLOR_MAP[currentBuild.currentResult], + message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} \n More info at: ${env.BUILD_URL}" + } + } +} + + + + + + + + + + + - timeout(time: 10, unit: 'MINUTES') { - waitForQualityGate abortPipeline: true + + + + + + + + + + + + pipeline { + agentany { + environment { + + } + parameters { + + } + tools { + maven3 "mvn3" + jdk11 "jdk11" + } + } + stages { + stage ('git checkout') { + steps { + sh "gitpull " + } + } + stage ('code validate') { + steps { + sh "mvn validate" } - } } + } + } + + + + FROM nginx:latest + COPY /etc/app + RUN apt get update + RUN apt get install -y + EXPOSE 80:80 + + + + + + + apiVersion: v1 + kind: Deployment + metadata: + name: dev + labels: + dev: '01' + company: talent + spec: + conta + + + + apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 + + + + + + + + + + + + + + +pipeline { + agent any + tools { + jdk "jdk11" + maven "mvn3" + } + environment { + SONARSERVER = 'admim' + NEXUS_ID = 'admin' + + + } + parameters { + + } + stages { + stage ('code pull') { + sh 'gitclone' + } + stage ('code validate') { + sh 'mvn validate' + } + stage ('code compile') { + sh 'mvn compile' + } + stage ('code test') { + sh 'mvn test' + } + stage ('build') { + sh 'mvn clean package' + } + } +} + + + + + + + + + + + + +FROM nginx:latest +LABEL dev:1 +RUN yum update -y +RUN yum install nginx -y +EXPOSE 80 +CMD ["nginx","-g", "daemon off:"] + +FROM openjdk:8-jdk-alpine as builder +RUN mkdir -p /app/source +COPY . /app/source +WORKDIR /app/source +RUN ./mvnw clean package + + +FROM builder +COPY --from=builder /app/source/target/*.jar /app/app.jar +EXPOSE 8080 +ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]\ + + + + +FROM ubuntu:latest +RUN apt-get update +RUN apt-get install nginx:latest +COPY /usr/share/nginx +CMD ["nginx","-g","daemon off:"] + + + + + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 5 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:latest + ports: + - containerPort: 80 + + + + + + + + + + + - stage("Publish to Nexus Repository Manager") { + +DevOps-Shack-Project --- k8s kubeadm join command + + + + join 172.31.40.50kubeadm:6443 --token 8jaarh.0vd93xk6bq5vxqec \ + --discovery-token-ca-cert-hash sha256:95bdae5d5fc65aedf6b6cd5b552aab0ea04b52cd8db7a4530eb9da665093182d + + + sonarqube token (squ_aa4ba1a09a4036d33963a4276a2eaf7fedd7dd5e) + jenkins managed files --- (54ba0e0d-017f-4e1b-991b-76a5fcb88cd8) + + pipeline { + agent any + tools { + jdk 'jdk17' + maven 'maven3' + } + environment { + SCANNER_HOME= tool 'sonar-scanner' + } + + stages { + stage('Git Checkout') { + steps { + git branch: 'main', url: 'https://github.com/Dasmanth/Boardgame.git' + } + } + stage('Compile') { + steps { + sh "mvn compile" + + } + } + stage('Test') { + steps { + sh "mvn test" + + } + } + stage('File System Scan') { + steps { + sh "trivy fs --format table -o trivy-fs-report.html ." + + } + } + stage('SonarQube Analsyis') { + steps { + withSonarQubeEnv('sonar') { + sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=BoardGame -Dsonar.projectKey=BoardGame \ + -Dsonar.java.binaries=. ''' + } + } + } + stage('Quality Gate') { steps { script { - pom = readMavenPom file: "pom.xml"; - filesByGlob = findFiles(glob: "target/*.${pom.packaging}"); - echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}" - artifactPath = filesByGlob[0].path; - artifactExists = fileExists artifactPath; - if(artifactExists) { - echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version} ARTVERSION"; - nexusArtifactUploader( - nexusVersion: NEXUS_VERSION, - protocol: NEXUS_PROTOCOL, - nexusUrl: NEXUS_URL, - groupId: pom.groupId, - version: ARTVERSION, - repository: NEXUS_REPOSITORY, - credentialsId: NEXUS_CREDENTIAL_ID, - artifacts: [ - [artifactId: pom.artifactId, - classifier: '', - file: artifactPath, - type: pom.packaging], - [artifactId: pom.artifactId, - classifier: '', - file: "pom.xml", - type: "pom"] - ] - ); - } - else { - error "*** File: ${artifactPath}, could not be found"; + waitForQualityGate abortPipeline: false, credentialsId: 'sonar-token' + } + } + } + stage ('Build') { + steps { + sh "mvn package" + } + } + stage('Publish To Nexus') { + steps { + withMaven(globalMavenSettingsConfig: 'global-settings', jdk: 'jdk17', maven: 'maven3', mavenSettingsConfig: '', traceability: true) { + sh "mvn deploy" + } + + } + } + stage('Build & Tag Docker Image') { + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker build -t dasmanth/jenkins:latest ." + } + } + } + } + stage('Docker Image Scan') { + steps { + sh "trivy image --format table -o trivy-image-report.html dasmanth/jenkins:latest " + } + } + stage('Push Docker Image') { + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker push dasmanth/jenkins:latest" } + } + } + } + + + } + +} + + + + + + + + + + +##Nginx docker file +FROM ubuntu:18.04 +RUN apt get update +RUN apt get install nginx -y +COPY nginx.conf /etc/nginx +COPY server.conf /etc/nginx/conf.d +EXPOSE 80:80 +CMD ["nginx","-g","daemon off;"] + + + + + +##jenkins file + + +pipeline { + agent any + tools { + maven "maven3" + jdk "jdk17" + } + environment { + + } + stages { + stage ('Git check out') { + steps { + sh git pull + } + } + } +} + + +##k8s pod yaml file + +apiVersion: v1 apiVersion: +kind: Pod +metadata: + name:nginx +spec: + containers: + - name: nginx + image: nginx:latest + ports: + - containerPort: 80 + + + + pipeline { + agent any + tools { + jdk 'jdk11' + maven 'maven3' + } + environment { + SONAR_HOME= tool + } + stages { + stage ('Git Checkout') { + steps { + gitbranch: '' + } + } + stage ('Code compile') { + steps { + sh "mvn compile" + } + } + stage ('Code validate') { + steps { + sh "mvn validate" + } + } + stage ('Code test') { + steps { + sh "mvn test" + } + } + stage ('Sonar analysis') { + steps { + + } + } + stage ('Quality gate') { + steps { + + } + } + stage ('Build') { + steps { + sh "mvn clean package" + } + } + stage ('Pull artifact to nexus'){ + steps { + + } + } + stage ('Docker image build & Tag') { + steps { + } } } + } + + + + + FROM ubuntu:latest + RUN apt get update -y + RUN apt get install nginx -y + COPY nginx.conf /etc/nginx + COPY server.conf /etc/nginx/nginx.conf + ADD + EXPOSE 80:80 + USER + CMD ["nginx","-g","daemon 0ff;"] + + + apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 + apiVersion: apps/v1 + kind: Deployment + metadata: + name: nginx-deployment + labels: + app: nginx + spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:latest + ports: + - containerPort: 80 + + +apviVesrion: apps/v1 +kind: Deployment +metadata: + name: nginx + labels: + app: nginx +spec: + replicas: 5 + selector: + matchLabels: + app: nginx + template: + meatadata: + labels: + app: Nginx + spec: + containers: + - name: nginx + image: nginx:latest + ports: + - containerPort: 80 + + FROM ubuntu:alpine + RUN apt get update -y + RUN apt get install nginx -y + COPY nginx.conf /etc/ + COPY server.cong / + EXPOSE 80:80 + CMD ["nginx","-g","daemon off;"] + + pipeline { + aget any + tools { + jdk "jdk11" + maven "maven3" + } + environment { + + } + stages { + stage ('Gir Check out') { + steps { + + } + } } + } -} +--- +- name: update web servers + hosts: webservers + remote_user: root + + tasks: + - name: ensure apache is at the latest version + ansible.builtin.yum: + name: httpd + state: latest + + - name: update database + ansible.builtin.template: + src: /srv/ + dest: /etc/ + + + +terraform { + +} \ No newline at end of file diff --git a/gitcommands.txt b/gitcommands.txt new file mode 100644 index 000000000..f2e59f3de --- /dev/null +++ b/gitcommands.txt @@ -0,0 +1,73 @@ +git clone --- This command will clone your remote repo to your local machine. +git checkout -b --- This command is used to create and switch to a new branch. + ##scenario--- When a new feature, bug fix, or infrastructure change is required, creating a new branch to isolate changes. DevOps engineers often use branches for: + + Creating new features + Fixing production issues + Writing or updating Infrastructure-as-Code (IaC) +git pull origin --- This command is used to pull the changes from remote repo to the local machine. + ##scenario --- Before staring any work,pulling the latest changes from the remote repo ensure your local branch is upto date + with the team's latest commits. + +git status --- Checking the status of changes done in the project. + ##scenario--- Regularly checking the status while working to see which files are modified, added, or deleted before committing changes. + It helps in tracking what needs to be staged or excluded. + +git add (or) git add . --- Staging the changes from working to stage. + ##scenario --- After making changes to configuration files (e.g., Dockerfiles, Kubernetes manifests, Terraform scripts), + DevOps engineers stage those changes before committing them to the branch + . +git commit -m --- Commiting the changes + ##scenario ---Commit changes after successful code or configuration updates. It’s a good practice to have meaningful commit messages + that describe what was changed (e.g., "Updated Jenkinsfile to support new build process"). + +git push origin --- Pushing the changes from local to remote repo. + ##scenario ---After committing changes locally, pushing them to the remote repository makes those changes available to others, + including for CI/CD pipelines to pick them up. + +git merge --- Merging the branches + ##scenario-- After completing the development or changes in a feature branch, merging those changes into the main branch or a staging branch. + Example Use Case: Merging changes from the feature/new-ci-pipeline branch into the main branch. + +git merge -- Resolving merge conflicts + ##scenario-- When there are conflicts between branches, Git pauses the merge, and + DevOps engineers must manually resolve conflicts, edit conflicting files, stage, and commit the resolutions. + +git rebase -- Rebasing the branch + ##scenario--- To ensure that the feature branch is up to date with the latest changes from the main branch without creating a merge commit. + This helps maintain a cleaner history, especially in production or release branches. + +git log (or) git log --online --- Viewing commit history + ##scenario-- Reviewing commit history to understand changes made by other team members or to investigate changes when something breaks in production. + +git diff -- Checking differneces between two commits + ##scenario-- To view changes that have been made but not yet committed. This helps in code reviews and debugging configuration files or code before committing. + +git tag (or) git push origin -- Tagging releases + ##scenario-- When releasing a new version of software or infrastructure, tagging the commit with a version (e.g., v1.0.0). \ + Tags help mark points in the Git history for releases, making rollback easier in case of failure. + +git reset -- Unstage changes + ##scenario-- If an incorrect change was made or committed, + DevOps engineers may need to reset the staging area or revert a commit to undo changes. This helps to maintain stability in production environments. + +git revert -- Revert a commit + ##scenario-- If an incorrect change was made or committed, + DevOps engineers may need to reset the staging area or revert a commit to undo changes. This helps to maintain stability in production environments. + +git cherry-pick -- Cherry-picking specific commits + ##scenario-- When you want to pick specific commits from one branch and apply them to another without merging the whole branch. This is useful when deploying hotfixes from a development branch to production. + +git remote -v -- Checking remote URLs + ##scenario-- To verify the remote repository’s URL, especially when managing multiple remotes like production, staging, or dev repositories. + +git fetch -- Fetching changes from remote repository + ##scenario-- To retrieve the latest changes from the remote repository without merging them into your working branch. This is useful when you want to inspect changes before applying them. + +git stash apply -- Stashing changes + ##scenario-- When you need to save your uncommitted changes temporarily (e.g., switching to another branch for an urgent task), you can stash those changes and apply them later. + +git rm -- Removing files + ##scenario-- When you need to remove files from the repository and from your working directory. This can be used when cleaning up configuration files or obsolete scripts. + + \ No newline at end of file diff --git a/linuxcommands.txt b/linuxcommands.txt new file mode 100644 index 000000000..d311c7fb2 --- /dev/null +++ b/linuxcommands.txt @@ -0,0 +1,79 @@ +.pem --- Privacy Enhanced Mail +.ppk --- PuTTY Private Key +.txt --- text file +.c --- C language extension +.java --- Java extension +.sh --- shell +.go -- go +.php --- php +.html -- html +.xml -- xm file +.json-- java script object notaion +.zip--- zip file +.jar -- java archive file +cat /etc/os-release --- which os +cat /etc/passwd --- linux users data +cat /etc/groups --- linux user groups data +cat /etc/system-release --- OS info +sudo su --- If you want to became a root user +cd / ---root directory +cd -- change directory + cd +cat -- It will display the file content +ls --- Listing the file and directories + ls -a ---Lists all files in a directory, including hidden files and directories + ls -R --- Lists all files, sorted by file size\ + ls -l-l: Also known as "long listing", this command shows details about the Linux file that are important to the Linux system + ls -t: Sorts files by modification time + ls -r: Sorts files in reverse order + ls -s: Prints the allocated size of each file, in blocks + ls -lrt: It will display the data in the time stamp +pwd --- present working directory +cd - --> Undo you will go back to the previous stage +touch -- It will create new empty file + touch +mkdir -- It will create new empty directory + mkdir +man -- to know the commands list and usage + man -- +useradd -- To create the new user + sudo useradd -- To add new user + sudo userdel -- To delete user + sudo passwd -- To set the password to the user +groupadd -- To add the new group + sudo groupadd + sudo groupdel +sudo usermod-g -- adding a user to the primary group +mv -- To move or rename the file/directory + mv + mv +cp -- Copy + cp test.txt testing +diff -- It will display the difference between the two files +echo - +echo "devops" >> -- append the data from existing data +echo "devops" > -- redirect the data (or) replace the data from existing data +read (r) --- 4 +writr (w) -- 2 +execute (x) -1 +rw- (user) r--(group) r--(others) +420 (6) 400 (4) 400(4) + +rwx r-x r-x +421(6) 401(5) 401 (5) +chmod -- The chmod command (short for "change mode") in Linux is used to change file or directory permissions +chmod -R -- Recursive + chmod -R 777 - Your'e going to give all permissiosn to the all users (user,group & others) +chown --- The chown command in Linux is used to change the ownership of files and directories. + sudo chown : + sudo chown : folders --- Changing folders permissions + sudo chown -R : folders -- Changing folder and its sub-folders permissions +cat cd /etc/cpuinfo +cat cd /etc/meminfo +free -m It will show +free -g +df -kh -- To display server details +history --- It will give history of the commands +cat devops.txt --- To konw the content in the file +ech0 " " > --- It is going to flush (or) empty the file + diff --git a/test.py b/test.py new file mode 100644 index 000000000..8a6d5357a --- /dev/null +++ b/test.py @@ -0,0 +1,4 @@ +str1 = "Hello" +str2 = "World" +result = str1 + " " + str2 +print(result) \ No newline at end of file