Browse Source

fix: deploy

李时威 9 months ago
parent
commit
58c91646ce

BIN
.DS_Store


+ 0 - 8
.idea/.gitignore

@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml

+ 0 - 22
.idea/deployment.xml

@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="PublishConfigData" autoUpload="Always" exclude=".svn;.cvs;.idea;.DS_Store;.git;.hg;*.hprof;*.pyc;test_imgs" remoteFilesAllowedToDisappearOnAutoupload="false">
-    <serverData>
-      <paths name="root@192.168.199.249:4868">
-        <serverdata>
-          <mappings>
-            <mapping deploy="/workspace" local="$PROJECT_DIR$" />
-          </mappings>
-        </serverdata>
-      </paths>
-      <paths name="root@192.168.199.249:4868 (2)">
-        <serverdata>
-          <mappings>
-            <mapping deploy="/workspace" local="$PROJECT_DIR$" />
-          </mappings>
-        </serverdata>
-      </paths>
-    </serverData>
-    <option name="myAutoUpload" value="ALWAYS" />
-  </component>
-</project>

+ 0 - 6
.idea/inspectionProfiles/profiles_settings.xml

@@ -1,6 +0,0 @@
-<component name="InspectionProjectProfileManager">
-  <settings>
-    <option name="USE_PROJECT_PROFILE" value="false" />
-    <version value="1.0" />
-  </settings>
-</component>

+ 0 - 4
.idea/misc.xml

@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (torch13)" project-jdk-type="Python SDK" />
-</project>

+ 0 - 8
.idea/modules.xml

@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ProjectModuleManager">
-    <modules>
-      <module fileurl="file://$PROJECT_DIR$/.idea/yl-ocr-layout.iml" filepath="$PROJECT_DIR$/.idea/yl-ocr-layout.iml" />
-    </modules>
-  </component>
-</project>

+ 0 - 6
.idea/vcs.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="VcsDirectoryMappings">
-    <mapping directory="$PROJECT_DIR$" vcs="Git" />
-  </component>
-</project>

+ 0 - 20
.idea/yl-ocr-layout.iml

@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="PYTHON_MODULE" version="4">
-  <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$" />
-    <orderEntry type="jdk" jdkName="Python 3.8 (torch13)" jdkType="Python SDK" />
-    <orderEntry type="sourceFolder" forTests="false" />
-  </component>
-  <component name="PyDocumentationSettings">
-    <option name="format" value="PLAIN" />
-    <option name="myDocStringFormat" value="Plain" />
-  </component>
-  <component name="TemplatesService">
-    <option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
-    <option name="TEMPLATE_FOLDERS">
-      <list>
-        <option value="$MODULE_DIR$/templates" />
-      </list>
-    </option>
-  </component>
-</module>

+ 117 - 0
deploy/Jenkinsfile

