yangxg il y a 2 ans
commit
9b9797db86
4 fichiers modifiés avec 321 ajouts et 0 suppressions
  1. 77 0
      .drone.yml
  2. 1 0
      Dockerfile
  3. 166 0
      deploy-tmp.yaml
  4. 77 0
      drone.template.yml

+ 77 - 0
.drone.yml

@@ -0,0 +1,77 @@
+kind: pipeline
+type: kubernetes
+name: nginx-material
+
+clone:
+  disable: true
+
+metadata:
+  namespace: drone
+
+steps:
+  - name: clone
+    image: hub.evbj.easou.com/dev/alpine-git:20200622
+    commands:
+      - git clone $DRONE_GIT_HTTP_URL .
+
+  - name: deployment
+    image: hub.evbj.easou.com/dev/drone-agent:v3.0.1
+    pull: always
+    # privileged: true
+    environment:
+      JNLP_ENV: pro
+      JNLP_REPLICAS: 1
+      JNLP_TAG: r1
+      JNLP_VERSION: v1  # default v1, v2 for canary
+      DEPLOY_ENV: k8s-1 # 可以选择把应用部署到集群:k8s-1 or k8s-2
+      JNLP_REPO: hub.evbj.easou.com
+      JNLP_CONTAINER_PORT: 80
+      JNLP_INGRESS: nginx
+      JNLP_SVC_MODE: http
+      JNLP_STORAGE_CLASS: rbd
+      JNLP_DOMAIN: .ieasou.cn
+      JNLP_CONTROL: StatefulSet
+      JNLP_STORAGE_CAPACITY: 100Gi
+      JNLP_MOUNT_PATH: /data
+      JNLP_LIVENESS_INIT: 30
+      JNLP_LIVENESS_PER: 15
+      JNLP_READINESS_INIT: 30
+      JNLP_READINESS_PER: 15
+      JNLP_INGRESS_PUB: no
+    commands:
+      # 切换目标集群
+      - kubecm s $DEPLOY_ENV
+      # 生成配置YAML文件
+      - python3 /root/tools.py -b
+      # 部署服务到kubernetes上
+      - python3 /root/tools.py -a
+      # 添加dns解析记录,生成访问域名
+      - python3 /root/tools.py -d
+
+  - name: success
+    image: hub.evbj.easou.com/dev/drone-wechat:20200622
+    settings:
+      corpid: ww419ee4063735e1c0
+      corp_secret: zpiRBLETH9eLwIMQ4eJ_r_dcm3BPSGeLHvTcft8Ot-M
+      agent_id: 1000004
+      title: "Pipeline pro/nginx-material:r180938 Success"
+      description: "${DRONE_BUILD_LINK} pro/nginx-material:r180938 部署完成 阅文实时接口k8s部署项目结构变更"
+      msg_url: ${DRONE_BUILD_LINK}
+      btn_txt: "否"
+    when:
+      status:
+        - success
+
+  - name: failure
+    image: hub.evbj.easou.com/dev/drone-wechat:20200622
+    settings:
+      corpid: ww419ee4063735e1c0
+      corp_secret: zpiRBLETH9eLwIMQ4eJ_r_dcm3BPSGeLHvTcft8Ot-M
+      agent_id: 1000004
+      title: "Pipeline pro/nginx-material:r180938 Failure"
+      description: "${DRONE_BUILD_LINK} 部署失败,请检查配置!阅文实时接口k8s部署项目结构变更"
+      msg_url: ${DRONE_BUILD_LINK}
+      btn_txt: "否"
+    when:
+      status:
+        - failure

+ 1 - 0
Dockerfile

@@ -0,0 +1 @@
+FROM nginx

+ 166 - 0
deploy-tmp.yaml

