Docker learning -jenkins + github achieve continuous integration and deployment

Previous introduces docker environment to build herein, this continue in-depth, combined with the use of docker-compose jenkins container arrangement brief introduction of how to achieve personal learning continuous integration / deployment.

Benpian learning curve:

1. Installation / operation jenkins container

2.asp.net core web project configuration

3.jenkins configuration github code management

4. The example shows

Installing / running jenkins container

1. Log in to run the command, pull jenkins mirror (note jenkins tag):

docker pull jenkins/jenkins 

Start jenkins container:

docker run -d --name jenkins -p 8081:8080 -p 50000:50000 -v /root/jenkins_home:/var/jenkins_home -v /usr/bin/docker:/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v /usr/local/bin/docker-compose:/bin/docker-compose jenkins/jenkins

The above brief explanation command: -d background identification, identification -name image name, -p designated host port - the internal container port mapping, identify the host -v Directory - mapping the container volume (container directory is mounted to the host directory so durable data)

Note that I am here -v /var/run/docker.sock:/var/run/docker.sock order to achieve internal container docker response command, see details about /var/run/docker.sock

2. Enter the server ip + jenkins port

 

 After jenkins container runs for the first time using the admin account login, password admin can: View / container mount path / secrets / initialAdminPassword file.

After logging in the default mode is to choose to install plug-ins, waiting to enter the page automatically after the plugin is installed (as a result of other causes speed plug-in installation fails, go to System Management - Plugin Manager can be installed manually)

Into jenkins home page:

 

 

asp.net core web project configuration

1. Create a new asp.net core web project and upload it to storage github

Configuring jenkins / github webhook, so that there is automatically triggered to submit the code message after sending a subscription target github

jenkins association github webhook configuration, see: https://www.jianshu.com/p/07b60b788088 

 

jenkins configuration github code management

Log jenkins, the new free-style software project

 

 That set up the project management source address access credentials

 

 Check above options (github code is submitted automatically trigger a build task)

 

 As the build script, simple instructions below:

# Remove docker build process temporary image (no image name and tag: none <none>)

docker image prune -f 

When receiving github jenkins trigger a build time, the Codes: {vessel mount directory} / workspace / {jenkins item name}, execute shell commands within the container jenkins Note that, an absolute path is absolute and therefore the interior of jenkins, into the the code storage location: cd / var / jenkins_home / workspace / WorkPipeline

Docker-compose build command execution

有关于docker-compose.yml即Dockerfile文件,请看本篇末尾github项目链接

示例演示

提交代码,

 

jenkins工作台可以看到正在构建

 

 查看构建日志:

 

 

 

 项目构建成功,docker-compose.yml文件中将主机端口映射到webonline容器5000端口

 

 现在,浏览器输入:http://{服务器ip}:5000

 

 web项目成功部署

本示例中的web项目及相关dockerfile配置见github链接:https://github.com/ChuanGoing/DockerMain.git

Guess you like

Origin www.cnblogs.com/ChuanGoing/p/12045697.html