TeamCity + Rancher + Docker achieve .Net Core project DevOps (the smallest cost DevOps practices)

1. Prepare items

1.1 a server, 1H4G (memory should also be smaller, self-testing), the system:. Ubuntu 16.04 64 bit

1.2 database, MYSQL, MSSQL can (there are other, self-configuration), the tutorial is MSSQL

1.3. Other software, Xshell (for remote Linux server), WinSCP (for files on a Linux server management)

2. Install the server environment

2.1.Docker installation environment:

Because of the wall, where the need to use a mirror to accelerate domestic service, where the use of mirrored Ali cloud acceleration services, Ali cloud services to accelerate the mirror, after landing Ali cloud, select [Mirror container service] -> [Mirror accelerator]

2.1.1 First, install Docker 

 
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

 

Bahrain input:

 
docker version

 

Query whether docker successfully installed.

Then configure the accelerated source, where you can use the command of Ali cloud provider, you can also find use WinSCP / etc / docker directory established daemon.json

 
{
  "registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com"]
}

 

xxxxxxx replaced by Ali cloud to provide your address

If you are using commands to add, so please enter the following command

Copy the code

mkdir -p /etc/docker

tee /etc/docker/daemon.json <<-'EOF'

{
"registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com"]
}

EOF

Copy the code

Then restart the docker services

 
systemctl daemon-reload

systemctl restart docker

Docker environment set up is completed

2.1.TeamCity-Server Environment Installation

Pulling official image (a bit large, it is recommended to use the cloud server test, inbound large bandwidth download speed block)

 
docker pull jetbrains/teamcity-server

 

appear

 
Status: Downloaded newer image for jetbrains/teamcity-server:latest

 

Then pulled successfully, then start teamcity-server

docker run -d -it --name teamcity-ecms -v /data/tc/datadir:/data/teamcity_server/datadir -p 8111:8111 jetbrains/teamcity-server

//然后
docker ps 
 
 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7a0a5b60a4b1 jetbrains/teamcity-server "/run-services.sh" 6 seconds ago Up 5 seconds 0.0.0.0:8111->8111/tcp teamcity-ecms

 

These results appear to succeed. Next, open the firewall port 8111 (if outside the network), visit: <your id>: 8111

Images appear above the building success!

Click [Proceed] button to enter the next step, select the type of database you are prepared, where the election MSSQL, you need to download JDBC drivers, click [Downloading JDBC drivers] button on the line, automatically download

 

According to the above picture to fill in, click on [Proceed], wait 3-10 minutes if there is an error, please check your parameters are filled in correctly!

After the agreement there will be a get that done, pulled the bottom, check Accept license agreement, click [Continue>] button

Then the Create an account page, create an administrator account on their own, landing ~

Up to this point, if the problem does not appear, then teamcity-server environment, we set up is completed.

2.2.TeamCity-Agent Environment Installation

There teamcity-server, agent needs to do Build, push the work (similar to compile platform)

The first step of pulling the Mirror Agent

 
docker pull jetbrains/teamcity-agent

 

The second step to start container

docker run -d -it -e SERVER_URL="192.168.0.19:8111" -v /etc/docker:/data/teamcity_agent/conf  -v /var/run/docker.sock:/var/run/docker.sock -v /opt/buildagent/work:/opt/buildagent/work -v /opt/buildagent/temp:/opt/buildagent/temp -v /opt/buildagent/tools:/opt/buildagent/tools -v /opt/buildagent/plugins:/opt/buildagent/plugins -v /opt/buildagent/system:/opt/buildagent/system jetbrains/teamcity-agent

 

 

[192.168.0.19:8111]这里最好填内网地址(安装速度快,省流量),如果没有局域网,就要填外网地址,请大家注意!

并且这个启动方式会和Agent的共享主机的Docker配置和缓存,如果有疑问可以使用另外一个命令,https://hub.docker.com/r/jetbrains/teamcity-agent/,自行翻阅

执行后,可使用docker logs -f <CONTAINER-ID>查看启动日志,CONTAINER-ID使用docker ps查看

然后进入Server的WEBUI页面,选择Agents->Unauthorized

审核它!然后他就会出现在Connected里!

到这里为准,TeamCity的所有环境就搭好了!!!!!

2.3.Rancher环境安装

拉取镜像并部署容器

 
docker run -d --restart=unless-stopped -p 8080:8080 rancher/server

 

过3-5分钟后,防火墙打开8080端口,访问<your id>:8080

出现上述页面,成功,rancher环境安装完毕!!!

2.4.docker register环境配置

修改之前的daemon.json

 
{
  "registry-mirrors": ["https://xfgphhex.mirror.aliyuncs.com"],
     "insecure-registries":["192.168.0.19:5000"]
}

 

保存。192.168.0.19可以配置成外网(已测试,木有问题),记得打开5000端口!

重启docker

 
systemctl restart docker

 

注意,重启docker会把teamcity和rancher的容器关掉,记得重启一下3个容器(ID通过docker ps -a命令查询)

 
docker start <Container ID>

 

启动register

 
docker run -d -p 5000:5000 --name registry registry:2

 

环境到这一步就搭建完毕了~!接下来就是DevOps实现

3.DevOps实践

3.1使用TeamCity制作镜像并注册到Docker register中

打开TeamCity,点击左上角[projects],点击[create project]

进入后,选择[Manually]

填一个名字保存。

进入下面这个页面,点击[+Create build configuration]

填一个名字保存。

进入下面这个页面,填写源代码的url,这里使用朋友的一个脚手架项目做演示,你们也可以先用这个做实验,gitee地址:https://gitee.com/kitteam/ecms

保存。返回下图的页面,点击Build Steps ,点击[+Add build step]按钮

 

 第一步,使用dockerfile制作镜像,参数如下,dockerfile在图上的地址,自行在gitee查看,可以使用后面的选择选出来也行。路径一定要填'/'要不然copy代码会失败

 

第二步,将打包好的镜像register到agent的服务器上

继续[+Add build step],这次命令选other,具体参数如下图

第三部,把register里的镜像推送上去

继续[+Add build step],这次命令选push,具体参数如下图

 

 OK,到这一步teamcity的配置就完成了!

接下来run一次把~~~~~

 

【192.168.1.43的问题是因为内网IP换了~~~,所以跟着换了,大家不用在意这点细节】

点击后,可以去[Projects]里看日志,稍等片刻把~(第一次build有点慢(5分钟左右),后续build因为docker缓存的原因会快很多(1分钟))

The following figure appears, then teamcity the task all done! !

3.2 Rancher management host, the mirror, the container

3.2.1 Add Host

 Top: Infrastructure - Host, click Add Host

Click Save

Fill in IP, copy the following command to the server to perform

 

Then wait a moment, the installation is successful, go to the host page views

3.2.2 Add Application

Click on the upper left corner, select the Environment

Click [add application]

Just fill out save!

After the jump, click on the upper right corner to add [service]

Fill parameters as shown below

Click Create

Then wait a moment, turn on the host

Start finished, this time to open <your ip>: 8081 visit

Here, in this article to the end, success ~

 

Articles hope for companies and individuals interested to build CI / CD DevOps environments help, Crab!

Guess you like

Origin www.cnblogs.com/duwamish/p/10971480.html