- 4- configure jenkins image to run docker commands on your host docker daemon
- 5- create CI/CD for this repo https://github.com/mahmoud254/jenkins_nodejs_example.git
- 1- create docker file to build image for jenkins slave
- 2- create container from this image and configure ssh
- 3 from jenkins master create new node with the slave container
- 4- integrate slack with jenkins
- 5- send slack message when stage in your pipeline is successful
- 6- install audit logs plugin and test it
- 7- fork the following repo https://github.com/mahmoud254/Booster_CI_CD_Project and add dockerfile to run this django app and use github actions to build the docker image and push it to your dockerhub
```
FROM jenkins/jenkins:lts
USER root
RUN apt-get update -y
RUN apt-get install apt-transport-https curl gnupg-agent ca-certificates software-properties-common -y
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" -y
RUN apt-get update -y
RUN apt-get install docker-ce docker-ce-cli containerd.io -y
RUN usermod -aG docker jenkins
```
```
docker build -t amrtarek6/jenkins_main:version .
docker push amrtarek6/jenkins_main:version
```
```
docker run -it -d --name jenkins_main -v /var/run/docker.sock:/var/run/docker.sock amrtarek6/jenkins_main:version
```
5- create CI/CD for this repo https://github.com/mahmoud254/jenkins_nodejs_example.git
```
pipeline {
agent any
stages {
stage('CI') {
steps {
git 'https://github.com/mahmoud254/jenkins_nodejs_example'
withCredentials([usernamePassword(credentialsId: 'Dockerhub', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh "docker build . -f dockerfile -t ${USER}/node-app:v1"
sh "docker login -u ${USER} -p ${PASS}"
sh "docker push ${USER}/node-app:v1"
}
}
}
stage('CD') {
steps {
withCredentials([usernamePassword(credentialsId: 'Dockerhub', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh "docker login -u ${USER} -p ${PASS}"
sh "docker run -d -p 3030:3000 ${USER}/node-app:v1"
}
}
}
}
post{
success {
slackSend(message: "success tes")
}
failure {
slackSend(message: "failure Run")
}
}
}
```
```
FROM ubuntu
USER root
RUN apt-get update -y
RUN apt-get install -y openssh-server
# RUN service ssh start
RUN apt-get install openjdk-11-jdk -y
RUN apt-get install git -y
RUN apt-get install apt-transport-https curl gnupg-agent ca-certificates software-properties-common -y
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" -y
RUN apt-get install docker-ce docker-ce-cli containerd.io -y
RUN mkdir /root/.ssh
COPY id_rsa.pub /root/.ssh/authorized_keys
ENTRYPOINT service ssh start && bash
```
ssh already cofigured with docker file only need to let id_rsa.pub in the same Dir and configure id_rsa with jenkins Credintials ```
docker build -t amrtarek6/jenkins_slave:version -f Dockefile_slave .
docker run -it -d --name slave -v /var/run/docker.sock:/var/run/docker.sock amrtarek6/jenkins_slave:version
```