Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Automatic building of centos7+docker+Jenkins+svn

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Centos7+docker+Jenkins+svn builds automated deployment platform 1. Centos7

Reference link: http://www.macrozheng.com/#/reference/linux_install

Tips

The company server configuration (1T machine + 256 solid state + i7 u) requires us to install the system, environment (java,mysql,redis,docker, etc.) on the solid state (fast), and our code on the machine. The zoning is shown in the following figure

2. Install docker1.31.1 in centos7

Own Baidu, there is no pit here.

3. Centos7 installation and configuration java8,maven,redis,mysql

When installing jdk1.8 and maven, try to use the compressed package to decompress, using yum to have a pit. My installation path

Configure the environment vim / etc/profile, as shown in the figure

# java,maven environment configuration # split different configurations export JAVA_HOME=/mydata/java/jdkMAVEN_HOME=/mydata/java/mavenexport PATH=$JAVA_HOME/bin:$PATH:$ {MAVEN_HOME} / binexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar with':'

For centos7 to install mysql5.7, refer to the link:

Https://www.cnblogs.com/helf/p/11244711.html

For centos7 to install redis, refer to the link:

Https://www.cnblogs.com/zuidongfeng/p/8032505.html4. Install Jenkins in docker

Download the docker image of Jenkins:

Docker pull jenkins/jenkins:lts

Run Jenkins in the Docker container:

/ / here, because java and maven are installed directly on linux and Jenkins is installed on docker, you must mount jdk and maven (pit) / /-v commands to mount, where the directory before the colon is the local directory; / / the path of the local javahome and mavenhome must be mounted to the Jenkins container / / the directory on the container after the colon, which can be written the same as the local directory. Docker run-p 8080 mydata/java/jdk:/mydata/java/jdk 8080-p 50000 docker run 5000-- name jenkins\-u root\-v / mydata/java/jdk/bin/java:/mydata/java/jdk/bin/java\-v / mydata/java/jdk:/mydata/java/jdk\-v / mydata/java/maven:/mydata/java/maven\-v / mydata/jenkins_home:/var/jenkins_home\-d jenkins/jenkins:lts

Forget the Jenkins initialization password and use docker logs jenkins to view the log

Reference link: http://www.macrozheng.com/#/reference/jenkins

Configuration as shown in the figure

5. Centos7 install svn

​ reference link: https://www.cnblogs.com/zhangheliang/p/8724605.html

6. Integration of Jenkins and svn

Configuration of Jenkins

There is also a way not to remove the tick. I reported 404 when I got the crumb value. In order to solve the problem, I need to do it on my own.

Configuration of svn

Add the following code to the generated post-commit

Curl-X post-v-u admin:117f598cc5f81226faaac0ceff40b367da http://ip:8080/jenkins/job/jenkinsdemo/build?token=APPLE_TOKEN7. Shell script and DockerFile file #! / bin/bash# operation / project path (path where Dockerfile is stored) Each project has a corresponding dockerfileDOCKERFILE_PATH=/mydata/jenkins_home/workspace/jenkinsdemo/src/main/docker#jenkins workspace SOURCE_PATH=/mydata/jenkins_home/workspace#docker image / container name or jar name here is named this SERVER_NAME=jenkinsdemoJAR_NAME=demo-0.0.1-SNAPSHOT# get container idCID=$ (docker ps | grep "${SERVER_NAME}" | awk'{print $1}') # get image idIID=$ (docker images | grep "${SERVER_NAME}" | awk'{print $3}') DATE= `date +% Y% m% d% H% M` # backup function backup () {if [- f "${DOCKERFILE_PATH} / ${SERVER_NAME} .jar"] Then echo "${SERVER_NAME} .jar backup." Cp ${DOCKERFILE_PATH} / ${JAR_NAME} .jar ${DOCKERFILE_PATH} / backup/$ {SERVER_NAME}-$DATE.jar echo "backup ${JAR_NAME} .jar completion" else echo ${DOCKERFILE_PATH} / ${JAR_NAME} .jar does not exist Skip backup "fi} # latest build code move to project environment # put the newly built jar package in the same level directory as dockerfile function transfer () {echo" la la ${DOCKERFILE_PATH} "echo" latest build code ${SOURCE_PATH} / ${SERVER_NAME} / target/$ {JAR_NAME} .jar migrate to ${DOCKERFILE_PATH} "cp ${SOURCE_PATH} / $ {SERVER_NAME} / target/$ {JAR_NAME} .jar ${DOCKERFILE_PATH} / echo "Migration completed"} # modify access function changemod () {echo "modify access to ${DOCKERFILE_PATH} / ${JAR_NAME} .jar" cd ${DOCKERFILE_PATH} chmod 777 ${JAR_NAME} .jar echo "modify access completed" # build docker image function build () {if [- n "$IID"] Then echo "there is a ${SERVER_NAME} image, IID=$IID" echo "stop container docker stop $CID" docker stop $CID echo "delete container docker rm $CID" docker rm $CID echo "delete image docker rmi ${SERVER_NAME}" docker rmi ${SERVER_NAME} echo "build image docker build-t" ${SERVER_NAME}. " Cd ${DOCKERFILE_PATH} docker build-t = "${SERVER_NAME}". Else echo "there is no ${SERVER_NAME} image, start building the image docker build-t ${SERVER_NAME}." Cd ${DOCKERFILE_PATH} docker build-t = "${SERVER_NAME}". Fi} # run docker container function run () {backup transfer changemod build echo "docker run to create container... Docker run-d-- name=$ {SERVER_NAME}-p 8002docker run 8082-v ${DOCKERFILE_PATH}: ${DOCKERFILE_PATH} jenkinsdemo:latest "docker run-d-- name=$ {SERVER_NAME}-p 8002pur8002-v ${DOCKERFILE_PATH}: ${DOCKERFILE_PATH} jenkinsdemo:latest echo" ${SERVER_NAME} Container creation complete "} # entry run # the basic image FROM java on which the image depends Copy the jar package under the current directory to the / directory of the docker container during the ADD demo-0.0.1-SNAPSHOT.jar / jenkinsdemo.jar# run to create a mall-tiny-docker-file.jar file RUN bash-c 'touch / jenkinsdemo.jar'# declare that the service runs on port 8083 EXPOSE 808 specifies that the jar package ENTRYPOINT runs when the jar container starts ["java" "- jar", "/ jenkinsdemo.jar"] # specify the name of the maintainer MAINTAINER zhaoguozhen

8. Docker installs the visualization tool Portainer

Reference link: https://my.oschina.net/zhengqingya/blog/3066410

9. Result

10. TIPS

Docker is packaged into a docker image and run through dockerfile, and multiple sub-projects (micro services) can also be deployed using Docker Compose (this thing is similar to batch processing, using one command to deploy all configured services).

The variables in the shell script cannot be printed. Consider changing the name.

For example, if BASE_PATH is replaced with DOCKERFILE_PATH, the shell script can be executed successfully.

The access link cannot be opened. Consider whether to turn on the firewall and permissions.

# Open firewall firewall-cmd-- zone=public-- add-port=9000/tcp-- permanent# reload firewall-cmd-reload# to view the open port firewall-cmd-- list-ports

Understanding CI CD in vernacular

Packaging the code into a container is called CI, and deploying the container to the server is CD

11. Postscript through the following picture, the GitHub webhook requirement must be a public network IP

Automated deployment platform understanding

The top is only done horizontally, but not vertically. Next, we need to get a docker manager to manually select the packaged code image on a docker in the docker cluster.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report