root 3 жил өмнө
parent
commit
822080b6b7
12 өөрчлөгдсөн 1401 нэмэгдсэн , 0 устгасан
  1. 30 0
      Dockerfile
  2. 193 0
      cluster-default.xml
  3. 9 0
      configmap.json
  4. 91 0
      deploy-tmp-v2.yaml
  5. 91 0
      deploy-tmp.yaml
  6. 14 0
      entrypoint.sh
  7. 233 0
      ppctl.py
  8. 1 0
      release
  9. 273 0
      resin.conf
  10. 175 0
      resin.properties
  11. 30 0
      supervisord.conf
  12. 261 0
      tools.py

+ 30 - 0
Dockerfile

@@ -0,0 +1,30 @@
+FROM hub.evbj.easou.com/dev/centos:7.6
+MAINTAINER robert[robert_du@easou.cn]
+
+ENV LANG C.UTF-8
+ENV TZ=Asia/Shanghai
+ENV JAVA_HOME /usr/java/jdk1.8.0_101
+
+#install jdk8 & resin4 & flume
+RUN yum install -y wget rsync epel-release \
+    && useradd book \
+    && yum install -y supervisor \
+    && mkdir -p /usr/java  /app/soft \
+    && curl -O http://10.26.22.185:9000/psop/soft/jdk-8u101-linux-x64.tar.gz \
+    && curl -O http://10.26.22.185:9000/psop/soft/resin-pro-3.1.6.tar.gz \
+    && tar -zxf jdk-8u101-linux-x64.tar.gz -C /usr/java/ \ 
+    && tar -zxf resin-pro-3.1.6.tar.gz -C /app/soft/ \
+    && rm -f jdk-8u101-linux-x64.tar.gz resin-pro-3.1.6.tar.gz \
+    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone 
+
+COPY resin.conf /app/soft/resin-pro-3.1.6/conf/resin.conf
+COPY entrypoint.sh /usr/bin/entrypoint.sh
+COPY release /etc/release 
+COPY supervisord.conf /etc/supervisord.conf
+
+RUN export RELEASE=`head -n 1 /etc/release` \
+    && rsync -avz $RELEASE/ROOT.war /tmp/ROOT.war
+
+#start resin
+ENTRYPOINT ["entrypoint.sh"]
+CMD ["supervisord"]

+ 193 - 0
cluster-default.xml

@@ -0,0 +1,193 @@
+<resin xmlns="http://caucho.com/ns/resin"
+       xmlns:resin="urn:java:com.caucho.resin">
+
+  <!--
+     - default configuration applied to all clusters
+    -->
+  <cluster-default>
+    <!-- shared webapp jars for non-classloader-aware libraries -->
+    <web-app-default>
+      <class-loader>
+        <library-loader path="${resin.root}/webapp-jars"/>
+        <library-loader path="${resin.root}/webapp.d/lib"/>
+        <library-loader path="config:/webapp.d/lib"/>
+      </class-loader>
+    </web-app-default>
+
+    <!-- shared jars and drivers for the app-tier -->
+    <class-loader>
+      <tree-loader path="${resin.root}/${cluster.id}-inf"/>
+    </class-loader>
+
+    <!-- enables development error pages -->
+    <resin:if test="${dev_mode}">
+      <development-mode-error-page/>
+    </resin:if>
+
+    <!--
+       - Enables the proxy cache (available in Resin Professional) 
+      -->
+    <resin:if test="${proxy_cache_enable}">
+      <proxy-cache memory-size="${proxy_cache_size}">
+       <!-- Vary header rewriting for IE -->
+        <rewrite-vary-as-private/>
+      </proxy-cache>
+    </resin:if>
+    
+    <!--
+       - Admin services
+      -->
+
+    <resin:if test="${remote_admin_enable}">
+      <resin:RemoteAdminService/>
+    </resin:if>
+    
+    <resin:AdminServices/>
+
+    <resin:if test="${elastic_cloud_enable}">
+      <resin:ElasticCloudService/>
+    </resin:if>
+
+    <!-- defaults for each server, i.e. JVM -->
+    <server-default>
+      <jvm-arg-line>${jvm_args}</jvm-arg-line>
+      <jvm-mode>${jvm_mode}</jvm-mode>
+
+      <!--
+         - If starting Resin as root on Unix, specify the user name
+         - and group name for the web server user.
+       -->
+      <user-name>${setuid_user}</user-name>
+      <group-name>${setuid_group}</group-name>
+
+      <port-default>
+        <port-thread-max>${port_thread_max}</port-thread-max>
+        <accept-thread-min>${accept_thread_min}</accept-thread-min>
+        <accept-thread-max>${accept_thread_max}</accept-thread-max>
+        <keepalive-max>${keepalive_max?:-1}</keepalive-max>
+
+        <tcp-cork>${tcp_cork}</tcp-cork>
+      </port-default>
+
+      <sendfile-enable>${sendfile}</sendfile-enable>
+
+      <keepalive-select-enable>${keepalive_select_enable}</keepalive-select-enable>
+
+      <!-- The http port -->
+      <http address="${http_address?:'*'}" port="${http}"/>
+
+      <!-- SSL port configuration: -->
+      <resin:choose>
+      <resin:when test="${openssl_file != null}">
+        <http address="${http_address?:'*'}" port="${https}">
+          <openssl>
+            <certificate-file>${file_lookup(openssl_file,__DIR__)}</certificate-file>
+            <certificate-key-file>${file_lookup(openssl_key, __DIR__)}</certificate-key-file>
+            <password>
+              <resin:Password>${openssl_password}</resin:Password>
+            </password>
+          </openssl>
+        </http>
+      </resin:when>
+      <resin:when test="${jsse_keystore_file != null}">
+        <http address="${http_address?:'*'}" port="${https}">
+          <jsse-ssl>
+            <key-store-type>${jsse_keystore_type?:'jks'}</key-store-type>
+            <key-store-file>${jsse_keystore_file}</key-store-file>
+            <password>
+              <resin:Password>${jsse_keystore_password}</resin:Password>
+            </password>
+          </jsse-ssl>
+        </http>
+      </resin:when>
+      <resin:when test="${class_exists('sun.security.x509.CertAndKeyGen') || class_exists('sun.security.tools.keytool.CertAndKeyGen')}">
+        <http address="${http_address?:'*'}" port="${https}">
+          <jsse-ssl self-signed-certificate-name="resin@localhost"/>
+        </http>
+      </resin:when>
+      </resin:choose>
+    </server-default>
+
+    <!--
+       - Default host configuration applied to all virtual hosts.
+      -->
+    <host-default>
+      <access-log path="/data/log/other/access.log" 
+                 format='v2{]b.easou.com{]%r{]%{uid_bi}c{]%{%Y%m%d %H%M%S%s}t{]%s{]-{]%D{]%b{]%b{]%{X-Real-IP}i{]%{X-Forwarded-For}i{]%{Referer}i{]-{]%{User-Agent}i{]online_ta{]%{uid_bi}c{]-{]%{uid}c{]%{cid}c{]{]v2'
+                 rollover-period="1h"/>
+
+      <!--
+         - Defaults applied to each web-app.
+        -->
+      <web-app-default>
+        <prologue>
+          <allow-servlet-el/>
+        </prologue>
+     
+        <!--
+           - Sets max-age for cacheable pages, e.g. static pages.
+          -->
+        <cache-mapping url-pattern="/" max-age="5s"/>
+        <cache-mapping url-pattern="*.gif" max-age="60s"/>
+        <cache-mapping url-pattern="*.jpg" max-age="60s"/>
+        <cache-mapping url-pattern="*.png" max-age="60s"/>
+        <cache-mapping url-pattern="*.css" max-age="60s"/>
+        <cache-mapping url-pattern="*.js" max-age="60s"/>
+
+        <session-config>
+          <use-persistent-store>${session_store}</use-persistent-store>
+          
+          <enable-url-rewriting>false</enable-url-rewriting>
+        </session-config>
+      </web-app-default>
+    </host-default>
+
+    <!--
+    <host id="${web_admin_host}" root-directory="${web_admin_host}">
+      -->
+    <host-default>
+      
+      <!--
+         - Administration application /resin-admin
+        -->
+      <resin:if test="${web_admin_enable}">
+        <web-app id="/resin-admin" root-directory="${resin.root}/doc/admin">
+          <prologue>
+            <!-- only allow access from internal IP (10.*,192.168.*,127.*) -->
+            <resin:set var="resin_admin_external"
+                       value="${web_admin_external}"/>
+            <resin:set var="resin_admin_insecure"
+                       value="${! web_admin_ssl}"/>
+          </prologue>
+        </web-app>
+      </resin:if>
+
+      <resin:if test="${rest_admin_enable}">
+        <web-app id="/resin-rest"
+                 root-directory="${resin.root}/doc/resin-rest">
+
+          <resin:BasicLogin realm-name="resin"/>
+
+          <resin:Allow url-pattern="/*">
+            <resin:IfUserInRole role="resin-admin"/>
+          </resin:Allow>
+
+          <servlet-mapping url-pattern="/*"
+                           servlet-class="com.caucho.admin.servlet.AdminRestServlet">
+            <init>
+              <require-secure>${rest_admin_ssl}</require-secure>
+            </init>
+          </servlet-mapping>
+        </web-app>
+      </resin:if>
+
+    </host-default>
+
+    <!-- include resources config files in resources/ -->
+    <resin:import fileset="${resin.root}/${cluster.id}-inf/**/*.xml"/>
+
+    <!-- standard servlet behavior, including .jsp, .php, and WEB-INF -->
+    <resin:import path="${__DIR__}/app-default.xml"/>
+  </cluster-default>
+</resin>
+

