Jenkins releases Net Core project

Package release of Net Core project


One: The following is the Net Core project packaging process. Select the project-"Right click-"Release


2: Upload the packaged project to the Linux system

Path: /home/wwwroot/WXOAuth/publish
Create a Dockerfile under the path /home/wwwroot/WXOAuth/.
Write the Dockerfilefile as follows:


vim Dockerfile

edit

FROM microsoft/dotnet:latest
WORKDIR /root
# Copy the app file to root 
COPY publish /root/
# Configure the listening port to 80 端口
EXPOSE 80/tcp
# Start the app 宿主名称 SMSService
ENTRYPOINT ["dotnet", "OutsideInter.dll"]
#设置容器的时区
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone


Three: jenkins releases Net Core

1: Create a jenkins project. Home-》New Project

2: Setting project-"Configuration:

3: Build the image, select when building-"Execute Shell

Edit script

#!/bin/bash
# 获取短版本号
echo '构建开始'

# variables
echo 'variables:变量'
Tag=latest
IMGNAME=wxoauth
CONTAINER=wxoauth
PublishPath=/home/wwwroot/WXOAuth
Port=6060
# publish
echo 'publish:发布' 
dotnet --version
# Dockerfile拷贝
echo 'Dockerfile拷贝'
cp -rf $PublishPath/publish/Dockerfile $PublishPath
cd $PublishPath && ls 
#docker rmi -f $IMGNAME
# image
echo 'image:镜像'
cd $PublishPath && docker build -t $IMGNAME:latest .

# container
#echo 'container:容器-本机布署'
#docker stop $CONTAINER || true && docker rm -f $CONTAINER || true
#docker run -d -p $Port:80 --name $CONTAINER $IMGNAME:$Tag 

echo '清理镜像'
docker rmi -f $(docker images -q -f dangling=true)

echo 'Tag并push镜像'
docker tag $IMGNAME 172.16.2.16:5002/$IMGNAME
docker push 172.16.2.16:5002/$IMGNAME

echo '构建结束'

Description: PublishPath: This is the path variable IMGNAME for uploading code: Mirror name variable Port: Port number variable 4: Post-build operation selection-"send build artifacts over SSH

Four: Post-build operation

Edit script

#!/bin/bash
Exec exit status not zero echo'Other
machine deployment started'
CONTAINER=wxoauth
ImageTag=172.16.2.16:5002/wxoauth
Port=8025
Port1=6060 echo'Image pull
'
docker pull $ImageTag echo'Container
start '
docker stop $CONTAINER || true && docker rm -f $CONTAINER || true
docker run -d -p $Port1:$Port --name $CONTAINER --restart=always -v /home/logs/WXOAuth:/home /Log/DNSJOutside $ImageTag 
docker rmi -f $(docker images -q -f dangling=true) echo'deployment of
other machines finished'

Note: 1. The new option of name selection in SSH Server: homepage jinkins-"system management-"system settings as shown in the figure below:

Two: Configure the port number: The
default host in core is: Kestrel, and the Kestrel startup in docker needs to be consistent with the configuration port number in the project's Program code

 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseKestrel()
                .UseUrls("http://*:8025/", "http://*:80/") // in Listening port on all network interfaces.
                UseStartup<Startup>();
    }

Therefore, you can only set 8025 or 80 when setting the port number of the docker container.
Three: log path, you need to set the physical machine log path, which is mapped to the log path of the virtual machine
-v /home/logs/WXOAuth:/home/Log/DNSJOutside

Four: It should be noted that if the mirror address is not on the same server as the installation server. You need to log in to the private server account password of the docker image first. Otherwise, docker will report an error when pulling images.

 

 

Guess you like

Origin blog.csdn.net/xulong5000/article/details/114370217