Static Webpage deployment using Git-Jenkins-Docker-Nginx
Install Jenkins using the below commands for Ubuntu 22.04
apt-get update apt install openjdk-11-jre curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null sudo apt-get update sudo apt-get install jenkins
Port 8O8O should be open to access Jenkins, if it is busy already use the below command and change the port.
systemctl edit jenkins
[Service]
Environment="JENKINS_PORT=8080"
Change 8080 to whatever port is available.
open http://<IP>:8080 and enter the Admin password which is available in the below path.
cat /var/lib/jenkins/secrets/initialAdminPassword
- Install the required plugins, and pass the initial username and password.
Install Docker using official documentation- https://docs.docker.com/engine/install/ubuntu/
- Run the below commands to give access to Jenkins users to run docker commands in the server.
chmod 666 /var/run/docker.sock
Now open Jenkins UI click on New Item name it a simple app and select Pipeline.
Select the GitHub project and enter the link to the repository below.
https://github.com/prashanthgowdagr/simple-index.html-app.git
Scroll down and select the GitHub hook trigger. This will help us to build the Jenkins job whenever the commit is made to the 'MAIN' branch of the Git repo.
To set this up go to GitHub and under repo go to settings> Webhooks> and paste the Jenkins server IP address with port number and end with GitHub-webhook/ (don't forget the / in the end). Select Just the push event and save the changes.
Under Pipeline select Pipeline script from SCM and select GIT as SCM.
Enter the Git repo URL and branch as main. The script path should be specified as Jenkinsfile.
Before running the job go to Manage_Jenkins> Credentials> system> golbal> name it "dockercreds" (Use same or it will throw an error/change the variable in jenkinsfile) and enter your DockerHub creds and password. If there is no DockerHub account, plz create one it's FREE!!!
Run the job now and this will pull the code from Git copy the index.html into the docker container and run it. You can access the webpage now using http://<IP>:80
This will also push the updated container to DockerHub with the tag 'latest' and also with the 'Jenkins Build Number'.
Subscribe to my newsletter
Read articles from Prashanth Gowda G R directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by