This repository contains code for my portfolio web pplication.
This projects builds a Jenkins CI pipeline. Every time I commit changes to this repository. Jenkins will build the docker image of my web application, push it to a docker repository that is being hosted on Sonatype Nexus, and update the version of the web application in the GitHub.
Read this blog for a better understanding of this project.
- use any Ubuntu version for the host server machine.
- port
22
: ssh - add only your device's ip address - port
8081
: nexus - this is where your nexus application will run - port
8082
: docker repo - this is the IP add of the docker(hosted by Nexus) where we will store images
ssh root@<ipAddressServer>
echo 'PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "' >> .bashrc && source .bashrc
- Install docker on Nexus server:
apt update -y && apt install docker.io -y
docker volume create --name nexus-data
docker run -d -p 8081:8081 -p 8082:8082 --name nexus -v nexus-data:/nexus-data sonatype/nexus3
- port
22
: ssh - add only your device's ip address - port
8080
: jenkins - this is where your jenkins application will run
Create a storage where all the components of your docker repository will be stored.
Create a docker(hosted) repository and assign port 8082 to it.
Create a role. Provide this role access to the docker repo.
Create a user. Assign this user the role that you just created.
- Install docker on Jenkins server:
apt update -y && apt install docker.io -y
docker run -d -p 8080:8080 -p 5000:5000 -v jenkins_home:/var/jenkins_home -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock --name jenkins jenkins/jenkins:lts-jdk11
- ssh into the jenkins-server as a root user.
vi /etc/docker/daemon.json
- Add
{"insecure-registries": ["64.227.128.95:8082"]}
to the daemon.json file. Create this file if it doesn't exist already. The IP address here is the address of the docker repo that you hosted on Nexus.
- Add
- Resart docker to reflect the changes:
systemctl daemon-reload
systemctl docker restart docker
- Check whether the jenkins user in the jenkins container still has the permission to read
/var/run/docker.sock
file or not. If not, give the permission again.
docker exec -it -u 0 jenkins bash
chmod 666 /var/run/docker.sock
exit
- This file can be accessed by root user as well
docker exec -it jenkins bash
cat /var/lib/jenkins/secrets/initialAdminPassword
- Create below creadentials IDs:
- github (git repository)
- dockerhub (artifact repository)
- Ad webhook in github
<ipAddressOfHostServer>:<portNoOfJenkins>/github-webhook/
- E.g.->
143.110.184.204:8080/github-webhook/
- E.g.->
- Add GitHub SCM trigger
- Add 'jenkins' user to the list of Polling ignores commits from certain users!