+ 9 - 0
configmap.json

@@ -0,0 +1,9 @@
+{
+    "apiVersion": "v1",
+    "data": CMDATA,
+    "kind": "ConfigMap",
+    "metadata": {
+    "name": "tcp-services",
+    "namespace": "ingress-nginx"
+    }
+}

+ 91 - 0
deploy-tmp-v2.yaml

@@ -0,0 +1,91 @@
+---
+apiVersion: apps/v1
+kind: $JNLP_CONTROL
+metadata:
+  name: $DRONE_REPO_NAME-v2
+  namespace: $JNLP_ENV
+  labels:
+    app: $DRONE_REPO_NAME
+spec:
+  serviceName: $DRONE_REPO_NAME-v2
+  replicas: $JNLP_REPLICAS
+  selector:
+    matchLabels:
+      app: $DRONE_REPO_NAME-v2
+  template:
+    metadata:
+      labels:
+        app: $DRONE_REPO_NAME-v2
+    spec:
+      terminationGracePeriodSeconds: 180
+      initContainers:
+        - name: init
+          image: $JNLP_REPO/dev/busybox
+          command: ["chmod","777","-R","$JNLP_MOUNT_PATH"]
+          imagePullPolicy: Always
+          volumeMounts:
+          - name: volume
+            mountPath: $JNLP_MOUNT_PATH
+      containers:
+      - name: $DRONE_REPO_NAME-v2
+        image: $JNLP_REPO/$JNLP_ENV/$DRONE_REPO_NAME:$JNLP_TAG
+        imagePullPolicy: Always
+        ports:
+        - containerPort: $JNLP_CONTAINER_PORT
+          name: port
+        volumeMounts:
+        - name: volume
+          mountPath: $JNLP_MOUNT_PATH
+        livenessProbe:
+          tcpSocket:
+            port: $JNLP_CONTAINER_PORT
+          initialDelaySeconds: $JNLP_LIVENESS_INIT
+          periodSeconds: $JNLP_LIVENESS_PER
+        readinessProbe:
+          tcpSocket:
+            port: $JNLP_CONTAINER_PORT
+          initialDelaySeconds: $JNLP_READINESS_INIT
+          periodSeconds: $JNLP_READINESS_PER
+  volumeClaimTemplates:
+  - metadata:
+      name: volume
+    spec:
+      accessModes: ["ReadWriteOnce"]
+      storageClassName: rbd
+      resources:
+        requests:
+          storage: $JNLP_STORAGE_CAPACITY
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: $DRONE_REPO_NAME-v2-svc
+  namespace: $JNLP_ENV
+  labels:
+    app: $DRONE_REPO_NAME-v2-svc
+spec:
+  type: NodePort
+  ports:
+  - port: $JNLP_CONTAINER_PORT
+    targetPort: $JNLP_CONTAINER_PORT
+  selector:
+    app: $DRONE_REPO_NAME-v2
+---
+apiVersion: extensions/v1beta1
+kind: Ingress
+metadata:
+  name: $DRONE_REPO_NAME-v2-ingress
+  namespace: $JNLP_ENV
+  annotations:
+    kubernetes.io/ingress.class: $JNLP_INGRESS
+    nginx.ingress.kubernetes.io/canary: "true"
+    nginx.ingress.kubernetes.io/canary-weight: "10"
+spec:
+  rules:
+  - host: $JNLP_ENV-$DRONE_REPO_NAME$JNLP_DOMAIN
+    http:
+      paths:
+      - path: /
+        backend:
+          serviceName: $DRONE_REPO_NAME-v2-svc
+          servicePort: $JNLP_CONTAINER_PORT

+ 91 - 0
deploy-tmp.yaml