@@ -0,0 +1,117 @@
+pipeline {
+  agent {
+    kubernetes {
+      yamlFile 'deploy/KubernetesPod.yaml'
+      retries 2
+    }
+  }
+
+  environment {
+    IMAGE_REPO = "SXKJ:32775"
+    IMAGE_REPO_YILI = "registry.cn-hangzhou.aliyuncs.com/sxtest"
+    TAB = "\n   \n  "
+    GIT_LOG = sh (script: "git log --oneline -n 1", returnStdout: true).trim()
+    BUILD_USER_NAME = sh(script: "git log -1 --pretty=format:'%an'", returnStdout: true).trim()
+    TITLE = "${JOB_BASE_NAME}-${ENV_APP}"
+    GIT_BRANCH_NAME = env.GIT_BRANCH.substring(env.GIT_BRANCH.lastIndexOf('/') + 1)
+    TIMESTAMP = sh(returnStdout: true, script: "TZ=Asia/Shanghai date  +'%F_%H-%M-%S'").trim()
+    TAG = "${ENV_APP}-${GIT_BRANCH_NAME}-${TIMESTAMP}"
+  }
+  stages {
+    stage('git-log') {
+      steps {
+        script {
+            sh 'echo "git log"'
+            env.BUILD_TASKS = "\n   \n  "
+        }
+        sh 'printenv'
+       }
+    }
+    stage('构建镜像') {
+      steps {
+        container('docker') {
+          echo "构建 Docker 镜像阶段"
+          sh '''
+          if [ "$ENV_APP" == "yiliocr-yn" ]; then
+            docker build  -t ${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG} --output type=docker .
+          else
+            xxx
+          fi
+          '''
+          echo "build success"
+        }
+        script {
+          env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB
+        }
+      }
+    }
+    stage('镜像推送') {
+      steps {
+        container('docker') {
+          echo "Push Docker 镜像阶段"
+          sh '''
+          if [ "$ENV_APP" == "yiliocr-yn" ]; then
+            docker push ${IMAGE_REPO_YILI}/${JOB_BASE_NAME}:${TAG}
+          else
+            xxx
+          fi
+          '''
+          echo "Push image success"
+        }
+        script {
+          env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB
+        }
+      }
+    }
+    stage('重启服务') {
+      steps {
+        container('kubectl') {
+          sh '''
+          if [ "$ENV_APP" == "yiliocr-yn" ]; then
+            echo "$ENV_APP"
+          else
+            xxx
+          fi
+          '''
+        }
+        script {
+          env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB
+        }
+        sh 'printenv'
+      }
+    }
+  }
+  post {
+    success {
+        echo 'Congratulations!'
+        sh """
+            curl 'https://oapi.dingtalk.com/robot/send?access_token=19195ef5d3ce080a6966db554d03a348b56cd7c42707deebee51a353fdb2cc7d' \
+                -H 'Content-Type: application/json' \
+                -d '{
+                    "msgtype": "markdown",
+                    "markdown": {
+                        "title":"${TITLE}",
+                        "text": "😄👍 构建成功 👍😄  \n**项目名称**:${TITLE}  \n**Git log**: ${GIT_LOG}   \n**构建者**: ${BUILD_USER_NAME}  \n**构建分支**: ${GIT_BRANCH}   \n**构建地址**:${BUILD_URL}  \n**构建任务**: ${BUILD_TASKS}"
+                    }
+                }'
+        """
+    }
+    failure {
+        echo 'Oh no!'
+        sh """
+            curl 'https://oapi.dingtalk.com/robot/send?access_token=19195ef5d3ce080a6966db554d03a348b56cd7c42707deebee51a353fdb2cc7d' \
+                -H 'Content-Type: application/json' \
+                -d '{
+                    "msgtype": "markdown",
+                    "markdown": {
+                        "title":"${TITLE}",
+                        "text": "😖❌ 构建失败 ❌😖  \n**项目名称**:${TITLE}  \n**Git log**: ${GIT_LOG}   \n**构建者**: ${BUILD_USER_NAME}   \n**构建分支**: ${GIT_BRANCH}  \n**构建地址**:${BUILD_URL}  \n**构建任务**: ${BUILD_TASKS}"
+                    }
+                }'
+        """
+    }
+    always {
+        echo 'I will always say Hello again!'
+    }
+  }
+}

+ 183 - 0
deploy/Jenkinsfile.bk

