<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                **1. 編寫`Jenkinsfile`文件** 一個微服務工程只需要一個`Jenkinsfile`文件。 ![](https://img.kancloud.cn/76/ee/76ee2aa3488a1e153b50ac79638453bd_1281x386.jpg) ```groovy //gitlab憑證ID def git_auth = "e4e02eb6-f6bb-4040-b842-c1423c397493" //gitlab的url地址 def git_url = "git@gitlab.master.com:itheima_group/tensquare-parent.git" //鏡像的版本號 def tag = "latest" //Harbor的url地址 def harbor_url = "reg.myharbor.com:85" //harbor鏡像庫項目名稱 def harbor_project_name = "tensquare" //Harbor的登錄憑證ID def harbor_auth = "0d458918-e2ea-4b51-8250-91c3731be288" node { stage('拉取代碼') { checkout([$class : 'GitSCM', branches: [[name: '*/${branch}']] , doGenerateSubmoduleConfigurations: false , extensions : [] , submoduleCfg : [] , userRemoteConfigs : [ [credentialsId: "${git_auth}", url: "${git_url}"] ]]) } stage('代碼審查') { //定義當前Jenkins的SonarQubeScanner工具 def scannerHome = tool 'sonarqube-scanner' //引用當前JenkinsSonarQube環境 withSonarQubeEnv('sonarqube-8.9.6.50800') { sh """ cd ${project_name} ${scannerHome}/bin/sonar-scanner """ } } stage('編譯/構建鏡像') { //定義鏡像名稱 def imageName = "${project_name}:${tag}" //編譯,安裝公共工程 sh "mvn -f tensquare-common clean install" //編譯,構建本地鏡像 sh "mvn -f ${project_name} clean package dockerfile:build" //給鏡像打標簽 sh "docker tag ${imageName} ${harbor_url}/${harbor_project_name}/${imageName}" //登錄harbor并上傳鏡像 withCredentials([ usernamePassword(credentialsId: "${harbor_auth}" , passwordVariable: 'password' , usernameVariable: 'username')]) { //登錄Harbor sh "docker login -u ${username} -p ${password} ${harbor_url}" //推送鏡像到Harbor sh "docker push ${harbor_url}/${harbor_project_name}/${imageName}" } //上傳完成后刪除本地鏡像 sh "docker rmi -f ${imageName}" sh "docker rmi -f ${harbor_url}/${harbor_project_name}/${imageName}" } stage('部署服務') { sshPublisher( publishers: [ sshPublisherDesc( configName: 'production-server' , transfers: [ sshTransfer( cleanRemote: false , excludes: '' , execCommand: "/opt/jenkins_shell/tensquare/deploy.sh $harbor_url $harbor_project_name $project_name $tag $port" , execTimeout: 120000 , flatten: false , makeEmptyDirs: false , noDefaultExcludes: false , patternSeparator: '[, ]+' , remoteDirectory: '' , remoteDirectorySDF: false , removePrefix: '' , sourceFiles: '' )] , usePromotionTimestamp: false , useWorkspaceInPromotion: false , verbose: false) ]) } } ``` **2. 在部署服務器 production-server 機器上編寫部署腳本** (1)`/opt/jenkins_shell/tensquare/deploy.sh`。 ```shell #!/bin/sh #接收外部參數 harbor_url=$1 harbor_project_name=$2 project_name=$3 tag=$4 port=$5 imageName=$harbor_url/$harbor_project_name/$project_name:$tag echo "$imageName" #查詢容器是否存在,存在則刪除 containerId=`docker ps -a | grep -w ${project_name}:${tag} | awk '{print $1}'` if [ "$containerId" != "" ] ; then #停掉容器 docker stop $containerId #刪除容器 docker rm $containerId echo "成功刪除容器" fi #查詢鏡像是否存在,存在則刪除 imageId=`docker images | grep -w $project_name | awk '{print $3}'` if [ "$imageId" != "" ] ; then #刪除鏡像 docker rmi -f $imageId echo "成功刪除鏡像"JAR_FILE fi # 登錄Harbor私服 docker login -u harborZhangsan -p harborZhang3 $harbor_url # 下載鏡像 docker pull $imageName # 啟動容器 docker run -di -p $port:$port $imageName echo "容器啟動成功" ``` (2)給該腳本執行權限。 ```shell chmod +x deploy.sh ``` **3.為每個微服務項目編寫各自的`sonar-project.properties`文件** 下面是微服務項目 tensquare-eureka-server 的一個例子,記得到Harbor上創建對應的項目哦。 ```properties # must be unique in a given SonarQube instance sonar.projectKey=tensquare-eureka-server # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=tensquare-eureka-server sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # This property is optional if sonar.modules is set. sonar.sources=. sonar.exclusions=**/test/**,**/target/** sonar.java.binaries=. sonar.java.source=1.8 sonar.java.target=1.8 #sonar.java.libraries=**/target/classes/** # Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8 ``` **4.為每個微服務項目編寫各自的`Dockerfile`文件** (1)每個微服務項目的`pom.xml`添加如下插件。 ```xml <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.3.6</version> <configuration> <repository>${project.artifactId}</repository> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin> </plugins> </build> ``` (2)tensquare-eureka-server 微服務的`Dockerfile`文件示例。 ```properties #FROM java:8 FROM openjdk:8-jdk-alpine ARG JAR_FILE COPY ${JAR_FILE} app.jar EXPOSE 10086 --注意每個微服務項目的端口都不一樣 ENTRYPOINT ["java","-jar","/app.jar"] ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看