@@ -0,0 +1,91 @@
+---
+apiVersion: apps/v1
+kind: $JNLP_CONTROL
+metadata:
+  name: $DRONE_REPO_NAME
+  namespace: $JNLP_ENV
+  labels:
+    app: $DRONE_REPO_NAME
+spec:
+  serviceName: $DRONE_REPO_NAME
+  replicas: $JNLP_REPLICAS
+  selector:
+    matchLabels:
+      app: $DRONE_REPO_NAME
+  template:
+    metadata:
+      labels:
+        app: $DRONE_REPO_NAME
+    spec:
+      terminationGracePeriodSeconds: 180
+      initContainers:
+        - name: init
+          image: $JNLP_REPO/dev/busybox
+          command: ["chmod","777","-R","$JNLP_MOUNT_PATH"]
+          imagePullPolicy: Always
+          volumeMounts:
+          - name: volume
+            mountPath: $JNLP_MOUNT_PATH
+      nodeSelector:
+        app.touchrs: touchrs
+      containers:
+      - name: $DRONE_REPO_NAME
+        image: $JNLP_REPO/$JNLP_ENV/$DRONE_REPO_NAME:$JNLP_TAG
+        imagePullPolicy: Always
+        ports:
+        - containerPort: $JNLP_CONTAINER_PORT
+          name: port
+        volumeMounts:
+        - name: volume
+          mountPath: $JNLP_MOUNT_PATH
+        livenessProbe:
+          tcpSocket:
+            port: $JNLP_CONTAINER_PORT
+          initialDelaySeconds: $JNLP_LIVENESS_INIT
+          periodSeconds: $JNLP_LIVENESS_PER
+        readinessProbe:
+          tcpSocket:
+            port: $JNLP_CONTAINER_PORT
+          initialDelaySeconds: $JNLP_READINESS_INIT
+          periodSeconds: $JNLP_READINESS_PER
+  volumeClaimTemplates:
+  - metadata:
+      name: volume
+    spec:
+      accessModes: ["ReadWriteOnce"]
+      storageClassName: rbd
+      resources:
+        requests:
+          storage: $JNLP_STORAGE_CAPACITY
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: $DRONE_REPO_NAME-svc
+  namespace: $JNLP_ENV
+  labels:
+    app: $DRONE_REPO_NAME-svc
+spec:
+  type: NodePort
+  ports:
+  - port: $JNLP_CONTAINER_PORT
+    targetPort: $JNLP_CONTAINER_PORT
+  selector:
+    app: $DRONE_REPO_NAME
+---
+apiVersion: extensions/v1beta1
+kind: Ingress
+metadata:
+  name: $DRONE_REPO_NAME-ingress
+  namespace: $JNLP_ENV
+  annotations:
+    kubernetes.io/ingress.class: $JNLP_INGRESS
+spec:
+  rules:
+  - host: $JNLP_ENV-$DRONE_REPO_NAME$JNLP_DOMAIN
+    http:
+      paths:
+      - path: /
+        backend:
+          serviceName: $DRONE_REPO_NAME-svc
+          servicePort: $JNLP_CONTAINER_PORT

