diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8919945 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +all: build-linux-arm64 build-linux-amd64 + +build-linux-arm64: + /bin/cp -arf /root/wx.yaml application.yaml + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go mod tidy + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -v -a -o wechat.bin main.go + /bin/cp -arf /usr/bin/kubectl . + /bin/cp -arf /root/.kube/config . + docker build -t sre/wechatgateway:arm64 . + kubectl rollout restart deployment -n sre wehcat-gateway + + +build-linux-amd64: + /bin/cp -arf /root/wx.yaml application.yaml + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go mod tidy + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -v -a -o wechat.bin main.go + /bin/cp -arf /usr/bin/kubectl . + /bin/cp -arf /root/.kube/config . + docker build -t sre/wechatgateway:arm64 . \ No newline at end of file diff --git a/handle/handleMessage.go b/handle/handleMessage.go index 2f16714..7cdec2f 100644 --- a/handle/handleMessage.go +++ b/handle/handleMessage.go @@ -29,7 +29,10 @@ func handleMessage(w http.ResponseWriter, r *http.Request) { return } else { log.Println("消息验证成功:", msgContent) - go RecordWechatLog(msgContent.ToUsername, msgContent.FromUsername, msgContent.CreateTime, msgContent.MsgType, msgContent.Content) + //event消息一直在 暂时不入库 + if msgContent.MsgType != "event" { + go RecordWechatLog(msgContent.ToUsername, msgContent.FromUsername, msgContent.CreateTime, msgContent.MsgType, msgContent.Content) + } if global.EnableReply { Reply(msgContent, timestamp, nonce, w) } else { diff --git a/manifests/Deployment.yaml b/manifests/Deployment.yaml new file mode 100644 index 0000000..d6bd51d --- /dev/null +++ b/manifests/Deployment.yaml @@ -0,0 +1,50 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: {} + labels: + app/name: wehcat-gateway + name: wehcat-gateway + namespace: sre +spec: + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 10 + selector: + matchLabels: + app/name: wehcat-gateway + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + template: + metadata: + creationTimestamp: null + labels: + app/name: wehcat-gateway + spec: + containers: + - image: 'sre/wechatgateway:arm64' + imagePullPolicy: IfNotPresent + name: wehcat-gateway + ports: + - containerPort: 8080 + name: http + protocol: TCP + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /app/data + name: volume-x6hei + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 + volumes: + - hostPath: + path: /data/wx-data + type: Directory + name: volume-x6hei \ No newline at end of file diff --git a/manifests/Service.yaml b/manifests/Service.yaml new file mode 100644 index 0000000..8e64b30 --- /dev/null +++ b/manifests/Service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: {} + labels: + app/name: wehcat-gateway + name: wehcat-gateway + namespace: sre +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app/name: wehcat-gateway + sessionAffinity: None + type: ClusterIP \ No newline at end of file diff --git a/manifests/ingress.yaml b/manifests/ingress.yaml new file mode 100644 index 0000000..7848af8 --- /dev/null +++ b/manifests/ingress.yaml @@ -0,0 +1,24 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-ip2region + namespace: sre + annotations: + kubernetes.io/ingress.class: "nginx" # 自动签发开关 + cert-manager.io/cluster-issuer: "letsencrypt-prod-http01" # 自动签发开关 +spec: + tls: + - hosts: + - test.com + secretName: ingress-tls-test-com # 需要修改 + rules: + - host: test.com + http: + paths: + - path: / + backend: + service: + name: ipregion + port: + number: 8080 + pathType: ImplementationSpecific \ No newline at end of file diff --git a/readme.md b/readme.md index dc0eaea..7d1d134 100644 --- a/readme.md +++ b/readme.md @@ -13,118 +13,12 @@ cd /root rm -rf WechatGateWay git clone https://git.sre.ink/go/WechatGateWay.git cd WechatGateWay -/bin/cp -arf /root/wx.yaml application.yaml -CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go mod tidy -CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -v -a -o wechat.bin main.go -/bin/cp -arf /usr/bin/kubectl . -/bin/cp -arf /root/.kube/config . -docker build -t sre/wechatgateway:arm64 . -kubectl rollout restart deployment -n sre wehcat-gateway +make build-linux-arm64 +``` +## k8s manifests ``` -## k8s -```yaml --- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: {} - labels: - app/name: wehcat-gateway - name: wehcat-gateway - namespace: sre -spec: - progressDeadlineSeconds: 600 - replicas: 1 - revisionHistoryLimit: 10 - selector: - matchLabels: - app/name: wehcat-gateway - strategy: - rollingUpdate: - maxSurge: 25% - maxUnavailable: 25% - type: RollingUpdate - template: - metadata: - creationTimestamp: null - labels: - app/name: wehcat-gateway - spec: - containers: - - image: 'sre/wechatgateway:arm64' - imagePullPolicy: IfNotPresent - name: wehcat-gateway - ports: - - containerPort: 8080 - name: http - protocol: TCP - resources: {} - terminationMessagePath: /dev/termination-log - terminationMessagePolicy: File - volumeMounts: - - mountPath: /app/data - name: volume-x6hei - dnsPolicy: ClusterFirst - restartPolicy: Always - schedulerName: default-scheduler - securityContext: {} - terminationGracePeriodSeconds: 30 - volumes: - - hostPath: - path: /data/wx-data - type: Directory - name: volume-x6hei - +manifests/Deployment.yaml +manifests/Service.yaml +manifests/ingress.yaml --- -apiVersion: v1 -kind: Service -metadata: - annotations: {} - labels: - app/name: wehcat-gateway - name: wehcat-gateway - namespace: sre -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: 8080 - selector: - app/name: wehcat-gateway - sessionAffinity: None - type: ClusterIP - - -``` - - -## ingress -```yaml -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: ingress-ip2region - namespace: sre - annotations: - kubernetes.io/ingress.class: "nginx" # 自动签发开关 - cert-manager.io/cluster-issuer: "letsencrypt-prod-http01" # 自动签发开关 -spec: - tls: - - hosts: - - test.com - secretName: ingress-tls-test-com # 需要修改 - rules: - - host: test.com - http: - paths: - - path: / - backend: - service: - name: ipregion - port: - number: 8080 - pathType: ImplementationSpecific -``` - -