@@ -0,0 +1,183 @@
+def label = "slave-${UUID.randomUUID().toString()}"
+
+
+podTemplate(cloud: 'kubernetes', namespace:'devops',label: label, serviceAccount: 'jenkins',containers: [
+  containerTemplate(name: 'docker', image: 'docker:latest', command: 'cat', ttyEnabled: true),
+  containerTemplate(name: 'kubectl', image: 'cnych/kubectl', command: 'cat', ttyEnabled: true)
+],volumes: [
+  hostPathVolume(mountPath: '/home/jenkins/.kube', hostPath: '/root/.kube'),
+  hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
+  hostPathVolume(mountPath: '/etc/docker/daemon.json', hostPath: '/etc/docker/daemon.json')
+], yaml: """
+spec:
+  nodeSelector:
+    kubernetes.io/hostname: h249
+  hostalias:
+  - ip: 192.168.199.31
+    hostnames:
+    - "SXKJ"
+"""
+) {
+
+    node(label) {
+        stage('构建 Docker 镜像') {
+          git url: ' http://gogs.soaringnova.com/sxwl_DL/meta_be.git', branch: 'master'
+          container('docker') {
+            echo "构建 Docker 镜像阶段"
+            retry(2) { sh "docker build  -t SXKJ:32775/meta-app:latest --output type=docker ." }
+            echo "build success"
+          }
+        }
+        stage('Docker Push 镜像') {
+            container('docker') {
+              retry(2) { sh "docker push SXKJ:32775/meta-app:latest" }
+              echo "Push success"
+            }
+        }
+        stage('运行 Kubectl') {
+          container('kubectl') {
+            echo "重启 pod"
+            sh "kubectl rollout restart deployments/app-be  -n meta-demo"
+          }
+        }
+    }
+}
+
+
+//
+// pipeline {
+//     agent { label 'jnlp-slave'}
+//
+//     options {
+//         buildDiscarder(logRotator(numToKeepStr: '10'))
+//         disableConcurrentBuilds()
+//         timeout(time: 20, unit: 'MINUTES')
+//         gitLabConnection('gitlab')
+//     }
+//
+//     environment {
+//         IMAGE_REPO = "112.29.146.236:5000/demo/myblog"
+//         DINGTALK_CREDS = credentials('dingTalk')
+//         TAB_STR = "\n                    \n                    "
+//     }
+//
+//     stages {
+//         stage('git-log') {
+//             steps {
+//                 script{
+//                     sh "git log --oneline -n 1 > gitlog.file"
+//                     env.GIT_LOG = readFile("gitlog.file").trim()
+//                 }
+//                 sh 'printenv'
+//             }
+//         }
+//         stage('checkout') {
+//             steps {
+//                 container('tools') {
+//                     checkout scm
+//                 }
+//                 updateGitlabCommitStatus(name: env.STAGE_NAME, state: 'success')
+//                 script{
+//                     env.BUILD_TASKS = env.STAGE_NAME + "√..." + env.TAB_STR
+//                 }
+//             }
+//         }
+//         stage('CI'){
+//             failFast true
+//             parallel {
+//                 stage('Unit Test') {
+//                     steps {
+//                         echo "Unit Test Stage Skip..."
+//                     }
+//                 }
+//                 stage('Code Scan') {
+//                     steps {
+//                         container('tools') {
+//                             withSonarQubeEnv('sonarqube') {
+//                                 sh 'sonar-scanner -X'
+//                                 sleep 3
+//                             }
+//                             script {
+//                                 timeout(1) {
+//                                     def qg = waitForQualityGate('sonarqube')
+//                                     if (qg.status != 'OK') {
+//                                         error "未通过Sonarqube的代码质量阈检查,请及时修改!failure: ${qg.status}"
+//                                     }
+//                                 }
+//                             }
+//                         }
+//                     }
+//                 }
+//             }
+//         }
+//         stage('build-image') {
+//             steps {
+//                 container('tools') {
+//                     retry(2) { sh 'docker build . -t ${IMAGE_REPO}:${GIT_COMMIT}'}
+//                 }
+//                 updateGitlabCommitStatus(name: env.STAGE_NAME, state: 'success')
+//                 script{
+//                     env.BUILD_TASKS += env.STAGE_NAME + "√..." + env.TAB_STR
+//                 }
+//             }
+//         }
+//         stage('push-image') {
+//             steps {
+//                 container('tools') {
+//                     retry(2) { sh 'docker push ${IMAGE_REPO}:${GIT_COMMIT}'}
+//                 }
+//                 updateGitlabCommitStatus(name: env.STAGE_NAME, state: 'success')
+//                 script{
+//                     env.BUILD_TASKS += env.STAGE_NAME + "√..." + env.TAB_STR
+//                 }
+//             }
+//         }
+//         stage('deploy') {
+//             steps {
+//                 container('tools') {
+//                     sh "sed -i 's#{{IMAGE_URL}}#${IMAGE_REPO}:${GIT_COMMIT}#g' deploy/*"
+//                     timeout(time: 1, unit: 'MINUTES') {
+//                         sh "kubectl apply -f deploy/"
+//                     }
+//                 }
+//                 updateGitlabCommitStatus(name: env.STAGE_NAME, state: 'success')
+//                 script{
+//                     env.BUILD_TASKS += env.STAGE_NAME + "√..." + env.TAB_STR
+//                 }
+//             }
+//         }
+//     }
+//     post {
+//         success {
+//             echo 'Congratulations!'
+//             sh """
+//                 curl 'https://oapi.dingtalk.com/robot/send?access_token=${DINGTALK_CREDS_PSW}' \
+//                     -H 'Content-Type: application/json' \
+//                     -d '{
+//                         "msgtype": "markdown",
+//                         "markdown": {
+//                             "title":"myblog",
+//                             "text": "😄👍 构建成功 👍😄  \n**项目名称**:jairmir  \n**Git log**: ${GIT_LOG}   \n**构建分支**: ${BRANCH_NAME}   \n**构建地址**:${RUN_DISPLAY_URL}  \n**构建任务**:${BUILD_TASKS}"
+//                         }
+//                     }'
+//             """
+//         }
+//         failure {
+//             echo 'Oh no!'
+//             sh """
+//                 curl 'https://oapi.dingtalk.com/robot/send?access_token=${DINGTALK_CREDS_PSW}' \
+//                     -H 'Content-Type: application/json' \
+//                     -d '{
+//                         "msgtype": "markdown",
+//                         "markdown": {
+//                             "title":"myblog",
+//                             "text": "😖❌ 构建失败 ❌😖  \n**项目名称**:jairmir  \n**Git log**: ${GIT_LOG}   \n**构建分支**: ${BRANCH_NAME}  \n**构建地址**:${RUN_DISPLAY_URL}  \n**构建任务**:${BUILD_TASKS}"
+//                         }
+//                     }'
+//             """
+//         }
+//         always {
+//             echo 'I will always say Hello again!'
+//         }
+//     }
+// }

+ 45 - 0
deploy/KubernetesPod.yaml

@@ -0,0 +1,45 @@
+apiVersion: v1
+kind: Pod
+metadata:
+  labels:
+    meta-be: meta-be
+spec:
+  containers:
+  - name: docker
+    image: docker:latest
+    command:
+    - cat
+    tty: true
+    volumeMounts:
+    - mountPath: "/etc/docker/daemon.json"
+      name: "volume-docker1"
+    - mountPath: "/root/.docker/config.json"
+      name: "docker-auth"
+    - mountPath: "/var/run/docker.sock"
+      name: "volume-docker0"
+  - name: helm
+    image: alpine/helm:3.11.1
+    command:
+    - cat
+    tty: true
+  - name: kubectl
+    image: cnych/kubectl
+    command:
+    - cat
+    tty: true
+  volumes:
+   - name: volume-docker0
+     hostPath:
+       path: "/var/run/docker.sock"
+   - name: docker-auth
+     hostPath:
+       path: "/root/.docker/config.json"
+   - name: volume-docker1
+     hostPath:
+       path: "/etc/docker/daemon.json"
+  nodeSelector:
+    kubernetes.io/hostname: h107
+  hostAliases:
+  - ip: 192.168.199.31
+    hostnames:
+    - "sxkj"

File diff suppressed because it is too large
+ 18 - 0
kubeconfig-sxkj


File diff suppressed because it is too large
+ 18 - 0
kubeconfig-sxkjprod


Some files were not shown because too many files changed in this diff