diff --git a/.classpath b/.classpath deleted file mode 100644 index 71f5fef..0000000 --- a/.classpath +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 7a3e2fd..0000000 --- a/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -# Local .terraform directories -**/.terraform/* - -# .tfstate files -*.tfstate -*.tfstate.* - -# Crash log files -crash.log - -# Ignore any .tfvars files that are generated automatically for each Terraform run. Most -# .tfvars files are managed as part of configuration and so should be included in -# version control. -# -# example.tfvars - -# Ignore override files as they are usually used to override resources locally and so -# are not checked in -override.tf -override.tf.json -*_override.tf -*_override.tf.json - -# Include override files you do wish to add to version control using negated pattern -# -# !example_override.tf - -# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan -# example: *tfplan* diff --git a/.project b/.project deleted file mode 100644 index 82f6f3c..0000000 --- a/.project +++ /dev/null @@ -1,34 +0,0 @@ - - - my-app - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - - - 1661092280675 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - - diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index f9fe345..0000000 --- a/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs deleted file mode 100644 index d4313d4..0000000 --- a/.settings/org.eclipse.jdt.apt.core.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.apt.aptEnabled=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b11489f..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,9 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore -org.eclipse.jdt.core.compiler.processAnnotations=disabled -org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f..0000000 --- a/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5c459fb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.6 +MAINTAINER Varun Manik "varunmanik1@gmail.com" +COPY . /app +WORKDIR /app +RUN pip install -r requirements.txt +ENTRYPOINT ["python"] +CMD ["app.py"] diff --git a/README.md b/README.md index 9cf16bd..b7f0b1c 100644 --- a/README.md +++ b/README.md @@ -1,109 +1,64 @@ -# Jenkins-cicd -PG DO - CI/CD Pipeline with Jenkins Simplilearn - -# AWS Ubuntu VM Provisioning steps -- Step 1: Click on Launch Instance -- Step 2 : Click on Software Image (AMI) -- Select Ubuntu -- Step 4: Key pair name – required -- Click on Create new key pair -- Put key pair name Jenkins-sl -- & Download it -- Step 5 : Click on Launch Instance -- Step 6 : Select your VM and Click connect -- Step 7 : You can see the terminal -- Step: Showing Github example - -# Git Status -``` -git --version -``` -## cretae Dir -``` -mkdir demo -cd demo -``` -## GIT & Ubuntu SSH connection -``` -ssh-keygen +# Installing Docker in Ubuntu -"Hit enter button 3 time" - -cat ~/.ssh/id_rsa.pub -git clone git@github.com:manikcloud/Jenkins-cicd.git -history -history | cut -c 8- ``` +sudo apt install docker.io -y +sudo systemctl start docker +sudo systemctl enable docker -# JENKINS INSTALLATION on UBUNTU 18.04, for Ubunt 22.04 please skip the step 3 & 4 ``` -sudo apt-get update -sudo apt install openjdk-8-jdk -sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' -sudo apt-get update -sudo apt install jenkins -sudo /etc/init.d/jenkins start -sudo service jenkins status -OR sudo cat /home/labsuser/jenkins/secrets/initialAdminPassword -history | cut -c 8- +# Installing Docker in Amazon linux ``` -# Jenkins URL with port 8080 -- http://x.x.x.x:8080/ - -replace x with your ip +sudo yum install docker -y +sudo systemctl start docker +sudo systemctl enable docker -# Change Security group rule for Jenkins -``` -- Select your instance -- Down below select your security tab -- Click on the Security groups sg-0c51908b5fa4abf75 (launch-wizard-2) -- Click on the action -- Click on EDIT INBOUND RULE -- Select custom TCP and put port 8080 -- Custom ip should be 0.0.0.0/0 -- Click on Save the rule ``` -# common error +# Simple Python Flask Dockerized Application# +- Git clone & ``` -getting "E: Unable to locate package openjdk-8-jdk" message on java update -``` - -# Resolution -Run this command +git clone https://github.com/manikcloud/Jenkins-cicd.git ``` -sudo apt update +- change the branch +``` +git switch 8.2-python-flask-app ``` -# Plugin Installation -dashboard>manage>jenkins>manage plugins>maven integration +## Build the image using the following command +```bash +sudo docker build -t flask-app:latest . +``` +Run the Docker container using the command shown below. -# Jenkins Setting +```bash +sudo docker run -d -p 5000:5000 flask-app -``` -Java_Home -/usr/lib/jvm/java-8-openjdk-amd64/ ``` -# Post Build Step +- The application will be accessible at http:127.0.0.1:5000 +- If you are using AWS EC2 VM then first find ip address and the use the ip `http://:5000` -``` -java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App + +# Jenkins Job setup "execute shell" ``` -# This project is parameterized +echo "running python-flask-app project" +#sudo docker rmi `docker images -aq` -f +sudo docker rm -f `docker ps -aq` +sudo docker build -t flask-app:$BUILD_ID . +sudo docker run -d -p 5000:5000 flask-app:$BUILD_ID + ``` -echo "User First name is : $First_Name" -echo "User Last name is : $Last_Name" -echo "User Gender is : $Sex" +## Common Error + Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: connect: permission denied + +- to overcome this error plz run the below command: ``` -# References: -1. https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html -2. https://maven.apache.org/download.cgi +chmod 777 /var/run/docker.sock +``` \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..5ab95f7 --- /dev/null +++ b/app.py @@ -0,0 +1,13 @@ +from flask import Flask +import os + +app = Flask(__name__) + +@app.route("/") +def hello(): + return "Flask inside Docker by Varun Manik 2023 Feb 19 Sunday!!" + + +if __name__ == "__main__": + port = int(os.environ.get("PORT", 5000)) + app.run(debug=True,host='0.0.0.0',port=port) diff --git a/history.txt b/history.txt deleted file mode 100644 index 850e06e..0000000 --- a/history.txt +++ /dev/null @@ -1,170 +0,0 @@ - 1 clear - 2 pwd - 3 apt udate - 4 apt update - 5 sudo apt update - 6 cat /etc/os-release - 7 ping fb.com - 8 mkdir demom - 9 mkdir demo - 10 cd demo - 11 git - 12 git -version - 13 git --version - 14 ls -a - 15 ll -a - 16 git init - 17 ll -a - 18 git status - 19 vim index.html - 20 git status - 21 git add . - 22 git status - 23 git commit -am"first file" - 24 git status - 25 git log - 26 vim index.html - 27 cat index.html - 28 git status - 29 git add . - 30 git status - 31 git commit -am"first file 1" - 32 git log - 33 cd .. - 34 ssh-keygen - 35 cd ~/.ssh/ - 36 ll - 37 cat id_rsa.pub - 38 cd - - 39 git clone git@github.com:manikcloud/Jenkins-cicd.git - 40 cat ~/.ssh/id_rsa.pub - 41 git clone git@github.com:manikcloud/Jenkins-cicd.git - 42 history - 43 history | cut -c 8- - 44 cd Jenkins-cicd/ - 45 vim README.md - 46 nano README.md - 47 git status - 48 git add . && git commit -am"adding readme" && git push - 49 nano README.md - 50 git add . && git commit -am"adding readme" && git push - 51 ll ~/.ssh/ - 52 cat ~/.ssh/id_rsa.pub - 53 ssh-keygen - 54 ll ~/.ssh/ - 55 ll - 56 rm varun * - 57 rm varun* - 58 ll - 59 git pull - 60 git status - 61 git rm . - 62 git status - 63 git rm README.md - 64 git status - 65 git rm pom.xml - 66 ll - 67 git status - 68 git restore --staged pom.xml - 69 ll - 70 cd .. - 71 rm -rf Jenkins-cicd/ - 72 git clone git@github.com:manikcloud/Jenkins-cicd.git - 73 cd Jenkins-cicd/ - 74 ll - 75 vi index.html - 76 git staus - 77 git status - 78 git add . - 79 git status - 80 git commit -am"adding index.html" - 81 git push - 82 vi README.md - 83 git pull - 84 vi README.md - 85 sudo apt install openjdk-8-jdk - 86 sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - 87 sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' - 88 sudo apt-get update - 89 sudo apt install jenkins - 90 sudo /etc/init.d/jenkins start - 91 service jenkins stgatus - 92 service jenkins status - 93 cat /var/lib/jenkins/secrets/initialAdminPassword - 94 sudo cat /var/lib/jenkins/secrets/initialAdminPassword - 95 history | cut -c 8- - 96 cd Jenkins-cicd/ - 97 vi README.md - 98 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 99 vi README.md - 100 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 101 git pull - 102 vi README.md - 103 ll -a - 104 rm .README.md.swp - 105 ll -a - 106 vim README.md - 107 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 108 vim README.md - 109 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 110 sudo cat /var/lib/jenkins/secrets/initialAdminPassword - 111 echo "varun" - 112 vim README.md - 113 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 114 git config --global --edit - 115 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 116 git push - 117 git pull - 118 vim README.md - 119 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 120 git pull - 121 vim README.md - 122 mvn --version - 123 sudo apt install maven - 124 apt install tree - 125 sudo apt install tree - 126 which mvn - 127 mvn --version - 128 cd .. - 129 mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false - 130 ll - 131 rm -rf my-app/ - 132 ll - 133 mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false - 134 ll - 135 cd my-app/ - 136 ll - 137 tree - 138 mvn ppackage - 139 mvn package - 140 ll - 141 tree - 142 ll - 143 ll target/ - 144 java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App - 145 vim src/main/java/com/mycompany/app/App.java - 146 java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App - 147 mvn clean install - 148 java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App - 149 cd .. - 150 ll - 151 rm -rf Jenkins-cicd/ - 152 git clone git@github.com:manikcloud/Jenkins-cicd.git - 153 cd Jenkins-cicd/ - 154 ll - 155 whereis mvn - 156 cd .. - 157 wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz - 158 ll - 159 tar -xvzf apache-maven-3.8.6-bin.tar.gz - 160 ll - 161 cd apache-maven-3.8.6/ - 162 ll - 163 pwd - 164 whereis java - 165 whereis git - 166 which git - 167 which mvn - 168 pwd - 169 ll - 170 history > ../Jenkins-cicd/history.txt diff --git a/index.html b/index.html deleted file mode 100644 index b14df64..0000000 --- a/index.html +++ /dev/null @@ -1 +0,0 @@ -Hi diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 8671f90..0000000 --- a/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - 4.0.0 - - com.mycompany.app - my-app - 1.0-SNAPSHOT - - my-app - - http://www.example.com - - - UTF-8 - 1.7 - 1.7 - - - - - junit - junit - 4.11 - test - - - - - - - - - maven-clean-plugin - 3.1.0 - - - - maven-resources-plugin - 3.0.2 - - - maven-compiler-plugin - 3.8.0 - - - maven-surefire-plugin - 2.22.1 - - - maven-jar-plugin - 3.0.2 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - - maven-site-plugin - 3.7.1 - - - maven-project-info-reports-plugin - 3.0.0 - - - - - diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7e10602 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java deleted file mode 100644 index d59f9ff..0000000 --- a/src/main/java/com/mycompany/app/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mycompany.app; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World! From Varun Manik" ); - } -} diff --git a/src/test/java/com/mycompany/app/AppTest.java b/src/test/java/com/mycompany/app/AppTest.java deleted file mode 100644 index 81ac345..0000000 --- a/src/test/java/com/mycompany/app/AppTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mycompany.app; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * Unit test for simple App. - */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); - } -} diff --git a/target/classes/com/mycompany/app/App.class b/target/classes/com/mycompany/app/App.class deleted file mode 100644 index 057e33a..0000000 Binary files a/target/classes/com/mycompany/app/App.class and /dev/null differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties deleted file mode 100644 index b1f1b69..0000000 --- a/target/maven-archiver/pom.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Created by Apache Maven 3.6.0 -version=1.0-SNAPSHOT -groupId=com.mycompany.app -artifactId=my-app 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 deleted file mode 100644 index de9dba0..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1 +0,0 @@ -com/mycompany/app/App.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 deleted file mode 100644 index 015d002..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ /dev/null @@ -1 +0,0 @@ -/root/Jenkins-cicd/my-app/src/main/java/com/mycompany/app/App.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 deleted file mode 100644 index 6348184..0000000 --- a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst +++ /dev/null @@ -1 +0,0 @@ -com/mycompany/app/AppTest.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 deleted file mode 100644 index cdee135..0000000 --- a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst +++ /dev/null @@ -1 +0,0 @@ -/root/Jenkins-cicd/my-app/src/test/java/com/mycompany/app/AppTest.java diff --git a/target/my-app-1.0-SNAPSHOT.jar b/target/my-app-1.0-SNAPSHOT.jar deleted file mode 100644 index 392b6ff..0000000 Binary files a/target/my-app-1.0-SNAPSHOT.jar and /dev/null differ diff --git a/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml b/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml deleted file mode 100644 index 4b9c2b4..0000000 --- a/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/surefire-reports/com.mycompany.app.AppTest.txt b/target/surefire-reports/com.mycompany.app.AppTest.txt deleted file mode 100644 index be9d8d3..0000000 --- a/target/surefire-reports/com.mycompany.app.AppTest.txt +++ /dev/null @@ -1,4 +0,0 @@ -------------------------------------------------------------------------------- -Test set: com.mycompany.app.AppTest -------------------------------------------------------------------------------- -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.115 s - in com.mycompany.app.AppTest diff --git a/target/test-classes/com/mycompany/app/AppTest.class b/target/test-classes/com/mycompany/app/AppTest.class deleted file mode 100644 index 11525d6..0000000 Binary files a/target/test-classes/com/mycompany/app/AppTest.class and /dev/null differ