@@ -0,0 +1,166 @@
+---
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+  name: nginx-material
+  namespace: pro
+  labels:
+    app: nginx-material
+spec:
+  serviceName: nginx-material
+  replicas: 2
+  selector:
+    matchLabels:
+      app: nginx-material
+  template:
+    metadata:
+      labels:
+        app: nginx-material
+    spec:
+      terminationGracePeriodSeconds: 180
+      dnsPolicy: ClusterFirstWithHostNet
+      dnsConfig:
+        nameservers:
+          - 223.5.5.5
+          - 10.26.22.50
+          - 10.26.22.150
+      initContainers:
+        - name: init
+          image: hub.evbj.easou.com/dev/busybox
+          command: [ "chmod","777","-R","/data" ]
+          imagePullPolicy: IfNotPresent
+          volumeMounts:
+            - name: volume
+              mountPath: /data
+      #nodeSelector:
+      #  app.touchrs: touchrs
+#      affinity:
+#        podAntiAffinity:
+#          preferredDuringSchedulingIgnoredDuringExecution:
+#          - weight: 100
+#            podAffinityTerm:
+#              labelSelector:
+#                matchExpressions:
+#                - key: app
+#                  operator: In
+#                  values:
+#                  - nginx-material
+#              topologyKey: kubernetes.io/hostname
+      containers:
+        - name: nginx-material
+          image: nginx:1.14.2
+          imagePullPolicy: IfNotPresent
+          ports:
+            - containerPort: 80
+              name: port
+          volumeMounts:
+            - name: volume
+              mountPath: /data
+            - name: nginx-material-config
+                mountPath: /etc/nginx/nginx.conf
+                subPath: nginx.conf
+          readinessProbe:
+            tcpSocket:
+              port: 80
+            initialDelaySeconds: 40
+            periodSeconds: 15
+#        - image: hub.evbj.easou.com/pro/filebeat:7.13.3
+#          imagePullPolicy: IfNotPresent
+#          name: filebeat
+#          volumeMounts:
+#            - name: volume #日志同时挂载在nginx和filebeat中
+#              mountPath: /data
+#            - name: filebeat-config
+#              mountPath: /usr/share/filebeat/filebeat.yml
+#              subPath: filebeat.yml
+      volumes:
+        - name: nginx-material-config
+          configMap:
+            name: nginx-material-config
+            items:
+              - key: nginx.conf
+                path: nginx.conf
+
+  volumeClaimTemplates:
+    - metadata:
+        name: volume
+      spec:
+        accessModes: [ "ReadWriteOnce" ]
+        storageClassName: ceph-block
+        resources:
+          requests:
+            storage: 100Gi
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: nginx-material-svc
+  namespace: pro
+  labels:
+    app: nginx-material-svc
+spec:
+  type: NodePort
+  ports:
+    - port: 80
+      targetPort: 80
+      name: "main"
+  selector:
+    app: nginx-material
+---
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: nginx-material-ingress
+  namespace: pro
+spec:
+  rules:
+    - host: material.appeasou.com
+      http:
+        paths:
+          - path: /
+            pathType: Prefix
+            backend:
+              service:
+                name: nginx-material-svc
+                port:
+                  number: 8080
+  ingressClassName: nginx
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: nginx-material-config
+  namespace: pro
+data:
+  nginx.conf: |
+    user  nginx;
+    worker_processes  1;
+    
+    error_log  /var/log/nginx/error.log warn;
+    pid        /var/run/nginx.pid;
+    
+    
+    events {
+        worker_connections  1024;
+    }
+    
+    
+    http {
+        include       /etc/nginx/mime.types;
+        default_type  application/octet-stream;
+    
+        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
+                          '$status $body_bytes_sent "$http_referer" '
+                          '"$http_user_agent" "$http_x_forwarded_for"';
+    
+        access_log  /var/log/nginx/access.log  main;
+    
+        sendfile        on;
+        #tcp_nopush     on;
+    
+        keepalive_timeout  65;
+    
+        #gzip  on;
+    
+        include /etc/nginx/conf.d/*.conf;
+    }

+ 77 - 0
drone.template.yml

@@ -0,0 +1,77 @@
+kind: pipeline
+type: kubernetes
+name: [APP]
+
+clone:
+  disable: true
+
+metadata:
+  namespace: drone
+
+steps:
+- name: clone
+  image: hub.evbj.easou.com/dev/alpine-git:20200622
+  commands:
+   - git clone $DRONE_GIT_HTTP_URL .
+
+- name: deployment
+  image: hub.evbj.easou.com/dev/drone-agent:v3.0.1
+  pull: always
+  # privileged: true
+  environment:
+    JNLP_ENV: [ENV]
+    JNLP_REPLICAS: [REPLICA]
+    JNLP_TAG: [TAG]
+    JNLP_VERSION: v1  # default v1, v2 for canary
+    DEPLOY_ENV: k8s-1 # 可以选择把应用部署到集群:k8s-1 or k8s-2
+    JNLP_REPO: hub.evbj.easou.com
+    JNLP_CONTAINER_PORT: 80
+    JNLP_INGRESS: nginx
+    JNLP_SVC_MODE: http
+    JNLP_STORAGE_CLASS: rbd
+    JNLP_DOMAIN: .ieasou.cn
+    JNLP_CONTROL: StatefulSet
+    JNLP_STORAGE_CAPACITY: 100Gi
+    JNLP_MOUNT_PATH: /data
+    JNLP_LIVENESS_INIT: 30
+    JNLP_LIVENESS_PER: 15
+    JNLP_READINESS_INIT: 30
+    JNLP_READINESS_PER: 15
+    JNLP_INGRESS_PUB: [EXPOSE]
+  commands:
+    # 切换目标集群
+    - kubecm s $DEPLOY_ENV
+    # 生成配置YAML文件
+    - python3 /root/tools.py -b
+    # 部署服务到kubernetes上
+    - python3 /root/tools.py -a
+    # 添加dns解析记录,生成访问域名
+    - python3 /root/tools.py -d
+
+- name: success
+  image: hub.evbj.easou.com/dev/drone-wechat:20200622
+  settings:
+    corpid: ww419ee4063735e1c0
+    corp_secret: zpiRBLETH9eLwIMQ4eJ_r_dcm3BPSGeLHvTcft8Ot-M
+    agent_id: 1000004
+    title: "Pipeline [ENV]/[APP]:[TAG] Success"
+    description: "${DRONE_BUILD_LINK} [ENV]/[APP]:[TAG] 部署完成 [DEPLOY_MSG]"
+    msg_url: ${DRONE_BUILD_LINK}
+    btn_txt: "否"
+  when:
+    status:
+     - success
+
+- name: failure
+  image: hub.evbj.easou.com/dev/drone-wechat:20200622
+  settings:
+    corpid: ww419ee4063735e1c0
+    corp_secret: zpiRBLETH9eLwIMQ4eJ_r_dcm3BPSGeLHvTcft8Ot-M
+    agent_id: 1000004
+    title: "Pipeline [ENV]/[APP]:[TAG] Failure"
+    description: "${DRONE_BUILD_LINK} 部署失败,请检查配置![DEPLOY_MSG]"
+    msg_url: ${DRONE_BUILD_LINK}
+    btn_txt: "否"
+  when:
+    status:
+     - failure