Browse Source

添加构建脚本

mayan31370 2 years ago
parent
commit
ba6fc53c39
3 changed files with 111 additions and 0 deletions
  1. 5 0
      Dockerfile
  2. 78 0
      Jenkinsfile
  3. 28 0
      nginx.conf

+ 5 - 0
Dockerfile

@@ -0,0 +1,5 @@
+FROM nginx:latest
+
+ADD dist/ /usr/share/nginx/html
+
+ADD nginx.conf /etc/nginx/nginx.conf

+ 78 - 0
Jenkinsfile

@@ -0,0 +1,78 @@
+pipeline {
+  agent any
+  options {
+    skipDefaultCheckout true
+  }
+  stages {
+    stage('checkout') {
+      steps {
+        checkout scm
+      }
+    }
+    stage('npm install') {
+      steps {
+        script {
+          sh "docker run -i --rm -v ${env.WORKSPACE}:/usr/src/workspace -w /usr/src/workspace mayan31370/docker-image-nodejs:14 cnpm install"
+        }
+      }
+    }
+    stage('npm build') {
+      steps {
+        script {
+          sh "docker run -i --rm -v ${env.WORKSPACE}:/usr/src/workspace -w /usr/src/workspace mayan31370/docker-image-nodejs:14 cnpm run build:h5"
+        }
+      }
+    }
+    stage('build docker image') {
+      steps {
+        script {
+          sh "aws ecr get-login-password --region cn-north-1 | docker login --username AWS --password-stdin 226381024927.dkr.ecr.cn-north-1.amazonaws.com.cn"
+          sh "docker build -t aibaidu/arrive-h5 ."
+        }
+      }
+    }
+    stage('push docker image') {
+      steps {
+        script {
+          sh "docker tag aibaidu/h5:latest 226381024927.dkr.ecr.cn-north-1.amazonaws.com.cn/aibaidu/arrive-h5:latest"
+          sh "docker push 226381024927.dkr.ecr.cn-north-1.amazonaws.com.cn/aibaidu/arrive-h5:latest"
+        }
+      }
+    }
+    // stage('deploy') {
+    //   steps {
+    //     script {
+    //       sh "ssh -o StrictHostKeyChecking=no aibaidu-admin './deploy-h5.sh'"
+    //     }
+    //   }
+    // }
+    
+        stage('Send notify'){
+            steps{
+                script{
+                    def content = "### 公众号H5\n<font color='info'>部署完成</font>" + getChangeString()
+                    sh "curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=743fe5f4-d4cf-4906-8aa5-93353a4287da' -H 'Content-Type: application/json' -d '{\"msgtype\": \"markdown\",\"markdown\": {\"content\": \"${content}\",\"mentioned_list\":[\"@all\"]}}'"
+                }
+            }
+        }
+    }
+}
+@NonCPS
+def getChangeString() {
+    MAX_MSG_LEN = 100
+    def changeString = ""
+    echo "Gathering SCM changes"
+    def changeLogSets = currentBuild.changeSets
+    for (int i = 0; i < changeLogSets.size(); i++) {
+        def entries = changeLogSets[i].items
+        for (int j = 0; j < entries.length; j++) {
+            def entry = entries[j]
+            truncated_msg = entry.msg.take(MAX_MSG_LEN)
+            changeString += " - ${truncated_msg} [${entry.author}]\n"
+        }
+    }
+    if (!changeString) {
+        changeString = " - No new changes"
+    }
+    return changeString
+}

+ 28 - 0
nginx.conf

@@ -0,0 +1,28 @@
+worker_processes  auto;
+worker_cpu_affinity auto;
+
+events {
+    worker_connections  8096;
+}
+
+http {
+
+	include       mime.types;
+    default_type  application/octet-stream;
+
+
+    server {
+        listen  80;
+        charset utf-8;
+        server_name_in_redirect off;
+        gzip on;
+        gzip_buffers 4 16k;
+        gzip_comp_level 6;
+        gzip_vary on;
+        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
+        location / {
+            try_files $uri $uri/ /index.html;
+            root   /usr/share/nginx/html;
+        }
+    }
+}