Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/master'

liweiquan 10 mēneši atpakaļ
vecāks
revīzija
5b7399e230
6 mainītis faili ar 388 papildinājumiem un 25 dzēšanām
  1. 28 25
      Dockerfile
  2. 96 0
      deploy/Jenkinsfile
  3. 183 0
      deploy/Jenkinsfile.bk
  4. 45 0
      deploy/KubernetesPod.yaml
  5. 18 0
      kubeconfig-sxkj
  6. 18 0
      kubeconfig-sxkjprod

+ 28 - 25
Dockerfile

@@ -1,3 +1,5 @@
+FROM condaforge/mambaforge:latest AS builder0
+
 FROM nvidia/cuda:11.0-cudnn8-devel-ubuntu18.04 AS builder
 
 RUN sed -i 's#archive.ubuntu.com#mirrors.aliyun.com#g' /etc/apt/sources.list  \
@@ -40,40 +42,42 @@ CMD ["supervisord", "-n"]
 
 FROM builder as builder1
 
-ENV PYTHON_VERSION 3
-RUN chsh -s `which zsh`
-RUN curl -o ~/miniconda.sh -O  https://repo.anaconda.com/miniconda/Miniconda${PYTHON_VERSION}-latest-Linux-x86_64.sh  && \
-    chmod +x ~/miniconda.sh && \
-    ~/miniconda.sh -b -p /opt/conda && \
-    rm ~/miniconda.sh
+# ENV PYTHON_VERSION 3
+# RUN chsh -s `which zsh`
+# RUN curl -o ~/miniconda.sh -O  https://repo.anaconda.com/miniconda/Miniconda${PYTHON_VERSION}-latest-Linux-x86_64.sh  && \
+#     chmod +x ~/miniconda.sh && \
+#     ~/miniconda.sh -b -p /opt/conda && \
+#     rm ~/miniconda.sh
+
+COPY --from=builder0 /opt/conda /opt/conda
 
 RUN ln /opt/conda/bin/conda /usr/local/bin/conda
 RUN conda init zsh
-RUN conda install mamba -n base -c conda-forge
+# RUN conda install 'mamba<=1.4.5' -n base -c conda-forge
 RUN ln /opt/conda/bin/mamba /usr/local/bin/mamba && mamba init zsh
 
 
 
 FROM builder1 as builder2
 
-RUN apt-get update && apt-get install -y --no-install-recommends openssh-server && rm -rf /var/lib/apt/lists/*
-RUN mkdir /var/run/sshd
-RUN echo 'root:root' | chpasswd
-RUN sed -i 's/.*PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
-# SSH login fix. Otherwise user is kicked off after login
-RUN sed -i 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd
+# RUN apt-get update && apt-get install -y --no-install-recommends openssh-server && rm -rf /var/lib/apt/lists/*
+# RUN mkdir /var/run/sshd
+# RUN echo 'root:root' | chpasswd
+# RUN sed -i 's/.*PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
+# # SSH login fix. Otherwise user is kicked off after login
+# RUN sed -i 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd
 
-RUN echo "\
-[program:sshd] \n\
-command=/usr/sbin/sshd -D\n\
-autorestart=True\n\
-autostart=True\n\
-redirect_stderr = true\n\
-" > /etc/supervisor/conf.d/sshd.conf
+# RUN echo "\
+# [program:sshd] \n\
+# command=/usr/sbin/sshd -D\n\
+# autorestart=True\n\
+# autostart=True\n\
+# redirect_stderr = true\n\
+# " > /etc/supervisor/conf.d/sshd.conf
 
-EXPOSE 22
+# EXPOSE 22
 
-FROM builder2 as builder3
+# FROM builder2 as builder3
 
 WORKDIR /workspace
 ADD environment.yml /environment.yml
@@ -90,13 +94,12 @@ autorestart=true\n\
 startretries=0\n\
 redirect_stderr=true\n\
 stdout_logfile=/var/log/be.log\n\
-stdout_logfile_maxbytes=0\n\
+stdout_logfile_maxbytes=50MB\n\
 " > /etc/supervisor/conf.d/be.conf
 RUN cd / && wget ftp://192.168.199.31/table-paddleclas.tgz && tar xvf table-paddleclas.tgz
 RUN cd / && wget ftp://192.168.199.31/table-paddleocr.tgz && tar xvf table-paddleocr.tgz
 
-ARG VERSION
-ENV USE_CUDA $VERSION
+
 Add . /workspace
 EXPOSE 8080
 

+ 96 - 0
deploy/Jenkinsfile

@@ -0,0 +1,96 @@
+pipeline {
+  agent {
+    kubernetes {
+      yamlFile 'deploy/KubernetesPod.yaml'
+      retries 2
+    }
+  }
+
+  environment {
+    IMAGE_REPO = "SXKJ:32775"
+    TAB = "\n   \n  "
+    GIT_LOG = sh (script: "git log --oneline -n 1", returnStdout: true).trim()
+    TITLE = "${JOB_BASE_NAME}-${ENV_APP}"
+    TIMESTAMP = sh(returnStdout: true, script: "TZ=Asia/Shanghai date  +'%F_%H-%M-%S'").trim()
+    TAG = "${ENV_APP}-${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 'docker build  -t ${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG} --output type=docker .'
+          echo "build success"
+        }
+        script {
+          env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB
+        }
+      }
+    }
+    stage('镜像推送') {
+      steps {
+        container('docker') {
+          echo "Push Docker 镜像阶段"
+          sh 'docker push ${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG}'
+          echo "Push image success"
+        }
+        script {
+          env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB
+        }
+      }
+    }
+    stage('重启服务') {
+      steps {
+        container('kubectl') {
+          sh '[[ "$ENV_APP" == "test" ]] && kubectl set image deployment/ocr-table table=${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG} --namespace yili-ocr --kubeconfig kubeconfig-sxkj ||  kubectl set image deployment/ocr-table table=${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG} --namespace yili-ocr  --kubeconfig kubeconfig-sxkjprod'
+        }
+        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**构建分支**: ${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**构建分支**: ${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"

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 18 - 0
kubeconfig-sxkj


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 18 - 0
kubeconfig-sxkjprod


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels