Gitlab+Jenkins+Docker+ project, to achieve a complete set of automated online services

table of Contents

         surroundings

         Install Gitlab

         Install Jenkins

         The combination of Jenkins and Gitlab

         Start integrating Jenkins

         Docker deploys LNMP

         Jenkins configuration to send files to LNMP host via ssh

         Push the project to Gitlab

         Perform Jenkins build tasks to achieve automatic release

         Visit the project web

         to sum up

 

surroundings

Gitlab node: 192.168.253.110 Jenkins node: 192.168.253.130

I used two servers for the test environment, and I placed the project on the jenkins server. The system version is centos 7.5.

Install Gitlab

Hi! Look here for the installation of Gitlab~~>  Docker builds the company's internal private cloud platform - Gitlab

[root@gitlab ~]# docker run -it -d --name gitbab -p 80:80 docker.io/gitlab/gitlab-ce
674e5e8a3e35cb2ec95c385e7130082e1fef0d55494b953b7bd88d039473683c

Install Jenkins

Of course, there is also a tutorial for installing Jenkins here~~>  Jenkins installation and Chinese display  , but here I want to do it myself again.

1) Download the java environment and upload the jenkins package

[root@jenkins ~]# yum -y install java-1.8.0 lrzsz   java环境
[root@jenkins ~]# ls
jenkins-2.222.4-1.1.noarch.rpm    我用的是这个版本

2) Install and start jenkins

[root@jenkins ~]# rpm -ivh jenkins-2.222.4-1.1.noarch.rpm 
警告:jenkins-2.222.4-1.1.noarch.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID d50582e6: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:jenkins-2.222.4-1.1              ################################# [100%]
[root@jenkins ~]# systemctl  start jenkins
[root@jenkins ~]# setenforce 0
[root@jenkins ~]# systemctl  stop firewalld

3) Browser http: ip + 8080 for access

[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
252fd6734a17467684cce9591eba7229

4) Configure download plug-in acceleration (the default plug-in download source is abroad, downloading is particularly slow)

[root@jenkins ~]# vim /var/lib/jenkins/hudson.model.UpdateCenter.xml
<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>        #改为国内的网站
  </site>
</sites>

[root@jenkins ~]# cd /var/lib/jenkins/updates/
[root@jenkins updates]# sed -i 's/http:\/\/updates.jenkinsci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json 
[root@jenkins updates]# sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
[root@jenkins ~]# systemctl  restart jenkins

5) Download Chinese plug-in

Just restart! !

The combination of Jenkins and Gitlab

1) We create a project on Gitlab to store our code

2) We clone the project warehouse to the local to test whether it can be cloned.

Create an empty directory on windows to store the project warehouse. Explain:

Here my git is the windows version ~~> This is the windows version package  , the Linux version git~~> here 

 I created a new directory on the desktop to put projects

Note: For the first clone, you will be prompted to enter the login account and password of gitlab

3) Check whether it is successful

4) Upload a line of code in the project for testing (I created a new txt file)

5) Make a local submission and submit the code to the wordpress project in gitlab

6) See if it is successful in this wordpress project

Start integrating Jenkins

1) Install the git plugin and git environment on the jenkins node

[root@jenkins ~]# yum -y install git

      1.1) Install the git plugin on the web

2) Create a task in Jenkins

Configure the URL address of the gitlab project warehouse and the account password for logging in to gitlab, and save it after filling in

3) Start the build task

  3.1) Click this build task to view the console output

! ! At this time, Jenkins and Gitlab are successfully combined

Docker deploys LNMP

Explain: My project here is wordpress, and I need to use the Lnmp environment.

1) Build the docker image of lnmp by yourself, here is the package for building the image~~>  Click me

[root@jenkins ~]# tar xzf lnmp.tar.gz 
[root@jenkins ~]# cd lnmp
[root@jenkins lnmp]# docker build -t lnmp .
[root@jenkins ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
lnmp                latest              57e3c3e09aab        9 seconds ago       443 MB
docker.io/centos    latest              0d120b6ccaa8        7 weeks ago         215 MB

2) Start a lnmp container

[root@jenkins ~]# docker run --name wordpress -itd -p 81:80 -v /opt/html/:/usr/local/nginx/html lnmp
1e62d99e01c2c20b4e529afffc01e11dea54e7e2d1a2f80333a3b1c99589390a
[root@jenkins ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
1e62d99e01c2        lnmp                "/usr/bin/supervis..."   6 seconds ago       Up 6 seconds        0.0.0.0:81->80/tcp   wordpress

Jenkins configuration to send files to LNMP host via ssh

1) Publish Over SSH plug-in needs to be installed on jenkins, through this plug-in jenkins can send files in the workspace to the remote host

2) Configure plug-in, add remote host, add LAMP host

3) Go to the home page and go to configuration tasks

!! So  far the task is configured! The file will be automatically sent to the remote host when the task is executed

Push the project to Gitlab

To explain: here is the blog on my project, of course, it can also be posted on others.

1) Unzip the installation package on the computer, copy and paste the package content to the local warehouse

2) Submit to the local warehouse and push to Gitlab

3) Check whether gitlab is successfully pushed

Perform Jenkins build tasks to achieve automatic release

1) Build task

2) Check whether the build is successful in the console

Visit the project web

1) Enter http:// + ip + 81 in the browser

to sum up

           It took a day to make this and it feels pretty good. The project I used here is a blog. Partners can also use other projects. Writing is not easy! !

Guess you like

Origin blog.csdn.net/yeyslspi59/article/details/108926990
Recommended