AntDeploy工具功能简介
- 支持docker一键部署(支持netcore)
- 支持iis一键部署(支持netcore和framework)
- 支持windows服务一键部署(支持netcore和framework)
- 支持linux服务一键部署(支持netcore)
- (支持增量发布)(支持一键回滚)(支持点火)(支持选择特定文件发布)(支持查看发布记录)
- 支持脱离Visual Studio独立使用(跨平台支持windows系统和mac系统)
- 支持Agent批量更新
资源地址:
- github源码:AntDeploy
- Visual Studio插件(同步化):AntDeploy - Visual Studio Marketplace
- Visual Studio插件(异步化):AntDeployVsix - Visual Studio Marketplace
- (如要安装Windows服务器上agent服务)How to install:https://github.com/yuzd/AntDeployAgent/issues/1
- 为什么发布到【windows服务】或【linux服务】需要服务器上要装agent?:https://github.com/yuzd/AntDeployAgent/issues/7
- 如何脱离Visual Studio独立使用:https://github.com/yuzd/AntDeployAgent/issues/18
- 其他教程(看完原理使用更上手):https://github.com/yuzd/AntDeployAgent/issues
使用AntDeploy一键制作镜像并上传腾讯云私有镜像仓库
1、演示环境说明:
- 操作系统:Windows 10 专业工作站版 x64,内核版本号 2004
- Microsoft Visual Studio Enterprise 2019 版本 16.8.2
- 本地Hyper-V安装ubuntu-20.04虚拟机(操作vm终端vs code)
- AntDeploy 离线版Version:7.28
注意事项:
- 确保本地配置的vm可以访问外网,并且与宿主机相互通信,查看网络工具=》# sudo apt install net-tools
- 确保vm安装docker=》# sudo apt update & sudo apt install docker.io
- 确保vm安装unzip =》# sudo apt install unzip
- vs code 安装插件(可选配置:Remote - WSL,Docker ),通过ssh 连接vm =》# ssh chait@172.29.161.146 提示输入密码即可
vm安装docker配置国内镜像源:
- 阿里镜像源配置=》ubuntu镜像-ubuntu下载地址-ubuntu安装教程-阿里巴巴开源镜像站 (aliyun.com) 配置对应linux版本即可;
- 确保vm(基于ubuntu)开启22端口,操作如下:
1. 查看Ubuntu的IP地址
ifconfig
2.执行后,可能该项的服务功能未安装,根据提示执行,安装网络工具
sudo apt install net-tools
安装后,想通过vs code/pwsh ssh远程工具连接的时候发现连接失败。
此时,查看Ubuntu关于22的端口,执行命令如下
netstat -ntlp|grep 22
参数解释:
-n 不以进程的服务名称,以端口号(port number)显示
-t 列出tcp网络封包的信息
-l 列出目前正在网络监听(listen)服务
-p 列出该网络服务的进程
此时若发现无任何关于22端口的进程内容,执行以下命令
#安装openssh-server
sudo apt install openssh-server
#安装ufw防火墙
sudo apt install ufw
#启动ufw防火墙
sudo ufw enable
#ufw开发22端口
sudo ufw allow 22
- vm中安装好docker后授权非root账户使用,配置步骤如下:
1.创建docker组
sudo groupadd docker
2.将当前用户加入docker组
sudo gpasswd -a ${USER} docker
3.重新启动docker服务
sudo service docker restart或sudo systemctl restart docker
4.当前用户退出系统重新登陆
# su root
# su chait
5.运行docker命令,查看是否可使用
docker ps 或 docker images
如果出现失败,可以重启下vm,再次测试。
重启命令 :
- reboot
- shutdown -r now 立刻重启
- shutdown -r 10 过10分钟自动重启
- shutdown -r 20:35 在时间为20:35时候重启
关机命令 :
- halt 立刻关机(一般加-p 关闭电源)
- poweroff 立刻关机
- shutdown -h now 立刻关机
- shutdown -h 10 10分钟后自动关机
如果是通过shutdown命令设置关机的话,可以用shutdown -c命令取消关机。
2、AntDeploy镜像制作:
2|1 准备.net5相关镜像,国内下载镜像可能会失败,受限于网络原因:
- dotnet/sdk: .NET SDK
- dotnet/aspnet: ASP.NET Core Runtime
- dotnet/runtime: .NET Runtime
- dotnet/runtime-deps: .NET Runtime Dependencies
- dotnet/samples: .NET Samples
按需拉取镜像即可,此处演示只需如下镜像:.NET SDK & ASP.NET Core Runtime
#5.0 (Current)
#5.0 ASP.NET Core Runtime
docker pull mcr.microsoft.com/dotnet/aspnet:5.0
docker pull mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim
#5.0 .NET SDK
docker pull mcr.microsoft.com/dotnet/sdk:5.0-buster-slim
腾讯云平台准备Docker私有镜像仓库,确保vm和宿主机可以正常登录访问:
#登录腾讯云docker registry
sudo docker login --username=[user] ccr.ccs.tencentyun.com
#提示输入对应的密码即可
#从registry拉取镜像
sudo docker pull ccr.ccs.tencentyun.com/sws-center-ol-service-dev/rg-sws-center-ol-dev-2069:[tag]
#将镜像推送到registry
sudo docker login --username=[user] ccr.ccs.tencentyun.com
sudo docker tag [ImageId] ccr.ccs.tencentyun.com/sws-center-ol-service-dev/rg-sws-center-ol-dev-2069:[tag]
sudo docker push ccr.ccs.tencentyun.com/sws-center-ol-service-dev/rg-sws-center-ol-dev-2069:[tag]
腾讯云平台Docker私有镜像仓库已经准备如下镜像:
本地拉取镜像的时候,可以配置国内镜像源:
本地Windows PowerShell/PowerShell 下载镜像,现在本机上面安装个Docker for Windows 客户端工具,然后配置镜像源地址:
2|2实现目标:
- 使用vs2019创建对应的b/s应用程序,此处演示的是【NetService-Jwt】;
- 使用AntDeploy工具一键制作镜像(基于.net5构建的应用镜像)并发布到腾讯的docker私有镜像仓库;
- 部署准备,腾讯云TKE(基于k8s)平台从私有镜像仓库拉取镜像实施资源部署;
1.配置AntDeploy.json, 界面操作工具配置好后得到如下配置信息;
{
"Env": [
{
"Name": "docker-ubuntu-20.04",
"ServerList": [],
"LinuxServerList": [
{
"UserName": "chait",
"Pwd": "35FE3BA71BD99AF92DB2A32F980ECDAE",
"Host": "172.29.161.146",
"NickName": "docker",
"IIsFireUrl": null,
"DockerFireUrl": "",
"WindowsServiceFireUrl": null,
"LinuxServiceFireUrl": null
}
],
"IgnoreList": [],
"WindowsBackUpIgnoreList": []
}
],
"IIsConfig": {
"SdkType": null,
"WebSiteName": "",
"LastEnvName": null,
"EnvPairList": [
{
"EnvName": "docker-ubuntu-20.04",
"ConfigName": "",
"LinuxEnvParam": null,
"DockerPort": null,
"DockerEnvName": null,
"DockerVolume": null,
"DockerOther": null
}
]
},
"WindowsServiveConfig": {
"ServiceName": "",
"SdkType": null,
"LastEnvName": null,
"EnvPairList": [
{
"EnvName": "docker-ubuntu-20.04",
"ConfigName": "",
"LinuxEnvParam": null,
"DockerPort": null,
"DockerEnvName": null,
"DockerVolume": null,
"DockerOther": null
}
]
},
"LinuxServiveConfig": {
"ServiceName": "",
"EnvParam": "",
"LastEnvName": null,
"EnvPairList": [
{
"EnvName": "docker-ubuntu-20.04",
"ConfigName": "",
"LinuxEnvParam": null,
"DockerPort": null,
"DockerEnvName": null,
"DockerVolume": null,
"DockerOther": null
}
]
},
"DockerConfig": {
"Prot": "",
"AspNetCoreEnv": "",
"LastEnvName": "docker-ubuntu-20.04",
"RemoveDaysFromPublished": "10",
"Volume": "",
"Other": "",
"EnvPairList": [
{
"EnvName": "docker-ubuntu-20.04",
"ConfigName": null,
"LinuxEnvParam": null,
"DockerPort": "",
"DockerEnvName": "",
"DockerVolume": "",
"DockerOther": ""
}
]
}
}
2.项目添加Dockerfile文件,vs2019 鼠标右键选择【添加】=》【Docker支持】选择Linux平台
本地vm事先下载好.net5相关的基础镜像,准备基础镜像信息如下:
修改默认创建的Dockerfile文件,并在vs 2019里面设置文件属性为【始终赋值】,此处如果不写Dockerfile文件,工具会默认生成一个;
此时基本环境都准好了,接下来我们使用AntDeploy工具离线版(V7.28)选择对应的项目.csproj文件,配置访问vm通信测试Ok,然后配置腾讯云Docker私有镜像仓库点击一键发布就完成了。
此处注意填写私有镜像仓库名称,这里吐槽一下腾讯云基本信息描述(表达意思误导人)
完整发布日志信息:发布工具版本AntDeploy-v7.29版本,构建镜像的Dcokerfile文件受注释影响,待后续优化;
16:24:39|INFO|The Porject ENTRYPOINT name:NetServices.Jwt.dll,DotNetSDK.Version:5.0
16:24:39|INFO|-----------------Start publish[Ver:7.29]-----------------
16:24:39|INFO|CurrentProjectFolder: file://G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt#link3
16:24:39|INFO|current project Path:G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\NetServices.Jwt.csproj
16:24:39|INFO|dotnet publish "G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\NetServices.Jwt.csproj" -c Release -o "G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\bin\Release\deploy_docker\docker-ubuntu-20.04\"
16:24:39|INFO|Copyright (C) Microsoft Corporation. All rights reserved.
16:24:40|INFO| Determining projects to restore...
16:24:40|INFO| Determining projects to restore...
16:24:42|INFO| All projects are up-to-date for restore.
16:24:42|INFO| All projects are up-to-date for restore.
16:24:43|INFO| NetServices.Helper.Cache -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.Cache\bin\Release\net5.0\NetServices.Helper.Cache.dll
16:24:43|INFO| NetServices.Helper.RabbitMQ -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.RabbitMQ\bin\Release\net5.0\NetServices.Helper.RabbitMQ.dll
16:24:43|INFO| NetServices.Helper.RabbitMQ -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.RabbitMQ\bin\Release\net5.0\NetServices.Helper.RabbitMQ.dll
16:24:43|INFO| NetServices.Helper.Base -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.Base\bin\Release\net5.0\NetServices.Helper.Base.dll
16:24:43|INFO| NetServices.Helper.Base -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.Base\bin\Release\net5.0\NetServices.Helper.Base.dll
16:24:43|INFO| NetServices.Helper.RestTemplate -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.RestTemplate\bin\Release\net5.0\NetServices.Helper.RestTemplate.dll
16:24:43|INFO| NetServices.Helper.RestTemplate -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.RestTemplate\bin\Release\net5.0\NetServices.Helper.RestTemplate.dll
16:24:44|INFO| NetServices.Helper.Database -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.Database\bin\Release\net5.0\NetServices.Helper.Database.dll
16:24:44|INFO| NetServices.Helper.Database -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.Database\bin\Release\net5.0\NetServices.Helper.Database.dll
16:24:44|INFO| NetServices.Helper.Log -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.Log\bin\Release\net5.0\NetServices.Helper.Log.dll
16:24:44|INFO| NetServices.Helper.Log -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Helper.Log\bin\Release\net5.0\NetServices.Helper.Log.dll
16:24:45|INFO| NetServices.Jwt -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\bin\Release\net5.0\NetServices.Jwt.dll
16:24:45|INFO| NetServices.Jwt -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\bin\Release\net5.0\NetServices.Jwt.dll
16:24:46|INFO| NetServices.Jwt -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\bin\Release\deploy_docker\docker-ubuntu-20.04\
16:24:46|INFO| NetServices.Jwt -> G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\bin\Release\deploy_docker\docker-ubuntu-20.04\
16:24:46|INFO|publish success ==> file://G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\bin\Release\deploy_docker\docker-ubuntu-20.04#link26
16:24:46|INFO|-----------------Start package-----------------
16:24:46|INFO|package ignoreList Count:0
16:24:46|INFO|Find Dockerfile In Package: Dockerfile
16:24:49|INFO|package success,package size:14M
16:24:49|INFO|-----------------Deploy Start-----------------
16:24:49|INFO|【Server】ssh connecting 172.27.94.126...
16:24:50|INFO|【Server】Connected to chait@172.27.94.126:22 via SSH
16:24:50|INFO|【Server】Changed directory to antdeploy/netservicesjwt/20201214162449/
16:24:50|INFO|【Server】uploaded 9 %
16:24:50|INFO|【Server】uploaded 21 %
16:24:50|INFO|【Server】uploaded 32 %
16:24:51|INFO|【Server】uploaded 44 %
16:24:51|INFO|【Server】uploaded 59 %
16:24:51|INFO|【Server】uploaded 71 %
16:24:51|INFO|【Server】uploaded 83 %
16:24:51|INFO|【Server】uploaded 94 %
16:24:51|INFO|【Server】uploaded 100 %
16:24:52|INFO|【Server】unzip -o -q antdeploy/netservicesjwt/20201214162449/publish.zip -d publish/
16:24:52|INFO|【Server】unzip success: antdeploy/netservicesjwt/20201214162449/publish/
16:24:52|INFO|【Server】Start Copy Files From [antdeploy/netservicesjwt/20201214162449/publish/] To [antdeploy/netservicesjwt/deploy/]
16:24:52|INFO|【Server】Success Copy Files From [antdeploy/netservicesjwt/20201214162449/publish/] To [antdeploy/netservicesjwt/deploy/]
16:24:52|INFO|【Server】Changed directory to antdeploy/netservicesjwt/deploy/
16:24:52|WARN|【Server】Volume in dockerFile is not defined
16:24:52|WARN|【Server】Docker Run Other Args in dockerFile is not defined
16:24:52|INFO|【Server】Add EXPOSE 5000 to dockerFile : 【antdeploy/netservicesjwt/deploy/Dockerfile】
16:24:52|INFO|【Server】Update DockerFile 【 \cp -rf antdeploy/netservicesjwt/deploy/Dockerfile antdeploy/netservicesjwt/20201214162449/publish/】
16:24:52|WARN|【Server】--name in Other Args is not defined
16:24:52|INFO|【Server】 docker build --no-cache --rm -t netservicesjwt:20201214162449 -f antdeploy/netservicesjwt/deploy/Dockerfile antdeploy/netservicesjwt/deploy/
16:24:53|INFO|【Server】Sending build context to Docker daemon 43.74MB
16:24:53|INFO|【Server】Step 1/6 : FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim
16:24:53|INFO|【Server】 ---> 1ad38cdee8b3
16:24:53|INFO|【Server】Step 2/6 : COPY . /publish
16:24:57|INFO|【Server】 ---> 89c1e9311f25
16:24:57|INFO|【Server】Step 3/6 : WORKDIR /publish
16:24:58|INFO|【Server】 ---> Running in ce10c33d6846
16:25:00|INFO|【Server】Removing intermediate container ce10c33d6846
16:25:00|INFO|【Server】 ---> ab9847d605e3
16:25:00|INFO|【Server】Step 4/6 : EXPOSE 8002
16:25:02|INFO|【Server】 ---> Running in e8411eb8a13e
16:25:03|INFO|【Server】Removing intermediate container e8411eb8a13e
16:25:03|INFO|【Server】 ---> c2e707157198
16:25:03|INFO|【Server】Step 5/6 : EXPOSE 5000
16:25:05|INFO|【Server】 ---> Running in 38a502ae6f0b
16:25:07|INFO|【Server】Removing intermediate container 38a502ae6f0b
16:25:07|INFO|【Server】 ---> ae6797201035
16:25:07|INFO|【Server】Step 6/6 : ENTRYPOINT ["dotnet", "NetServices.Jwt.dll"]
16:25:08|INFO|【Server】 ---> Running in b10cbf0cad95
16:25:10|INFO|【Server】Removing intermediate container b10cbf0cad95
16:25:10|INFO|【Server】 ---> 8eb53a301a0f
16:25:10|INFO|【Server】Successfully built 8eb53a301a0f
16:25:11|INFO|【Server】Successfully tagged netservicesjwt:20201214162449
16:25:11|WARN|【Server】ignore docker run
16:25:11|WARN|【Server】[upload image] - set -e; docker login -u [user] -p [pwd] ccr.ccs.tencentyun.com; docker tag 8eb53a301a0f ccr.ccs.tencentyun.com/sws-center-ol-service-dev/rg-sws-center-ol-dev-2069:jwt-v1.0.0; docker push ccr.ccs.tencentyun.com/sws-center-ol-service-dev/rg-sws-center-ol-dev-2069:jwt-v1.0.0
16:25:11|WARN|【Server】[upload image] - Login Succeeded
16:25:12|WARN|【Server】[upload image] - The push refers to repository [ccr.ccs.tencentyun.com/sws-center-ol-service-dev/rg-sws-center-ol-dev-2069]
16:25:12|WARN|【Server】[upload image] - 04b1dc15379b: Preparing
16:25:12|WARN|【Server】[upload image] - 064d1568f66a: Preparing
16:25:12|WARN|【Server】[upload image] - 8c8ce230525b: Preparing
16:25:12|WARN|【Server】[upload image] - ac1439b965df: Preparing
16:25:12|WARN|【Server】[upload image] - b22af9287e60: Preparing
16:25:12|WARN|【Server】[upload image] - f5600c6330da: Preparing
16:25:12|WARN|【Server】[upload image] - f5600c6330da: Waiting
16:25:12|WARN|【Server】[upload image] - 8c8ce230525b:
16:25:12|WARN|【Server】[upload image] - Layer already exists
16:25:12|WARN|【Server】[upload image] - 064d1568f66a:
16:25:12|WARN|【Server】[upload image] - Layer already exists
16:25:12|WARN|【Server】[upload image] - b22af9287e60:
16:25:12|WARN|【Server】[upload image] - Layer already exists
16:25:13|WARN|【Server】[upload image] - ac1439b965df:
16:25:13|WARN|【Server】[upload image] - Layer already exists
16:25:13|WARN|【Server】[upload image] - f5600c6330da:
16:25:13|WARN|【Server】[upload image] - Layer already exists
16:25:18|WARN|【Server】[upload image] - 04b1dc15379b:
16:25:18|WARN|【Server】[upload image] - Pushed
16:25:21|WARN|【Server】[upload image] - jwt-v1.0.0: digest: sha256:1c165fdc9dbd311692000812771e39c97397dee747001887b032ad127abe05c5 size: 1583
16:25:21|INFO|【Server】[upload image] - Success
16:25:21|INFO|publish Host: 172.27.94.126【docker】 End
16:25:21|INFO|Deploy Version:20201214162449
16:25:21|INFO|local publish folder ==> file://G:\SvnProject\HCIMS_V3.1_Online\Project\Services\SwsXytxMsServices\branches\v1.0\NetServices.Jwt\bin\Release\deploy_docker\docker-ubuntu-20.04#link105
16:25:21|INFO|-----------------Deploy End,[Total]:1,[Fail]:0-----------------
最后查看腾讯云平台私有镜像仓库,显示信息如下:
以上就是完整的发布构建镜像过程,有帮助到小伙伴的欢迎点赞分享,在这里也由衷感谢工具原创者不吝赐教的指点交流!