Giter Club home page Giter Club logo

jenkins-lab's Introduction

jenkins-lab

Questions.

Remaining old Questions.

New Questions part.

  • 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

Answers

4- configure jenkins image to run docker commands on your host docker daemon

Docker file.

```
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

```

Build and push the image.

```
docker build -t amrtarek6/jenkins_main:version .
docker push amrtarek6/jenkins_main:version
```

Runing the container.

```
docker run -it -d --name jenkins_main -v /var/run/docker.sock:/var/run/docker.sock amrtarek6/jenkins_main:version
```

image

image

pipeline Code.

```
    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")
            }
        }

    }
```

Runing app

image

1- create docker file to build image for jenkins slave

Dockefile_slave Code.

```
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

```

2- create container from this image and configure ssh

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

```

image image

3 from jenkins master create new node with the slave container

image image

runing app with slave node using slave label

image

4- integrate slack with jenkins

image image image image

5- send slack message when stage in your pipeline is successful

image

6- install audit logs plugin and test it

image image

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

my forked Repo

https://github.com/AmrTarek17/Booster_CI_CD_Project

success Trigered Action

image

runing app

image

jenkins-lab's People

Contributors

amrtarek17 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.