Static Webpage deployment using Git-Jenkins-Docker-Nginx

  1. 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
    
  2. 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.

  1. open http://<IP>:8080 and enter the Admin password which is available in the below path.

     cat /var/lib/jenkins/secrets/initialAdminPassword
    
    1. Install the required plugins, and pass the initial username and password.

Install Docker using official documentation- https://docs.docker.com/engine/install/ubuntu/

  1. Run the below commands to give access to Jenkins users to run docker commands in the server.
     chmod 666 /var/run/docker.sock
  1. Now open Jenkins UI click on New Item name it a simple app and select Pipeline.

  2. Select the GitHub project and enter the link to the repository below.

https://github.com/prashanthgowdagr/simple-index.html-app.git
  1. 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.

  2. 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.

  3. Under Pipeline select Pipeline script from SCM and select GIT as SCM.

  4. Enter the Git repo URL and branch as main. The script path should be specified as Jenkinsfile.

  5. 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!!!

  6. 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

  7. This will also push the updated container to DockerHub with the tag 'latest' and also with the 'Jenkins Build Number'.

0
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

Prashanth Gowda G R
Prashanth Gowda G R