+ 14 - 0
entrypoint.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+
+set -e
+set -o pipefail
+
+
+mkdir -p /data/log/devlog/ /data/log/other/  /data/project/  /data/log/novelweb/ /home/book/preps/.java/.userPrefs
+rm -rf /data/project/* /data/wapage
+touch /home/book/preps/.java/.userPrefs/.user.lock.book
+touch /home/book/preps/.java/.userPrefs/.userRootModFile.book
+mv /tmp/ROOT.war /data/project/
+chown book:book -R  /data /app/soft/resin-pro-3.1.6 /home/book/preps
+
+exec "$@"

+ 233 - 0
ppctl.py

@@ -0,0 +1,233 @@
+#!/usr/bin/python
+# -*- coding: UTF-8 -*-
+from __future__ import print_function
+import os
+import commands
+import httplib, urllib
+import json
+import time
+from kubernetes.client.rest import ApiException
+from pprint import pprint
+from kubernetes import client, config
+import sys, getopt, random
+from aliyunsdkcore.client import AcsClient
+from aliyunsdkcore.acs_exception.exceptions import ClientException
+from aliyunsdkcore.acs_exception.exceptions import ServerException
+from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest
+from aliyunsdkalidns.request.v20150109.DeleteDomainRecordRequest import DeleteDomainRecordRequest
+from aliyunsdkalidns.request.v20150109.DescribeDomainRecordsRequest import DescribeDomainRecordsRequest
+
+
+
+JNLP_ENV = os.getenv('JNLP_ENV')
+JNLP_TAG = os.getenv('JNLP_TAG')
+JNLP_CONTAINER_PORT = os.getenv('JNLP_CONTAINER_PORT')
+# JNLP_WAR = os.getenv('JNLP_WAR')
+JNLP_INGRESS = os.getenv('JNLP_INGRESS')
+JNLP_IMAGE = os.getenv('JNLP_IMAGE')
+JNLP_CONTROL_NAME = os.getenv('DRONE_REPO_NAME')
+JNLP_STORAGE_CLASS = os.getenv('JNLP_STORAGE_CLASS')
+JNLP_DOMAIN = os.getenv('JNLP_DOMAIN')
+JNLP_CONTROL = os.getenv('JNLP_CONTROL')
+JNLP_REPLICAS = os.getenv('JNLP_REPLICAS')
+JNLP_STORAGE_CAPACITY = os.getenv('JNLP_STORAGE_CAPACITY')
+JNLP_MOUNT_PATH = os.getenv('JNLP_MOUNT_PATH')
+JNLP_SVC_MODE = os.getenv('JNLP_SVC_MODE')
+NGINX_SVC = str(JNLP_ENV) + '/' + str(JNLP_CONTROL_NAME) + '-svc:' + str(JNLP_CONTAINER_PORT)
+NGINX_PORT = os.getenv('JNLP_CONTAINER_PORT')
+RECORD_NAME = os.getenv('JNLP_ENV') + "-" + os.getenv('DRONE_REPO_NAME')
+INGRESS_LIST_IN = ["10.26.32.137"]
+INGRESS_LIST_PUB = ["120.192.70.105"]
+NGINX_RECORD_IP = random.sample(INGRESS_LIST_PUB, 1)[0]
+DOMAINNAME = os.getenv('JNLP_DOMAIN').strip('.')
+
+
+# 生成deploy.yaml文件
+def deployYamlCreate():
+    tmpctl = '''
+    config=`env|grep JNLP`
+    template=`cat ./deploy-tmp.yaml`
+    printf "$config\ncat << EOF\n$template\nEOF" | bash > ./deploy.yaml
+    '''
+    f1 = open("tempshell.sh","w")
+    f1.writelines(tmpctl)
+    f1.close()
+    status,output = commands.getstatusoutput("sh tempshell.sh && rm -f tempshell.sh")
+    print("code:" + str(status) + str(output) + "; create deploy.yaml success !!!")
+    return status,output
+
+
+# 生成Dockerfile文件
+def DockerfileCreate():
+    tmp = '''
+    onfig=`env|grep JNLP`
+    template=`cat ./Dockerfile`
+    printf "$config\ncat << EOF\n$template\nEOF" | bash > ./Dockerfile
+    '''
+    f2 = open("tmp.sh","w")
+    f2.writelines(tmp)
+    f2.close()
+    status,output = commands.getstatusoutput("sh tmp.sh && rm -f tmp.sh")
+    print("code:" + str(status) + str(output) + "; create Dockerfile success !!!")
+    return
+
+
+# 更新haproxy configmap.json配置文件,生成TCP服务转发记录
+def updateConfigMap(file):
+    if JNLP_SVC_MODE == "tcp":
+        data = {}
+        data[NGINX_PORT] = NGINX_SVC
+        status, output = commands.getstatusoutput("kubectl  get cm  tcp-services -n  ingress-nginx -o=json")
+        tempdict = eval(output)
+        tempdict['data'][NGINX_PORT] = NGINX_SVC
+        newdata = tempdict['data']
+        print(newdata,status) 
+        old_str = "CMDATA"
+        new_str = str(newdata).replace("'",'"')
+        with open(file, "r") as f1,open("%s.bak" % file, "w" ) as f2:
+            for line in f1:
+                if old_str in line:
+                    line = line.replace(old_str, new_str)
+                f2.write(line)
+        os.remove(file)
+        os.rename("%s.bak" % file, file)
+        cmStatus = "1"
+    else:
+        print("****** Nginx Tcp Services Configmap.json Do Not Update ******")
+        cmStatus = "0"
+    return cmStatus
+
+# 部署应用到kubernetes平台
+def deployToKube():
+    cmStatus = updateConfigMap("configmap.json")
+    appStatus = commands.getoutput("kubectl  get sts $JNLP_CONTROL_NAME -n $JNLP_NAMESPACE|grep $JNLP_CONTROL_NAME|wc -l")
+    if appStatus == "1" and cmStatus == "1":
+        print("Warning:" + JNLP_CONTROL_NAME + " is already, i will update it and update nginx tcp proxy !!!")
+        apply_out = commands.getoutput("kubectl apply -f ./deploy.yaml && kubectl apply -f ./configmap.json")
+        print("===>>> kubectl apply output <<<===")
+        print(apply_out)
+    elif appStatus == "1" and cmStatus == "0":
+        print("Warning:" + JNLP_CONTROL_NAME + " is already, i will update it !!!")
+        apply_out = commands.getoutput("kubectl apply -f ./deploy.yaml")
+        print("===>>> kubectl apply output <<<===")
+        print(apply_out)
+    elif appStatus != "1" and cmStatus == "1":
+        apply_out = commands.getoutput("kubectl apply -f ./deploy.yaml && kubectl apply -f ./configmap.json")
+        print("===>>> kubectl apply output <<<===")
+        print(apply_out)
+        print("===>>> apply is successfull <<<===")
+    else:
+        apply_out = commands.getoutput("kubectl apply -f ./deploy.yaml")
+        print("===>>> kubectl apply output <<<===")
+        print(apply_out)
+        print("===>>> apply app successfull <<<===")
+    return
+
+
+# 部署应用状态获取
+def deployStatus():
+    kubeconfig = config.kube_config.load_kube_config(config_file="/root/.kube/config")
+    appsv1_api_instance = client.AppsV1Api(kubeconfig)
+    namespace = JNLP_ENV
+    stsname = JNLP_CONTROL_NAME
+    pretty = "true"
+    for x in range(20):
+        try:
+            sts_response = appsv1_api_instance.read_namespaced_stateful_set_status(stsname, namespace, pretty=pretty)
+            if sts_response.status.replicas == sts_response.status.ready_replicas :
+                print("===>>> " +stsname + " is RUNNING <<<===")
+                chk_status = 1
+                break
+            else:
+                if x < 40:
+                    time.sleep(15)
+                else:
+                    chk_status = 0
+                    print(stsname + " status check fail !!! , Please contact kubernetes systen administrator")
+        except ApiException as e:
+            print("Exception when calling CoreV1Api->list_namespaced_pod: %s\n" % e)
+    return chk_status
+
+
+# DNS解析
+# 域名由jenkins项目名+命名空间+dns域组合而成
+# 如果域名已存在,不会再更新
+def dnsAllocation():
+    if JNLP_INGRESS == "nginx":
+        httpClient = httplib.HTTPConnection("opsadmin.evbj.easou.com", 80, timeout=30)
+        headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
+        params = urllib.urlencode({'method': 'add', 'type': 'record', 'domain_id': 24, 'record_type': 'A', 'record_name': RECORD_NAME ,'record_ip': NGINX_RECORD_IP , 'record_ttl': 180})
+        httpClient.request("POST", "/dns/dnsapi/?token=c2d1856be235a3207cd03b6f4d3c4094", params, headers)
+        response = httpClient.getresponse().read()
+        jstr = json.loads(response)
+        nsStatus = jstr['status']
+        print(NGINX_RECORD_IP)
+        if nsStatus == "-501":
+            print(JNLP_ENV + "-" + JNLP_CONTROL_NAME + JNLP_DOMAIN + " is already exist")
+        elif nsStatus == "0":
+            httpClient = httplib.HTTPConnection("opsadmin.evbj.easou.com", 80, timeout=30)
+            httpClient.request("POST", "/dns/mkconfig/?token=c2d1856be235a3207cd03b6f4d3c4094")
+            response = httpClient.getresponse().read()
+            jstr = json.loads(response)
+            upStatus = jstr['status']
+            print(JNLP_ENV + "-" + JNLP_CONTROL_NAME + JNLP_DOMAIN + " " +upStatus + " add successfull !!!")
+        else:
+            print("*****Please contact DNS systen administrator*****")
+    else :
+        print(">>> Ingress error, Only nginx !!! <<<")
+    return
+
+def cloudDns():
+    if JNLP_INGRESS == "nginx":
+        client = AcsClient('LTAI4LibOCW5ilIa', 'NiA9OumXJDHp4TwLwXWcCKGoDgDjms', 'cn-hangzhou')
+
+        # describe record
+        request = DescribeDomainRecordsRequest()
+        request.set_accept_format('json')
+        request.set_DomainName(DOMAINNAME)
+        request.set_RRKeyWord(RECORD_NAME)
+        response = client.do_action_with_exception(request)
+        jsondata = json.loads(response)
+        # print(response)
+        if jsondata['TotalCount'] != 0:
+            print(RECORD_NAME + "." + DOMAINNAME + " is already exists <<<")
+        else :
+        # add record
+            request = AddDomainRecordRequest()
+            request.set_accept_format('json')
+            request.set_Value(NGINX_RECORD_IP)
+            request.set_Type("A")
+            request.set_RR(RECORD_NAME)
+            request.set_DomainName(DOMAINNAME)
+            response = client.do_action_with_exception(request)
+            # print(response)
+            print(RECORD_NAME + "." + DOMAINNAME + " add sucess <<<")
+    else :
+        print(">>> Ingress error, Only nginx !!! <<<")
+    return
+
+def main(argv=None):
+    if argv is None:
+        args = sys.argv[1:]
+        for opt_name in args :
+            if opt_name in ('-a','--apply'):
+                print("===>>> deploy app to kubernetes <<<===")
+                deployToKube()
+                time.sleep(10)
+                sys.exit()
+            if opt_name in ('-b','--build'):
+                print("===>>> create deploy.yaml <<<===")
+                deployYamlCreate()
+                sys.exit()
+            if opt_name in ('-c','--check'):
+                print("===>>> app status check <<<===")
+                deployStatus()
+                sys.exit()
+            if opt_name in ('-d','--dns'):
+                print("===>>> add/update dns resolve <<<===")
+                cloudDns()
+                sys.exit()
+    return
+
+if __name__ == "__main__":
+    main()

+ 1 - 0
release

@@ -0,0 +1 @@
+10.26.22.190::release/app-web/prod-64/copyright-content-manager/1.0.0/copyright-content-manager_1.0.0_1.0.0Dev_T1.0.0-167720_1.0.0_20210714-174011_RBL

+ 273 - 0
resin.conf

@@ -0,0 +1,273 @@
+<!--
+   - Resin 3.1 configuration file.
+  -->
+<resin xmlns="http://caucho.com/ns/resin"
+       xmlns:resin="http://caucho.com/ns/resin/core">
+
+  <!-- adds all .jar files under the resin/lib directory -->
+  <class-loader>
+    <tree-loader path="${resin.home}/ext-lib"/>
+    <tree-loader path="${resin.root}/ext-lib"/>
+
+    <tree-loader path="${resin.home}/lib"/>
+    <tree-loader path="${resin.root}/lib"/>
+  </class-loader>
+
+  <!--
+     - Management configuration
+     -
+     - Remote management requires at least one enabled admin user.
+    -->
+  <management path="${resin.root}/admin">
+    <user name="admin" password="password" disable="true"/>
+
+    <resin:if test="${resin.professional}">
+      <deploy-service/>
+      <jmx-service/>
+      <log-service/>
+      <xa-log-service/>
+    </resin:if>
+  </management>
+
+
+  <log name="" level="info" path="stdout:"
+       timestamp="[%Y-%m-%d %H:%M:%S.%s] {%{thread}} "/>
+ <log name='' level='fine' path='stderr:' timestamp="[%Y-%m-%d %H:%M:%S.%s] {%{thread}} "/>
+
+  <logger name="com.caucho" level="info"/>
+  <logger name="com.caucho.java" level="config"/>
+  <logger name="com.caucho.loader" level="config"/>
+
+
+  <dependency-check-interval>2s</dependency-check-interval>
+
+  <javac compiler="internal" args="-source 1.6"/>
+
+
+  <cluster id="app-tier">
+    <!-- sets the content root for the cluster, relative to server.root -->
+    <root-directory>.</root-directory>
+
+    <server-default>
+      <!-- The http port -->
+      <http address="*" port="8080"/>
+
+   
+      <jvm-arg>-server</jvm-arg>
+      <jvm-arg>-Xmx4096m</jvm-arg>
+      <jvm-arg>-Xms4096m</jvm-arg>
+      <jvm-arg>-Xmn1024m</jvm-arg>
+      <jvm-arg>-Xss1m</jvm-arg>
+      <jvm-arg>-XX:PermSize=128m</jvm-arg>
+      <jvm-arg>-XX:MaxPermSize=256m</jvm-arg>
+<!--
+      <jvm-arg>-Xincgc</jvm-arg>
+-->
+      <jvm-arg>-Xdebug</jvm-arg>
+      <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>
+      <jvm-arg>-Djava.util.prefs.userRoot=/home/book/preps</jvm-arg>
+
+      <!--
+         - Uncomment to enable admin heap dumps
+         - <jvm-arg>-agentlib:resin</jvm-arg>
+        -->
+
+      <!--
+         - arguments for the watchdog process
+        -->
+      <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg>
+      <watchdog-port>9600</watchdog-port>
+
+      <!--
+         - Configures the minimum free memory allowed before Resin
+         - will force a restart.
+        -->
+      <memory-free-min>1M</memory-free-min>
+
+      <!-- Maximum number of threads. -->
+      <thread-max>2300</thread-max>
+
+      <!-- Configures the socket timeout -->
+      <socket-timeout>15s</socket-timeout>
+
+      <!-- Configures the keepalive -->
+      <keepalive-max>128</keepalive-max>
+      <keepalive-timeout>15s</keepalive-timeout>
+
+    
+    </server-default>
+
+    <!-- define the servers in the cluster -->
+    <server id="" address="127.0.0.1" port="6800" load-balance-socket-timeout="600s"/>
+
+    <resin:if test="${resin.professional}">
+      <persistent-store type="cluster">
+        <init path="session"/>
+      </persistent-store>
+    </resin:if>
+
+
+    <!--
+       - Enables the cache (available in Resin Professional) 
+      -->
+    <resin:if test="${resin.professional}">
+      <cache path="cache" memory-size="64M">
+        <!-- Vary header rewriting for IE -->
+        <rewrite-vary-as-private/>
+      </cache>
+    </resin:if>
+
+    <!--
+       - Enables periodic checking of the server status and
+       - check for deadlocks..
+       -
+       - All servers can add <url>s to be checked.
+      -->
+    <resin:if test="${resin.professional}">
+      <ping>
+        <!-- <url>http://localhost:8080/test-ping.jsp</url> -->
+      </ping>
+    </resin:if>
+
+    <!--
+       - Defaults applied to each web-app.
+      -->
+    <web-app-default>
+      <prologue>
+        <!--
+           - Extension library for common jar files.  The ext is safe
+           - even for non-classloader aware jars.  The loaded classes
+           - will be loaded separately for each web-app, i.e. the class
+           - itself will be distinct.
+          -->
+        <class-loader>
+          <tree-loader path="${resin.root}/ext-webapp-lib"/>
+        </class-loader>
+
+        <!--
+           - Enable EL expressions in Servlet and Filter init-param
+          -->
+        <allow-servlet-el/>
+      </prologue>
+      
+      <!--
+         - Sets timeout values for cacheable pages, e.g. static pages.
+        -->
+      <cache-mapping url-pattern="/" expires="60m"/>
+      <cache-mapping url-pattern="/*.m" expires="60m"/>
+
+
+      <!--
+         - for security, disable session URLs by default.
+        -->
+      <session-config>
+        <enable-url-rewriting>false</enable-url-rewriting>
+        <session-timeout>40</session-timeout>
+        <session-max>12000</session-max>
+      </session-config>
+
+      <!--
+         - For security, set the HttpOnly flag in cookies.
+         - <cookie-http-only/>
+        -->
+
+      <!--
+         - Some JSP packages have incorrect .tld files.  Its possible to
+         - set validate-taglib-schema to false to work around these packages.
+        -->
+        <jsp>
+          <validate-taglib-schema>true</validate-taglib-schema>
+          <fast-jstl>true</fast-jstl>
+          <fast-jsf>false</fast-jsf>
+        </jsp>
+    </web-app-default>
+
+    <!-- includes the app-default for default web-app behavior -->
+    <resin:import path="${resin.home}/conf/app-default.xml"/>
+
+    <!--
+       - Sample database pool configuration
+       -
+       - The JDBC name is java:comp/env/jdbc/test
+        <database>
+       <jndi-name>jdbc/noveladmin</jndi-name>
+       <driver type="com.mysql.jdbc.Driver">
+         <url>jdbc:mysql://10.13.24.176:3306/ESBOOKCONFIG</url>
+         <user>wap.esbconf</user>
+         <password>qazwsx@186</password>
+        </driver>
+        <prepared-statement-cache-size>20</prepared-statement-cache-size>
+        <max-connections>60</max-connections>
+        <max-idle-time>30s</max-idle-time>
+        <max-active-time>12h</max-active-time>
+        <max-pool-time>12h</max-pool-time>
+        </database>
+         -->
+
+        <database>
+            <jndi-name>jdbc/noveladmin</jndi-name>
+            <driver type="com.mysql.jdbc.Driver">
+            <url>jdbc:mysql://10.26.30.112:3306/noveladmin</url>
+            <user>wap.news</user>
+            <password>qazwsx</password>
+            </driver>
+            <prepared-statement-cache-size>20</prepared-statement-cache-size>
+            <max-connections>60</max-connections>
+            <max-idle-time>30s</max-idle-time>
+            <max-active-time>12h</max-active-time>
+            <max-pool-time>12h</max-pool-time>
+        </database>
+    <!--
+       - Default host configuration applied to all virtual hosts.
+      -->
+    <host-default>
+      <!--
+         - With another web server, like Apache, this can be commented out
+         - because the web server will log this information. -->
+
+       <access-log path-format="/data/log/other/access.log" 
+            format='v2{]b.easou.com{]%r{]%{uid_bi}c{]%{%Y%m%d %H%M%S%s}t{]%s{]-{]%D{]%b{]%b{]%{X-Real-IP}i{]%{X-Forwarded-For}i{]%{Referer}i{]-{]%{User-Agent}i{]online_ta{]%{uid_bi}c{]-{]%{uid}c{]%{cid}c{]{]v2'
+            rollover-period="1h"/>
+
+      <!-- creates the webapps directory for .war expansion -->
+      <web-app-deploy path="webapps"/>
+
+      <!-- creates the deploy directory for .ear expansion -->
+      <ear-deploy path="deploy">
+        <ear-default>
+          <ejb-server>
+            <config-directory>WEB-INF</config-directory>
+          </ejb-server>
+        </ear-default>
+      </ear-deploy>
+
+      <!-- creates the deploy directory for .rar expansion -->
+      <resource-deploy path="deploy"/>
+    </host-default>
+
+    <!-- configures a deployment directory for virtual hosts -->
+    <host-deploy path="hosts">
+      <host-default>
+        <resin:import path="host.xml" optional="true"/>
+      </host-default>
+    </host-deploy>
+
+    <!-- configures the default host, matching any host name -->
+    <host id="" root-directory=".">
+        <web-app id="/" character-encoding='UTF-8' document-directory="/data/project/ROOT" archive-path="/data/project/ROOT.war">
+        <stdout-log path="/data/log/devlog/stdout.log" rollover-period="1W"/>
+        <stderr-log path="/data/log/devlog/stderr.log" rollover-period='1W'/>
+        <!--<access-log path="/data/log/novelweb/access.log"
+            format='%h"%{%Y-%m-%d %H:%M:%S}t"%r"%s"%b"%{esid}o"%{cid}o"%{X-Forwarded-For}i"%{mobile}o"%{ua}o"%{mid}o"%{did}o'
+            rollover-period="1D"/> -->
+       <jsp>
+        <dependency-check-interval>300s</dependency-check-interval>
+       </jsp>
+       </web-app>
+    </host>
+  </cluster>
+
+  <!--
+     - Configuration for the web-tier/load-balancer
+    -->
+</resin>

+ 175 - 0
resin.properties

@@ -0,0 +1,175 @@
+# resin.properties - configuration variable values
+# 
+# See resin.xml, cluster-default.xml, and health.xml for full configuration.
+# Any variable defined by ${...} can be set as a property in this file.
+# 
+# Individual server overrides can be specified by prepending the server.id.
+# For example, increasing the log level for an individual server:
+#
+# log_level : info
+# app-0.log_level : finest
+#
+# Like Resin XML configuration, modification of this file will trigger
+# a restart.
+#
+
+# General log level (modify resin.xml for more granular log level adjustments)
+# log_level     : finer
+
+# Enable verbose browser error reporting
+dev_mode      : true
+
+# How often Resin should check for updated files.
+# dependency_check_interval : 5m
+
+# Enable /resin-doc Resin documentation
+resin_doc      : false
+resin_doc_host :
+
+# List Triad server ip-addresses:hmux-port for each tier, space separated
+# App tier Triad servers must be listed to enable web-tier to 
+# app-tier load-balancing
+
+# web-tier Triad servers: web-0 web-1 web-2
+# web_servers      : 127.0.0.1:6810
+
+# app-tier Triad servers: app-0 app-1 app-2
+app_servers      : 127.0.0.1:6800
+
+# Configures Resin for a memcached server tier
+# memcached-tier Triad servers: memcached-0 memcached-1 memcached-2
+# memcached_servers    : 127.0.0.1:6820
+# memcached_port : 11211
+
+# proxycache tier: proxycache-0 proxycache-1 proxycache-2
+# proxycache_servers   : 127.0.0.1:6830
+# backend_servers       : 127.0.0.1:80
+
+# Allow elastic nodes to join the cluster (enable for cloud mode)
+# elastic_cloud_enable : true
+
+# The cluster that elastic nodes should join - each will contact a Triad server
+# Use a separate resin.properties file for each cluster
+home_cluster : app
+
+# Used for an elastic server to join the cluster in home_cluster
+# elastic_server : true
+
+# Create a distinct webapps/ directory for each server, for vertical scaling
+# elastic_webapp : true
+
+# Used for cloud servers with dynamic IP addresses where the DNS name for the
+# server is assigned after the server starts. Resin will retry the start.
+# elastic_dns : true
+
+# specifies the --server in the config file
+# home_server : app-0
+
+# Set HTTP and HTTPS bind address
+# http_address  : *
+
+# Set HTTP and HTTPS ports.
+# Use overrides for individual server control, for example: app-0.http : 8081
+app.http          : 8080
+# app.https         : 8443
+
+web.http          : 8080
+# web.https         : 8443
+
+# memcached.http      : 8080
+# memcached.https     : 8443
+
+# proxycache.http    : 8080
+# proxycache.https  : 8443
+
+# For security, Resin can switch to a non-root user after binding to port 80
+setuid_user : book
+setuid_group : book
+
+# Arg passed directly to the JVM
+#jvm_args  : -Xmx1536m -Xms1536m -Xmn512m -Xss1m -XX:PermSize=128m -XX:MaxPermSize=512m -Xdebug -Dcom.sun.management.jmxremote 
+jvm_args  : -Xmx2048m -Xms2048m -Xss1m -XX:PermSize=256m -XX:MaxPermSize=512m -Xdebug -Dcom.sun.management.jmxremote -verbose:gc -Xloggc:log/gc.log  -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseParallelOldGC
+jvm_mode    : -server
+
+# Local URLs for the watchdog to check to ensure the server is up,
+# space separated
+# http_ping_urls : http://127.0.0.1/test.jsp
+
+# Throttle the number of active threads for a port
+port_thread_max   : 256
+accept_thread_max : 32
+accept_thread_min : 4
+# keepalive_max   : 512
+
+# Enable JNI TCP speed optimizations
+tcp_cork : true
+sendfile : true
+keepalive_select_enable : true
+
+# OpenSSL certificate configuration
+# Keys are typically stored in the resin configuration directory.
+# openssl_file : keys/test.crt
+# openssl_key : keys/test.key
+# openssl_password : changeme
+
+# JSSE certificate configuration
+# Keys are typically stored in the resin configuration directory.
+# jsse_keystore_type : jks
+# jsse_keystore_file : /etc/resin/keys/server.keystore
+# jsse_keystore_password : changeme
+
+# In absence of a signed certificate, Resin will fallback to using a 
+# self-signed development certificate if HTTPS is enabled
+
+# Enable the proxy-cache - for caching static content in memory
+proxy_cache_enable : true
+
+# Sets the proxy cache memory size
+# proxy_cache_size : 256m
+
+# Enable clustered persistent sessions (for failover)
+session_store : true
+
+# disable the quercus *.php mapping when using Apache for PHP
+# quercus_disable : true
+
+# Web-apps named with numeric suffixes, e.g. foo-10.0.war and can be browsed
+# as /foo. When a new version of the web-app is deployed, Resin continues
+# to route active session requests to the previous web-app version while
+# new sessions go to the new version, so users will not be aware of the
+# application upgrade.
+# webapp_multiversion_routing : true
+
+# Set the email address to receive weekly and restart PDF reports
+# email : admin@example.com
+
+# Set a global password to prevent foreign Resin instances from connecting.
+# Must be identical between web, app, and cache clusters.
+# cluster_system_key : changeme
+
+# Enable remote admin (for remote CLI and for EC2 ext: triad discovery)
+# remote_admin_enable : true
+
+# Enable /resin-admin web administration console
+web_admin_enable : false
+web_admin_host   :
+
+# Permit access to /resin-admin from non-local network ip-addresses
+# web_admin_external : true
+
+# Require HTTPS to access /resin-admin
+# web_admin_ssl : true
+
+# Enable Resin REST Admin
+# rest_admin_enable : true
+
+# Require SSL for REST Admin
+# rest_admin_ssl : true
+
+# Access to /resin-admin and remote CLI is password restricted.
+# Use "resinctl generate-password" and copy/paste here to set the admin
+# admin_user : admin
+# admin_password : {SSHA}xxxxxxxx
+
+# Enable reading EC2 user data as resin properties
+# properties_import_url : http://169.254.169.254/latest/user-data

+ 30 - 0
supervisord.conf

@@ -0,0 +1,30 @@
+[unix_http_server]
+file=/var/run/supervisor/supervisor.sock   ; (the path to the socket file)
+
+
+[supervisord]
+logfile=/var/log/supervisor/supervisord.log  ; (main log file;default $CWD/supervisord.log)
+logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
+logfile_backups=10          ; (num of main logfile rotation backups;default 10)
+loglevel=info               ; (log level;default info; others: debug,warn,trace)
+pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
+nodaemon=true              ; (start in foreground if true;default false)
+minfds=10240                 ; (min. avail startup file descriptors;default 1024)
+minprocs=2000                ; (min. avail process descriptors;default 200)
+
+[rpcinterface:supervisor]
+supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
+
+[supervisorctl]
+serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL  for a unix socket
+
+
+[program:resin]
+command=/app/soft/resin-pro-3.1.6/bin/httpd.sh         ; the program (relative uses PATH, can take args)
+process_name=%(program_name)s ; process_name expr (default %(program_name)s)
+autostart=true                ; start at supervisord start (default: true)
+autorestart=true              ; retstart at unexpected quit (default: true)
+stdout_logfile=/data/log/devlog/stdout.log
+stderr_logfile=/data/log/devlog/stderr.log
+user=book
+

+ 261 - 0
tools.py

@@ -0,0 +1,261 @@
+#!/usr/bin/python
+# -*- coding: UTF-8 -*-
+from __future__ import print_function
+import os
+import commands
+import httplib, urllib
+import json
+import time
+import sys, getopt, random
+from kubernetes.client.rest import ApiException
+from pprint import pprint
+from kubernetes import client, config
+from aliyunsdkcore.client import AcsClient
+from aliyunsdkcore.acs_exception.exceptions import ClientException
+from aliyunsdkcore.acs_exception.exceptions import ServerException
+from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest
+from aliyunsdkalidns.request.v20150109.DeleteDomainRecordRequest import DeleteDomainRecordRequest
+from aliyunsdkalidns.request.v20150109.DescribeDomainRecordsRequest import DescribeDomainRecordsRequest
+
+
+JNLP_ENV = os.getenv('JNLP_ENV')
+JNLP_TAG = os.getenv('JNLP_TAG')
+JNLP_VERSION = os.getenv('JNLP_VERSION')
+JNLP_CONTAINER_PORT = os.getenv('JNLP_CONTAINER_PORT')
+# JNLP_WAR = os.getenv('JNLP_WAR')
+JNLP_INGRESS = os.getenv('JNLP_INGRESS')
+JNLP_IMAGE = os.getenv('JNLP_IMAGE')
+JNLP_CONTROL_NAME = os.getenv('DRONE_REPO_NAME')
+JNLP_STORAGE_CLASS = os.getenv('JNLP_STORAGE_CLASS')
+JNLP_DOMAIN = os.getenv('JNLP_DOMAIN')
+JNLP_CONTROL = os.getenv('JNLP_CONTROL')
+JNLP_REPLICAS = os.getenv('JNLP_REPLICAS')
+JNLP_STORAGE_CAPACITY = os.getenv('JNLP_STORAGE_CAPACITY')
+JNLP_MOUNT_PATH = os.getenv('JNLP_MOUNT_PATH')
+JNLP_SVC_MODE = os.getenv('JNLP_SVC_MODE')
+NGINX_SVC = str(JNLP_ENV) + '/' + str(JNLP_CONTROL_NAME) + '-svc:' + str(JNLP_CONTAINER_PORT)
+NGINX_PORT = os.getenv('JNLP_CONTAINER_PORT')
+RECORD_NAME = os.getenv('JNLP_ENV') + "-" + os.getenv('DRONE_REPO_NAME')
+INGRESS_LIST_IN = ["10.26.32.137"]
+INGRESS_LIST_PUB = ["120.192.70.105"]
+NGINX_RECORD_IP = random.sample(INGRESS_LIST_PUB, 1)[0]
+DOMAINNAME = os.getenv('JNLP_DOMAIN').strip('.')
+
+
+# 生成deploy.yaml文件
+def deployYamlCreate():
+    if JNLP_VERSION == "v1":
+        tmpctl = '''
+            config=`env|grep JNLP`
+            template=`cat ./deploy-tmp.yaml`
+            printf "$config\ncat << EOF\n$template\nEOF" | bash > ./deploy.yaml
+        '''
+        f1 = open("tempshell.sh","w")
+        f1.writelines(tmpctl)
+        f1.close()
+        status,output = commands.getstatusoutput("sh tempshell.sh && rm -f tempshell.sh")
+        print("code:" + str(status) + str(output) + "; create deploy.yaml success !!!")
+        return status,output
+    elif JNLP_VERSION == "v2":
+        tmpctl = '''
+            config=`env|grep JNLP`
+            template=`cat ./deploy-tmp-v2.yaml`
+            printf "$config\ncat << EOF\n$template\nEOF" | bash > ./deploy.yaml
+        '''
+        f1 = open("tempshell.sh","w")
+        f1.writelines(tmpctl)
+        f1.close()
+        status,output = commands.getstatusoutput("sh tempshell.sh && rm -f tempshell.sh")
+        print("code:" + str(status) + str(output) + "; create deploy.yaml success !!!")
+        return status,output
+    else:
+        print("Can Not Find JNLP_VERSION, Please Check !!!")
+        return "Can Not Find JNLP_VERSION, Please Check !!!"
+
+
+
+# 生成Dockerfile文件
+def DockerfileCreate():
+    tmp = '''
+    onfig=`env|grep JNLP`
+    template=`cat ./Dockerfile`
+    printf "$config\ncat << EOF\n$template\nEOF" | bash > ./Dockerfile
+    '''
+    f2 = open("tmp.sh","w")
+    f2.writelines(tmp)
+    f2.close()
+    status,output = commands.getstatusoutput("sh tmp.sh && rm -f tmp.sh")
+    print("code:" + str(status) + str(output) + "; create Dockerfile success !!!")
+    return
+
+
+# 更新haproxy configmap.json配置文件,生成TCP服务转发记录
+def updateConfigMap(file):
+    if JNLP_SVC_MODE == "tcp":
+        data = {}
+        data[NGINX_PORT] = NGINX_SVC
+        status, output = commands.getstatusoutput("kubectl  get cm  tcp-services -n  ingress-nginx -o=json")
+        tempdict = eval(output)
+        tempdict['data'][NGINX_PORT] = NGINX_SVC
+        newdata = tempdict['data']
+        print(newdata,status)
+        old_str = "CMDATA"
+        new_str = str(newdata).replace("'",'"')
+        with open(file, "r") as f1,open("%s.bak" % file, "w" ) as f2:
+            for line in f1:
+                if old_str in line:
+                    line = line.replace(old_str, new_str)
+                f2.write(line)
+        os.remove(file)
+        os.rename("%s.bak" % file, file)
+        cmStatus = "1"
+    else:
+        print("****** Nginx Tcp Services Configmap.json Do Not Update ******")
+        cmStatus = "0"
+    return cmStatus
+
+# 部署应用到kubernetes平台
+def deployToKube():
+    cmStatus = updateConfigMap("configmap.json")
+    appStatus = commands.getoutput("kubectl  get sts $JNLP_CONTROL_NAME -n $JNLP_NAMESPACE|grep $JNLP_CONTROL_NAME|wc -l")
+    if appStatus == "1" and cmStatus == "1":
+        print("Warning:" + JNLP_CONTROL_NAME + " is already, i will update it and update nginx tcp proxy !!!")
+        apply_out = commands.getoutput("kubectl apply -f ./deploy.yaml && kubectl apply -f ./configmap.json")
+        print("===>>> kubectl apply output <<<===")
+        print(apply_out)
+    elif appStatus == "1" and cmStatus == "0":
+        print("Warning:" + JNLP_CONTROL_NAME + " is already, i will update it !!!")
+        apply_out = commands.getoutput("kubectl apply -f ./deploy.yaml")
+        print("===>>> kubectl apply output <<<===")
+        print(apply_out)
+    elif appStatus != "1" and cmStatus == "1":
+        apply_out = commands.getoutput("kubectl apply -f ./deploy.yaml && kubectl apply -f ./configmap.json")
+        print("===>>> kubectl apply output <<<===")
+        print(apply_out)
+        print("===>>> apply is successfull <<<===")
+    else:
+        apply_out = commands.getoutput("kubectl apply -f ./deploy.yaml")
+        print("===>>> kubectl apply output <<<===")
+        print(apply_out)
+        print("===>>> apply app successfull <<<===")
+    return
+
+
+# 部署应用状态获取
+# 20200615新增
+def appStatusCheck():
+    cmd = "kubedog  rollout  track statefulset " + JNLP_CONTROL_NAME + " -n " + JNLP_ENV
+    appStatus = commands.getstatusoutput(cmd)
+    if appStatus[0] == 0:
+        print("===>>> statefulset: " + JNLP_ENV + "/" + JNLP_CONTROL_NAME + " is running ... <<<===")
+    else:
+        print("===>>> statefulset: " + JNLP_ENV + "/" + JNLP_CONTROL_NAME + " is error, Please Check or Connect Administrator !!! <<<===")
+    return appStatus
+
+# 不再使用该方法检查服务状态
+def deployStatus():
+    kubeconfig = config.kube_config.load_kube_config(config_file="/root/.kube/config")
+    appsv1_api_instance = client.AppsV1Api(kubeconfig)
+    namespace = JNLP_ENV
+    stsname = JNLP_CONTROL_NAME
+    pretty = "true"
+    for x in range(20):
+        try:
+            sts_response = appsv1_api_instance.read_namespaced_stateful_set_status(stsname, namespace, pretty=pretty)
+            if sts_response.status.replicas == sts_response.status.ready_replicas :
+                print("===>>> " +stsname + " is RUNNING <<<===")
+                chk_status = 1
+                break
+            else:
+                if x < 40:
+                    time.sleep(15)
+                else:
+                    chk_status = 0
+                    print(stsname + " status check fail !!! , Please contact kubernetes systen administrator")
+        except ApiException as e:
+            print("Exception when calling CoreV1Api->list_namespaced_pod: %s\n" % e)
+    return chk_status
+
+
+# DNS解析
+# 域名由jenkins项目名+命名空间+dns域组合而成
+# 如果域名已存在,不会再更新
+def dnsAllocation():
+    if JNLP_INGRESS == "nginx":
+        httpClient = httplib.HTTPConnection("opsadmin.evbj.easou.com", 80, timeout=30)
+        headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
+        params = urllib.urlencode({'method': 'add', 'type': 'record', 'domain_id': 24, 'record_type': 'A', 'record_name': RECORD_NAME ,'record_ip': NGINX_RECORD_IP , 'record_ttl': 180})
+        httpClient.request("POST", "/dns/dnsapi/?token=c2d1856be235a3207cd03b6f4d3c4094", params, headers)
+        response = httpClient.getresponse().read()
+        jstr = json.loads(response)
+        nsStatus = jstr['status']
+        print(NGINX_RECORD_IP)
+        if nsStatus == "-501":
+            print(JNLP_ENV + "-" + JNLP_CONTROL_NAME + JNLP_DOMAIN + " is already exist")
+        elif nsStatus == "0":
+            httpClient = httplib.HTTPConnection("opsadmin.evbj.easou.com", 80, timeout=30)
+            httpClient.request("POST", "/dns/mkconfig/?token=c2d1856be235a3207cd03b6f4d3c4094")
+            response = httpClient.getresponse().read()
+            jstr = json.loads(response)
+            upStatus = jstr['status']
+            print(JNLP_ENV + "-" + JNLP_CONTROL_NAME + JNLP_DOMAIN + " " +upStatus + " add successfull !!!")
+        else:
+            print("*****Please contact DNS systen administrator*****")
+    else :
+        print(">>> Ingress error, Only nginx !!! <<<")
+    return
+
+def cloudDns():
+    if JNLP_INGRESS == "nginx":
+        client = AcsClient('LTAI4Fv2cVQGqCkscSuxgx49', '9e13VJa66veTCjsNocBxA09CTcVIi5', 'cn-hangzhou')
+
+        # describe record
+        request = DescribeDomainRecordsRequest()
+        request.set_accept_format('json')
+        request.set_DomainName(DOMAINNAME)
+        request.set_RRKeyWord(RECORD_NAME)
+        response = client.do_action_with_exception(request)
+        jsondata = json.loads(response)
+        # print(response)
+        if jsondata['TotalCount'] != 0:
+            print(RECORD_NAME + "." + DOMAINNAME + " is already exists <<<")
+        else :
+        # add record
+            request = AddDomainRecordRequest()
+            request.set_accept_format('json')
+            request.set_Value(NGINX_RECORD_IP)
+            request.set_Type("A")
+            request.set_RR(RECORD_NAME)
+            request.set_DomainName(DOMAINNAME)
+            response = client.do_action_with_exception(request)
+            # print(response)
+            print(RECORD_NAME + "." + DOMAINNAME + " add sucess <<<")
+    else :
+        print(">>> Ingress error, Only nginx !!! <<<")
+    return
+
+def main(argv=None):
+    if argv is None:
+        args = sys.argv[1:]
+        for opt_name in args :
+            if opt_name in ('-a','--apply'):
+                print("===>>> deploy app to kubernetes <<<===")
+                deployToKube()
+                time.sleep(10)
+                sys.exit()
+            if opt_name in ('-b','--build'):
+                print("===>>> create deploy.yaml <<<===")
+                deployYamlCreate()
+                sys.exit()
+            if opt_name in ('-c','--check'):
+                print("===>>> app status check <<<===")
+                appStatusCheck()
+                sys.exit()
+            if opt_name in ('-d','--dns'):
+                print("===>>> add/update dns resolve <<<===")
+                cloudDns()
+                sys.exit()
+    return
+
+if __name__ == "__main__":
+    main()