From 810f3d292824ea87e00abc0120887ed77b6f24e4 Mon Sep 17 00:00:00 2001 From: truongpx-Mac Date: Wed, 18 Oct 2023 16:14:06 +0700 Subject: [PATCH] udpate --- Makefile | 70 +++ build/images/openim-cmdutils/Dockerfile | 7 +- jenkins-deploy/component/kafka.yaml | 67 ++ jenkins-deploy/component/minio.yaml | 70 +++ jenkins-deploy/component/mongo.yaml | 58 ++ jenkins-deploy/component/mysql.yaml | 50 ++ jenkins-deploy/component/mysql_dev.sql | 179 ++++++ jenkins-deploy/component/redis.yaml | 52 ++ jenkins-deploy/component/zookeeper.yaml | 48 ++ jenkins-deploy/dockerfile/api.Dockerfile | 19 + .../dockerfile/msg_gateway.Dockerfile | 20 + .../dockerfile/msg_transfer.Dockerfile | 18 + jenkins-deploy/dockerfile/push.Dockerfile | 19 + jenkins-deploy/dockerfile/rpc_auth.Dockerfile | 19 + .../dockerfile/rpc_conversation.Dockerfile | 20 + .../dockerfile/rpc_friend.Dockerfile | 19 + .../dockerfile/rpc_group.Dockerfile | 19 + jenkins-deploy/dockerfile/rpc_msg.Dockerfile | 20 + .../dockerfile/rpc_third.Dockerfile | 19 + jenkins-deploy/dockerfile/rpc_user.Dockerfile | 20 + jenkins-deploy/jenkinsfiles/api.jenkinsfile | 129 ++++ .../jenkinsfiles/gateway.jenkinsfile | 113 ++++ jenkins-deploy/jenkinsfiles/rpc.jenkinsfile | 114 ++++ jenkins-deploy/k8sdeployment_dev/api.yaml | 64 ++ .../default-configMap-test.yaml | 592 ++++++++++++++++++ .../default-namespace-test.yaml | 4 + .../k8sdeployment_dev/msg_gateway.yaml | 66 ++ .../k8sdeployment_dev/rpc_deployment.yaml | 59 ++ .../k8sdeployment_dev/transfer.yaml | 41 ++ 29 files changed, 1993 insertions(+), 2 deletions(-) create mode 100644 jenkins-deploy/component/kafka.yaml create mode 100644 jenkins-deploy/component/minio.yaml create mode 100644 jenkins-deploy/component/mongo.yaml create mode 100644 jenkins-deploy/component/mysql.yaml create mode 100644 jenkins-deploy/component/mysql_dev.sql create mode 100644 jenkins-deploy/component/redis.yaml create mode 100644 jenkins-deploy/component/zookeeper.yaml create mode 100644 jenkins-deploy/dockerfile/api.Dockerfile create mode 100644 jenkins-deploy/dockerfile/msg_gateway.Dockerfile create mode 100644 jenkins-deploy/dockerfile/msg_transfer.Dockerfile create mode 100644 jenkins-deploy/dockerfile/push.Dockerfile create mode 100644 jenkins-deploy/dockerfile/rpc_auth.Dockerfile create mode 100644 jenkins-deploy/dockerfile/rpc_conversation.Dockerfile create mode 100644 jenkins-deploy/dockerfile/rpc_friend.Dockerfile create mode 100644 jenkins-deploy/dockerfile/rpc_group.Dockerfile create mode 100644 jenkins-deploy/dockerfile/rpc_msg.Dockerfile create mode 100644 jenkins-deploy/dockerfile/rpc_third.Dockerfile create mode 100644 jenkins-deploy/dockerfile/rpc_user.Dockerfile create mode 100644 jenkins-deploy/jenkinsfiles/api.jenkinsfile create mode 100644 jenkins-deploy/jenkinsfiles/gateway.jenkinsfile create mode 100644 jenkins-deploy/jenkinsfiles/rpc.jenkinsfile create mode 100644 jenkins-deploy/k8sdeployment_dev/api.yaml create mode 100644 jenkins-deploy/k8sdeployment_dev/default-configMap-test.yaml create mode 100644 jenkins-deploy/k8sdeployment_dev/default-namespace-test.yaml create mode 100644 jenkins-deploy/k8sdeployment_dev/msg_gateway.yaml create mode 100644 jenkins-deploy/k8sdeployment_dev/rpc_deployment.yaml create mode 100644 jenkins-deploy/k8sdeployment_dev/transfer.yaml diff --git a/Makefile b/Makefile index 1d01409a5..68dc49dc0 100644 --- a/Makefile +++ b/Makefile @@ -244,3 +244,73 @@ help: Makefile .PHONY: help-all help-all: go.help copyright.help tools.help image.help dependencies.help gen.help release.help swagger.help help $(call makeallhelp) + +##### +##### +##### + +.PHONY:api +api: + @echo "${NOW} Starting to build api..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-api cmd/openim-api/main.go + +.PHONY:gateway +gateway: + @echo "${NOW} Starting to build gateway..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-msg-gateway cmd/openim-msggateway/main.go + +.PHONY:transfer +transfer: + @echo "${NOW} Starting to build transfer..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-msgtransfer cmd/openim-msgtransfer/main.go + +.PHONY:push +push: + @echo "${NOW} Starting to build push..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-push cmd/openim-push/main.go + +.PHONY:group +group: + @echo "${NOW} Starting to build rpc_group..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-group cmd/openim-rpc/openim-rpc-group/main.go + +.PHONY:msg +msg: + @echo "${NOW} Starting to build rpc_msg..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-msg cmd/openim-rpc/openim-rpc-msg/main.go + +.PHONY:user +user: + @echo "${NOW} Starting to build rpc_user..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-user cmd/openim-rpc/openim-rpc-user/main.go + +.PHONY:conversation +conversation: + @echo "${NOW} Starting to build rpc_conversation..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-conversation cmd/openim-rpc/openim-rpc-conversation/main.go + +.PHONY:friend +friend: + @echo "${NOW} Starting to build rpc_conversation..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-friend cmd/openim-rpc/openim-rpc-friend/main.go + +.PHONY:third +third: + @echo "${NOW} Starting to build rpc_conversation..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-third cmd/openim-rpc/openim-rpc-third/main.go + +.PHONY:auth +auth: + @echo "${NOW} Starting to build rpc_conversation..." + CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-auth cmd/openim-rpc/openim-rpc-auth/main.go + +.PHONY:build +build: api gateway transfer push group msg user conversation friend third auth + @echo "${NOW} Build done, files in ./bin as follow:" + @ls -l bin | grep openim- + +.PHONY:clean +clean: + @echo "${NOW} Starting to clean ..." + rm -rf bin/openim-* && rm -rf logs + @echo "${NOW} Clean done!" diff --git a/build/images/openim-cmdutils/Dockerfile b/build/images/openim-cmdutils/Dockerfile index 56923fe8a..0d6f1ca08 100644 --- a/build/images/openim-cmdutils/Dockerfile +++ b/build/images/openim-cmdutils/Dockerfile @@ -39,8 +39,11 @@ FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -COPY --from=builder $OPENIM_SERVER_BINDIR/platforms /openim/openim-server/_output/bin/platforms -COPY --from=builder ${SERVER_WORKDIR}/config /openim/openim-server/config +# COPY --from=builder $OPENIM_SERVER_BINDIR/platforms /openim/openim-server/_output/bin/platforms +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms +# COPY --from=builder ${SERVER_WORKDIR}/config /openim/openim-server/config +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-cmdutils /usr/bin/openim-cmdutils diff --git a/jenkins-deploy/component/kafka.yaml b/jenkins-deploy/component/kafka.yaml new file mode 100644 index 000000000..734978b10 --- /dev/null +++ b/jenkins-deploy/component/kafka.yaml @@ -0,0 +1,67 @@ +# kafka +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: social + name: kafka + labels: + app: kafka +spec: + replicas: 1 + selector: + matchLabels: + app: kafka + template: + metadata: + name: kafka + labels: + app: kafka + spec: + containers: + - name: kafka + image: wurstmeister/kafka + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9092 + protocol: TCP + env: + - name: KAFKA_BROKER_ID + value: "1" # Kafka Broker ID,从 0 开始递增 + - name: KAFKA_ZOOKEEPER_CONNECT + value: "zookeeper:30001" # 连接到 ZooKeeper 服务的地址 + - name: KAFKA_ADVERTISED_HOST_NAME + value: "kafka" + - name: KAFKA_ADVERTISED_PORT + value: "30032" + - name: KAFKA_CREATE_TOPICS + value: "latestMsgToRedis:8:1,msgToPush:8:1,offlineMsgToMongoMysql:8:1" +# - name: KAFKA_LISTENERS +# value: "INSIDE://:9092,OUTSIDE://:9093" +# - name: KAFKA_ADVERTISED_LISTENERS +# value: "INSIDE://:9092,OUTSIDE://:9093" +# - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP +# value: "INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" +# - name: KAFKA_INTER_BROKER_LISTENER_NAME +# value: "INSIDE" + restartPolicy: Always + +--- +apiVersion: v1 +kind: Service +metadata: + name: kafka + namespace: social + labels: + name: kafka +spec: + selector: + app: kafka + ports: + - protocol: TCP + port: 30032 + targetPort: 9092 + nodePort: 30032 + type: NodePort + sessionAffinity: None + \ No newline at end of file diff --git a/jenkins-deploy/component/minio.yaml b/jenkins-deploy/component/minio.yaml new file mode 100644 index 000000000..4761d8801 --- /dev/null +++ b/jenkins-deploy/component/minio.yaml @@ -0,0 +1,70 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: social + name: minio + labels: + app: minio +spec: + replicas: 1 + selector: + matchLabels: + app: minio + template: + metadata: + name: minio + labels: + app: minio + spec: + containers: + - name: minio + image: minio/minio + imagePullPolicy: IfNotPresent + env: + - name: MINIO_ROOT_USER + value: "root" + - name: MINIO_ROOT_PASSWORD + value: "openIM123" + args: + - server + - --console-address + - :9001 + - /data + ports: + - containerPort: 9000 + - containerPort: 9001 + readinessProbe: + httpGet: + path: /minio/health/ready + port: 9000 + initialDelaySeconds: 120 + periodSeconds: 20 + livenessProbe: + httpGet: + path: /minio/health/live + port: 9000 + initialDelaySeconds: 120 + periodSeconds: 20 + restartPolicy: Always + +--- +apiVersion: v1 +kind: Service +metadata: + name: social + namespace: social + labels: + name: social +spec: + selector: + app: social + ports: + - name: minio-dashboard + port: 30046 + targetPort: 9001 + nodePort: 30046 + - name: rpc + port: 30047 + targetPort: 9000 + nodePort: 30047 + type: NodePort \ No newline at end of file diff --git a/jenkins-deploy/component/mongo.yaml b/jenkins-deploy/component/mongo.yaml new file mode 100644 index 000000000..5dce03c60 --- /dev/null +++ b/jenkins-deploy/component/mongo.yaml @@ -0,0 +1,58 @@ +# mongo +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: social + name: mongo + labels: + app: mongo +spec: + replicas: 1 + selector: + matchLabels: + app: mongo + template: + metadata: + name: mongo + labels: + app: mongo + spec: + containers: + - name: mongo + image: mongo:6.0.2 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 27017 + protocol: TCP + env: + - name: MONGO_INITDB_ROOT_USERNAME + value: root + - name: MONGO_INITDB_ROOT_PASSWORD + value: openIM123 + - name: MONGO_INITDB_DATABASE + value: openIM_v3 + - name: MONGO_USERNAME + value: root + - name: MONGO_PASSWORD + value: openIM123 + restartPolicy: Always + +--- +apiVersion: v1 +kind: Service +metadata: + name: mongo + namespace: social + labels: + name: mongo +spec: + selector: + app: mongo + ports: + - protocol: TCP + port: 30007 + targetPort: 27017 + nodePort: 30007 + type: NodePort + sessionAffinity: None \ No newline at end of file diff --git a/jenkins-deploy/component/mysql.yaml b/jenkins-deploy/component/mysql.yaml new file mode 100644 index 000000000..656e09393 --- /dev/null +++ b/jenkins-deploy/component/mysql.yaml @@ -0,0 +1,50 @@ +#mysql +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql + labels: + app: mysql + namespace: social +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + name: mysql + labels: + app: mysql + spec: + containers: + - name: mysql + image: mysql:5.7 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 3306 + protocol: TCP + env: + - name: MYSQL_ROOT_PASSWORD + value: "openIM123" + restartPolicy: Always + +--- +apiVersion: v1 +kind: Service +metadata: + name: mysql + namespace: social + labels: + name: mysql +spec: + selector: + app: mysql + ports: + - protocol: TCP + port: 30006 + targetPort: 3306 + nodePort: 30006 + type: NodePort + sessionAffinity: None \ No newline at end of file diff --git a/jenkins-deploy/component/mysql_dev.sql b/jenkins-deploy/component/mysql_dev.sql new file mode 100644 index 000000000..49b86839d --- /dev/null +++ b/jenkins-deploy/component/mysql_dev.sql @@ -0,0 +1,179 @@ +create DATABASE if not exists openIM_v3; + +CREATE TABLE if not EXISTS `blacks` ( + `owner_user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `block_user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `create_time` datetime(3) DEFAULT NULL, + `add_source` int(11) DEFAULT NULL, + `operator_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ex` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`owner_user_id`,`block_user_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `chat_logs` ( + `server_msg_id` char(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `client_msg_id` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `send_id` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `recv_id` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `sender_platform_id` int(11) DEFAULT NULL, + `sender_nick_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `sender_face_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `session_type` int(11) DEFAULT NULL, + `msg_from` int(11) DEFAULT NULL, + `content_type` int(11) DEFAULT NULL, + `content` varchar(3000) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `status` int(11) DEFAULT NULL, + `send_time` datetime(3) DEFAULT NULL, + `create_time` datetime(3) DEFAULT NULL, + `ex` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + KEY `sendTime` (`send_time`), + KEY `send_id` (`send_time`,`send_id`), + KEY `recv_id` (`send_time`,`recv_id`), + KEY `session_type` (`send_time`,`session_type`), + KEY `session_type_alone` (`session_type`), + KEY `content_type` (`send_time`,`content_type`), + KEY `content_type_alone` (`content_type`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `conversations` ( + `owner_user_id` char(128) COLLATE utf8mb4_unicode_ci NOT NULL, + `conversation_id` char(128) COLLATE utf8mb4_unicode_ci NOT NULL, + `conversation_type` int(11) DEFAULT NULL, + `user_id` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `group_id` char(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `recv_msg_opt` int(11) DEFAULT NULL, + `is_pinned` tinyint(1) DEFAULT NULL, + `is_private_chat` tinyint(1) DEFAULT NULL, + `burn_duration` int(11) DEFAULT '30', + `group_at_type` int(11) DEFAULT NULL, + `attached_info` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ex` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `max_seq` bigint(20) DEFAULT NULL, + `min_seq` bigint(20) DEFAULT NULL, + `create_time` datetime(3) DEFAULT NULL, + `is_msg_destruct` tinyint(1) DEFAULT '0', + `msg_destruct_time` bigint(20) DEFAULT '604800', + `latest_msg_destruct_time` datetime(3) DEFAULT NULL, + PRIMARY KEY (`owner_user_id`,`conversation_id`), + KEY `create_time` (`create_time`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `friend_requests` ( + `from_user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `to_user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `handle_result` int(11) DEFAULT NULL, + `req_msg` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `create_time` datetime(3) DEFAULT NULL, + `handler_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `handle_msg` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `handle_time` datetime(3) DEFAULT NULL, + `ex` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`from_user_id`,`to_user_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `friends` ( + `owner_user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `friend_user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `remark` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `create_time` datetime(3) DEFAULT NULL, + `add_source` int(11) DEFAULT NULL, + `operator_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ex` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`owner_user_id`,`friend_user_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `group_members` ( + `group_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `nickname` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `user_group_face_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `role_level` int(11) DEFAULT NULL, + `join_time` datetime(3) DEFAULT NULL, + `join_source` int(11) DEFAULT NULL, + `inviter_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `operator_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `mute_end_time` datetime(3) DEFAULT NULL, + `ex` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`group_id`,`user_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `group_requests` ( + `user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `group_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `handle_result` int(11) DEFAULT NULL, + `req_msg` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `handle_msg` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `req_time` datetime(3) DEFAULT NULL, + `handle_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `handle_time` datetime(3) DEFAULT NULL, + `join_source` int(11) DEFAULT NULL, + `inviter_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ex` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`user_id`,`group_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `groups` ( + `group_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `notification` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `introduction` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `face_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `create_time` datetime(3) DEFAULT NULL, + `ex` longtext COLLATE utf8mb4_unicode_ci, + `status` int(11) DEFAULT NULL, + `creator_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `group_type` int(11) DEFAULT NULL, + `need_verification` int(11) DEFAULT NULL, + `look_member_info` int(11) DEFAULT NULL, + `apply_member_friend` int(11) DEFAULT NULL, + `notification_update_time` datetime(3) DEFAULT NULL, + `notification_user_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`group_id`), + KEY `create_time` (`create_time`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `object_hash` ( + `hash` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, + `engine` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL, + `size` bigint(20) DEFAULT NULL, + `bucket` longtext COLLATE utf8mb4_unicode_ci, + `name` longtext COLLATE utf8mb4_unicode_ci, + `create_time` datetime(3) DEFAULT NULL, + PRIMARY KEY (`hash`,`engine`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `object_info` ( + `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, + `hash` longtext COLLATE utf8mb4_unicode_ci, + `content_type` longtext COLLATE utf8mb4_unicode_ci, + `valid_time` datetime(3) DEFAULT NULL, + `create_time` datetime(3) DEFAULT NULL, + PRIMARY KEY (`name`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `object_put` ( + `put_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, + `hash` longtext COLLATE utf8mb4_unicode_ci, + `path` longtext COLLATE utf8mb4_unicode_ci, + `name` longtext COLLATE utf8mb4_unicode_ci, + `content_type` longtext COLLATE utf8mb4_unicode_ci, + `object_size` bigint(20) DEFAULT NULL, + `fragment_size` bigint(20) DEFAULT NULL, + `put_urls_hash` longtext COLLATE utf8mb4_unicode_ci, + `valid_time` datetime(3) DEFAULT NULL, + `effective_time` datetime(3) DEFAULT NULL, + `create_time` datetime(3) DEFAULT NULL, + PRIMARY KEY (`put_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE if not EXISTS `users` ( + `user_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `face_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ex` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `create_time` datetime(3) DEFAULT NULL, + `app_manger_level` int(11) DEFAULT '18', + `global_recv_msg_opt` int(11) DEFAULT NULL, + PRIMARY KEY (`user_id`), + KEY `create_time` (`create_time`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/jenkins-deploy/component/redis.yaml b/jenkins-deploy/component/redis.yaml new file mode 100644 index 000000000..b9f608bd1 --- /dev/null +++ b/jenkins-deploy/component/redis.yaml @@ -0,0 +1,52 @@ +# redis +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis + labels: + app: redis + namespace: social +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + name: redis + labels: + app: redis + spec: + containers: + - name: redis + image: redis:7.0.0 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 6379 + protocol: TCP + # env: + # - name: REDIS_PASSWORD + # value: "openIM123" + restartPolicy: Always + +--- +apiVersion: v1 +kind: Service +metadata: + name: redis + namespace: social + labels: + name: redis +spec: + selector: + app: redis + ports: + - protocol: TCP + port: 30029 + targetPort: 6379 + nodePort: 30029 + type: NodePort + sessionAffinity: None + + \ No newline at end of file diff --git a/jenkins-deploy/component/zookeeper.yaml b/jenkins-deploy/component/zookeeper.yaml new file mode 100644 index 000000000..e431bb1bd --- /dev/null +++ b/jenkins-deploy/component/zookeeper.yaml @@ -0,0 +1,48 @@ +#zk +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper + labels: + app: zookeeper + namespace: social +spec: + replicas: 1 + selector: + matchLabels: + app: zookeeper + template: + metadata: + name: zookeeper + labels: + app: zookeeper + spec: + containers: + - name: zookeeper:latest + image: wurstmeister/zookeeper + imagePullPolicy: IfNotPresent + ports: + - containerPort: 2181 + protocol: TCP + restartPolicy: Always + +--- +apiVersion: v1 +kind: Service +metadata: + name: zookeeper + namespace: social + labels: + name: zookeeper +spec: + selector: + app: zookeeper + ports: + - protocol: TCP + port: 30001 + targetPort: 2181 + nodePort: 30001 + type: NodePort + sessionAffinity: None + \ No newline at end of file diff --git a/jenkins-deploy/dockerfile/api.Dockerfile b/jenkins-deploy/dockerfile/api.Dockerfile new file mode 100644 index 000000000..0c7fe2e34 --- /dev/null +++ b/jenkins-deploy/dockerfile/api.Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make api + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10002 +CMD ["./bin/openim-api","--port", "10002"] diff --git a/jenkins-deploy/dockerfile/msg_gateway.Dockerfile b/jenkins-deploy/dockerfile/msg_gateway.Dockerfile new file mode 100644 index 000000000..7ae61dbad --- /dev/null +++ b/jenkins-deploy/dockerfile/msg_gateway.Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt && make tidy +RUN make gateway + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +#Copy binary files to the blank image +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10140 +EXPOSE 10001 +CMD ["./bin/openim-rpc-msg-gateway","--port", "10140","--ws_port", "10001"] diff --git a/jenkins-deploy/dockerfile/msg_transfer.Dockerfile b/jenkins-deploy/dockerfile/msg_transfer.Dockerfile new file mode 100644 index 000000000..c934437b7 --- /dev/null +++ b/jenkins-deploy/dockerfile/msg_transfer.Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt && make tidy +RUN make transfer + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +#Copy binary files to the blank image +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +CMD ["./bin/openim-msgtransfer"] diff --git a/jenkins-deploy/dockerfile/push.Dockerfile b/jenkins-deploy/dockerfile/push.Dockerfile new file mode 100644 index 000000000..a21033e22 --- /dev/null +++ b/jenkins-deploy/dockerfile/push.Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make push + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10170 +CMD ["./bin/openim-push","--port", "10170"] diff --git a/jenkins-deploy/dockerfile/rpc_auth.Dockerfile b/jenkins-deploy/dockerfile/rpc_auth.Dockerfile new file mode 100644 index 000000000..5b6b7d87f --- /dev/null +++ b/jenkins-deploy/dockerfile/rpc_auth.Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make auth + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10002 +CMD ["./bin/openim-api","--port", "10160"] diff --git a/jenkins-deploy/dockerfile/rpc_conversation.Dockerfile b/jenkins-deploy/dockerfile/rpc_conversation.Dockerfile new file mode 100644 index 000000000..fea26988a --- /dev/null +++ b/jenkins-deploy/dockerfile/rpc_conversation.Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make conversation + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10230 +CMD ["./bin/openim-rpc-conversation","--port", "10230"] + diff --git a/jenkins-deploy/dockerfile/rpc_friend.Dockerfile b/jenkins-deploy/dockerfile/rpc_friend.Dockerfile new file mode 100644 index 000000000..7b2da1e46 --- /dev/null +++ b/jenkins-deploy/dockerfile/rpc_friend.Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make friend + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10002 +CMD ["./bin/openim-api","--port", "10120"] diff --git a/jenkins-deploy/dockerfile/rpc_group.Dockerfile b/jenkins-deploy/dockerfile/rpc_group.Dockerfile new file mode 100644 index 000000000..9238ae18d --- /dev/null +++ b/jenkins-deploy/dockerfile/rpc_group.Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make group + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10150 +CMD ["./bin/openim-rpc-group","--port", "10150"] diff --git a/jenkins-deploy/dockerfile/rpc_msg.Dockerfile b/jenkins-deploy/dockerfile/rpc_msg.Dockerfile new file mode 100644 index 000000000..c3c82a309 --- /dev/null +++ b/jenkins-deploy/dockerfile/rpc_msg.Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make msg + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10130 +CMD ["./bin/openim-rpc-msg","--port", "10130"] + diff --git a/jenkins-deploy/dockerfile/rpc_third.Dockerfile b/jenkins-deploy/dockerfile/rpc_third.Dockerfile new file mode 100644 index 000000000..15e0a0cdc --- /dev/null +++ b/jenkins-deploy/dockerfile/rpc_third.Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make third + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10002 +CMD ["./bin/openim-api","--port", "10200"] diff --git a/jenkins-deploy/dockerfile/rpc_user.Dockerfile b/jenkins-deploy/dockerfile/rpc_user.Dockerfile new file mode 100644 index 000000000..a1dd49ece --- /dev/null +++ b/jenkins-deploy/dockerfile/rpc_user.Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.18.0 as build + +WORKDIR /openim +COPY . . + +RUN make fmt \ + && make tidy +RUN make user + +FROM ubuntu + +WORKDIR /openim +VOLUME ["/openim/logs","/openim/bin"] + +COPY --from=build /openim/bin /openim/bin +COPY --from=build /openim/config /openim/config + +EXPOSE 10110 +CMD ["./bin/openim-rpc-user","--port", "10110"] + diff --git a/jenkins-deploy/jenkinsfiles/api.jenkinsfile b/jenkins-deploy/jenkinsfiles/api.jenkinsfile new file mode 100644 index 000000000..c17eb5432 --- /dev/null +++ b/jenkins-deploy/jenkinsfiles/api.jenkinsfile @@ -0,0 +1,129 @@ +pipeline { + agent any + // agent { + // node { + // label 'jnlp-slave' + // } + // } + environment { + JOB_ENV = "social" // namespace + DEPLOYMENT_NAME = "api" // k8s deploy name + CONFIGMAP_NAME = "${DEPLOYMENT_NAME}-conf" // runtime conf + JOB_NAME = "${JOB_NAME}" // jenkins job name + GIT_URL = "https://github.com/truongpx396/k8s-jenkins" // gitlab or github codebase + CREDENTIALS_ID = "GitHub" // need configure it in jenkins, will use it's username and password to pull codebase + HARBOR_URL = "truongpx396" // docker harbor url + HARBOR_ID = "" // docker harbor id, will use it to login + DOCKER_CPU = "100m" + DOCKER_MEM = "200Mi" + BASEDIR = "." + BUILD_NUM = "${BUILD_NUMBER}" + CONF_PATH = "/openim/config/" + } + parameters { + gitParameter( + branch: '', + branchFilter: 'origin/(.*)', + defaultValue: 'main', + description: '', + name: 'RELEASE_BRANCH', + quickFilterEnabled: false, + selectedValue: 'NONE', + sortMode: 'NONE', + tagFilter: '*', + type: 'PT_BRANCH' + ) + extendedChoice( + name: "RELEASE_PROJECTS", + type: "PT_RADIO", + multiSelectDelimiter: " ", + value: """api,msg_gateway,msg_transfer,push,rpc_conversation,rpc_group,rpc_msg,rpc_user""", + defaultValue: "", + description: "please choice projects to deploy" + ) + } + stages { + stage('Git') { + steps { + checkout([$class: 'GitSCM', + branches: [[name: "${params.RELEASE_BRANCH}"]], + doGenerateSubmoduleConfigurations: false, + extensions: [], + gitTool: 'Default', + submoduleCfg: [], + userRemoteConfigs: [[url: "${GIT_URL}", credentialsId: "${CREDENTIALS_ID}"]] + ]) + } + } + stage('CommitHash') { + steps { + script { + env.CommitHash = sh (script: 'git rev-parse --short HEAD', returnStdout: true).trim() + } + } + } + stage('Check Param') { + steps { + script { + def releaseParams = "${params.RELEASE_PROJECTS}" + def tag = "${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM}" + def selectEnv = "${params.SERVICE_ENV}" + if(releaseParams) { + echo "=============================================" + echo "projects: $releaseParams" + echo "tag: $tag" + echo "selectEnv: $selectEnv" + echo "=============================================" + } else { + echo "=============================================" + echo "invalid release projects!!! stop now!!!" + } + } + } + } + stage('Docker Build') { + steps { + // container ('docker') { + // withCredentials([usernamePassword(credentialsId: "${HARBOR_ID}", passwordVariable: 'password', usernameVariable: 'username')]) { + // sh """ + // docker build -t ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} -f ${BASEDIR}/deploy/dockerfile/${params.RELEASE_PROJECTS}.Dockerfile . + // docker tag ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + + // docker login -u ${username} -p ${password} ${HARBOR_URL} + + // docker push ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + // docker rmi ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + // docker rmi ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + // """ + // } + // } + withDockerRegistry([ credentialsId: "DockerHub", url: "" ]){ + sh """ + echo `Build image ...` + docker build -t ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} -f ${BASEDIR}/dockerfile/${params.RELEASE_PROJECTS}.Dockerfile . + docker tag ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + + echo `Push image ...` + docker push ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + + echo `Start removing image ...1.` + docker rmi ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + docker rmi ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + echo `Done removing image!` + """ + } + } + } + // stage('Deploy') { + // steps { + // container ('helm-kubectl') { + // sh """ + // envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/default-configMap-test.yaml | kubectl apply -f - + // envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/default-namespace-test.yaml | kubectl apply -f - + // envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/api.yaml | kubectl apply -f - && kubectl rollout status -f - + // """ + // } + // } + // } + } +} \ No newline at end of file diff --git a/jenkins-deploy/jenkinsfiles/gateway.jenkinsfile b/jenkins-deploy/jenkinsfiles/gateway.jenkinsfile new file mode 100644 index 000000000..8dce04c3a --- /dev/null +++ b/jenkins-deploy/jenkinsfiles/gateway.jenkinsfile @@ -0,0 +1,113 @@ +pipeline { + agent { + node { + label 'jnlp-slave' + } + } + environment { + JOB_ENV = "social" // namespace + DEPLOYMENT_NAME = "gateway" // k8s deploy name + CONFIGMAP_NAME = "${DEPLOYMENT_NAME}-conf" // runtime conf + JOB_NAME = "${JOB_NAME}" // jenkins job name + GIT_URL = "" // gitlab or github codebase + CREDENTIALS_ID = "" // need configure it in jenkins, will use it's username and password to pull codebase + HARBOR_URL = "" // docker harbor url + HARBOR_ID = "" // docker harbor id, will use it to login + DOCKER_CPU = "100m" + DOCKER_MEM = "200Mi" + BASEDIR = "." + BUILD_NUM = "${BUILD_NUMBER}" + CONF_PATH = "/openim/config/" + } + parameters { + gitParameter( + branch: '', + branchFilter: 'origin/(.*)', + defaultValue: 'main', + description: '', + name: 'RELEASE_BRANCH', + quickFilterEnabled: false, + selectedValue: 'NONE', + sortMode: 'NONE', + tagFilter: '*', + type: 'PT_BRANCH' + ) + extendedChoice( + name: "RELEASE_PROJECTS", + type: "PT_RADIO", + multiSelectDelimiter: " ", + value: """api,msg_gateway,msg_transfer,push,rpc_conversation,rpc_group,rpc_msg,rpc_user""", + defaultValue: "", + description: "please choice projects to deploy" + ) + } + stages { + stage('Git') { + steps { + checkout([$class: 'GitSCM', + branches: [[name: "${params.RELEASE_BRANCH}"]], + doGenerateSubmoduleConfigurations: false, + extensions: [], + gitTool: 'Default', + submoduleCfg: [], + userRemoteConfigs: [[url: "${GIT_URL}", credentialsId: "${CREDENTIALS_ID}"]] + ]) + } + } + stage('CommitHash') { + steps { + script { + env.CommitHash = sh (script: 'git rev-parse --short HEAD', returnStdout: true).trim() + } + } + } + stage('Check Param') { + steps { + script { + def releaseParams = "${params.RELEASE_PROJECTS}" + def tag = "${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM}" + def selectEnv = "${params.SERVICE_ENV}" + if(releaseParams) { + echo "=============================================" + echo "projects: $releaseParams" + echo "tag: $tag" + echo "selectEnv: $selectEnv" + echo "=============================================" + } else { + echo "=============================================" + echo "invalid release projects!!! stop now!!!" + } + } + } + } + stage('Docker Build') { + steps { + container ('docker') { + withCredentials([usernamePassword(credentialsId: "${HARBOR_ID}", passwordVariable: 'password', usernameVariable: 'username')]) { + sh """ + docker build -t ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} -f ${BASEDIR}/deploy/dockerfile/${params.RELEASE_PROJECTS}.Dockerfile . + docker tag ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + + docker login -u ${username} -p ${password} ${HARBOR_URL} + + docker push ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + docker rmi ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + docker rmi ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + """ + } + } + } + } + stage('Deploy') { + steps { + container ('helm-kubectl') { + sh """ + envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/default-configMap-test.yaml | kubectl apply -f - + envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/default-namespace-test.yaml | kubectl apply -f - + envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/msg_gateway.yaml | kubectl apply -f - && kubectl rollout status -f - + """ + } + } + } + } +} diff --git a/jenkins-deploy/jenkinsfiles/rpc.jenkinsfile b/jenkins-deploy/jenkinsfiles/rpc.jenkinsfile new file mode 100644 index 000000000..194b4aa14 --- /dev/null +++ b/jenkins-deploy/jenkinsfiles/rpc.jenkinsfile @@ -0,0 +1,114 @@ +pipeline { + agent { + node { + label 'jnlp-slave' + } + } + environment { + JOB_ENV = "social" // namespace + DEPLOYMENT_NAME = "" // rpc server k8s deploy name, like user + CONFIGMAP_NAME = "${DEPLOYMENT_NAME}-conf" // runtime conf + JOB_NAME = "${JOB_NAME}" // jenkins job name + GIT_URL = "" // gitlab or github codebase + CREDENTIALS_ID = "" // need configure it in jenkins, will use it's username and password to pull codebase + HARBOR_URL = "" // docker harbor url + HARBOR_ID = "" // docker harbor id, will use it to login + DOCKER_CPU = "100m" + DOCKER_MEM = "200Mi" + BASEDIR = "." + BUILD_NUM = "${BUILD_NUMBER}" + CONF_PATH = "/openim/config/" + EXPOSED_PORT = "10110" // server port,will be container expose port + } + parameters { + gitParameter( + branch: '', + branchFilter: 'origin/(.*)', + defaultValue: 'main', + description: '', + name: 'RELEASE_BRANCH', + quickFilterEnabled: false, + selectedValue: 'NONE', + sortMode: 'NONE', + tagFilter: '*', + type: 'PT_BRANCH' + ) + extendedChoice( + name: "RELEASE_PROJECTS", + type: "PT_RADIO", + multiSelectDelimiter: " ", + value: """api,msg_gateway,msg_transfer,push,rpc_conversation,rpc_group,rpc_msg,rpc_user""", + defaultValue: "", + description: "please choice projects to deploy" + ) + } + stages { + stage('Git') { + steps { + checkout([$class: 'GitSCM', + branches: [[name: "${params.RELEASE_BRANCH}"]], + doGenerateSubmoduleConfigurations: false, + extensions: [], + gitTool: 'Default', + submoduleCfg: [], + userRemoteConfigs: [[url: "${GIT_URL}", credentialsId: "${CREDENTIALS_ID}"]] + ]) + } + } + stage('CommitHash') { + steps { + script { + env.CommitHash = sh (script: 'git rev-parse --short HEAD', returnStdout: true).trim() + } + } + } + stage('Check Param') { + steps { + script { + def releaseParams = "${params.RELEASE_PROJECTS}" + def tag = "${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM}" + def selectEnv = "${params.SERVICE_ENV}" + if(releaseParams) { + echo "=============================================" + echo "projects: $releaseParams" + echo "tag: $tag" + echo "selectEnv: $selectEnv" + echo "=============================================" + } else { + echo "=============================================" + echo "invalid release projects!!! stop now!!!" + } + } + } + } + stage('Docker Build') { + steps { + container ('docker') { + withCredentials([usernamePassword(credentialsId: "${HARBOR_ID}", passwordVariable: 'password', usernameVariable: 'username')]) { + sh """ + docker build -t ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} -f ${BASEDIR}/deploy/dockerfile/${params.RELEASE_PROJECTS}.Dockerfile . + docker tag ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + + docker login -u ${username} -p ${password} ${HARBOR_URL} + + docker push ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + docker rmi ${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + docker rmi ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + """ + } + } + } + } + stage('Deploy') { + steps { + container ('helm-kubectl') { + sh """ + envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/default-configMap-test.yaml | kubectl apply -f - + envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/default-namespace-test.yaml | kubectl apply -f - + envsubst < ${BASEDIR}/deploy/k8sdeployment_dev/rpc_deployment.yaml | kubectl apply -f - && kubectl rollout status -f - + """ + } + } + } + } +} diff --git a/jenkins-deploy/k8sdeployment_dev/api.yaml b/jenkins-deploy/k8sdeployment_dev/api.yaml new file mode 100644 index 000000000..608bbb58d --- /dev/null +++ b/jenkins-deploy/k8sdeployment_dev/api.yaml @@ -0,0 +1,64 @@ +# api.yaml +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: api + namespace: ${JOB_ENV} +spec: + replicas: 1 + selector: + matchLabels: + name: api + template: + metadata: + labels: + name: api + spec: + containers: + - name: api + image: ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + imagePullPolicy: Always + resources: + limits: + memory: "500Mi" + cpu: "80m" + requests: + memory: "200Mi" + cpu: "50m" + ports: + - containerPort: 10002 + name: api + protocol: TCP + volumeMounts: + - name: localtime + mountPath: /etc/localtime + - name: config + mountPath: ${CONF_PATH} + volumes: + - name: localtime + hostPath: + path: /usr/share/zoneinfo/UTC + - name: config + configMap: + name: ${CONFIGMAP_NAME} + restartPolicy: Always + +--- +# 外部访问的服务 +kind: Service +apiVersion: v1 +metadata: + labels: + name: api + name: api + namespace: ${JOB_ENV} +spec: + type: NodePort + ports: + - name: api + port: 10002 + targetPort: 10002 + nodePort: 30020 + selector: + name: api \ No newline at end of file diff --git a/jenkins-deploy/k8sdeployment_dev/default-configMap-test.yaml b/jenkins-deploy/k8sdeployment_dev/default-configMap-test.yaml new file mode 100644 index 000000000..8360a344d --- /dev/null +++ b/jenkins-deploy/k8sdeployment_dev/default-configMap-test.yaml @@ -0,0 +1,592 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: ${CONFIGMAP_NAME} + namespace: ${JOB_ENV} + labels: + app: ${CONFIGMAP_NAME} +data: + config.yaml: | + ################################################ + # 测试环境 + ################################################ + zookeeper: + schema: openim #不建议修改 + address: [ 127.0.0.1:30001 ] # + username: #用户名 + password: #密码 + + mysql: + address: [ 127.0.0.1:30006 ] #目前仅支持单机 + username: root #用户名 + password: openIM123 #密码 + database: openIM_v3 #不建议修改 + maxOpenConn: 1000 #最大连接数 + maxIdleConn: 100 #最大空闲连接数 + maxLifeTime: 60 #连接可以重复使用的最长时间(秒) + logLevel: 4 #日志级别 1=slient 2=error 3=warn 4=info + slowThreshold: 500 #慢语句阈值 (毫秒) + + mongo: + uri: #不为空则直接使用该值 + address: [ 127.0.0.1:30007 ] #单机时为mongo地址,使用分片集群时,为mongos地址 + database: openIM_v3 #mongo db 默认即可 + username: root #用户名 + password: openIM123 #密码 + maxPoolSize: 100 + + redis: + address: [ 127.0.0.1:30029 ] # + username: #only redis version 6.0+ need username + password: #密码 + + kafka: + username: #用户名 + password: #密码 + addr: [ 127.0.0.1:30032 ] # + latestMsgToRedis: + topic: "latestMsgToRedis" #不建议修改 + offlineMsgToMongo: + topic: "offlineMsgToMongoMysql" #不建议修改 + msgToPush: + topic: "msgToPush" #不建议修改 + consumerGroupID: #消费者组,不建议修改 + msgToRedis: redis # + msgToMongo: mongo # + msgToMySql: mysql # + msgToPush: push # + + + rpc: + registerIP: #作为rpc启动时,注册到zookeeper的IP,api/gateway能访问到此ip和对应的rpcPort中的端口 + listenIP: #默认为0.0.0.0 + + + api: + openImApiPort: [ 10002 ] #api服务端口 + listenIP: #默认为0.0.0.0 + + object: + enable: "minio" #使用minio + apiURL: "http://127.0.0.1:10002/object/" + minio: + bucket: "openim" #不建议修改 + endpoint: "http://127.0.0.1:10005" #minio对外服务的ip和端口,app要能访问此ip和端口 + accessKeyID: "root" #ID + secretAccessKey: "openIM123" #秘钥 + sessionToken: "" #token + cos: #tencent cos + bucketURL: "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" + secretID: "" + secretKey: "" + sessionToken: "" + oss: #ali oss + endpoint: "https://oss-cn-chengdu.aliyuncs.com" + bucket: "demo-9999999" + bucketURL: "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" + accessKeyID: "" + accessKeySecret: "" + sessionToken: "" + + rpcPort: #rpc服务端口,不建议修改,端口由脚本读取后传入程序,如启动多个程序,只需要填入多个端口,用逗号隔开,如 [10110, 10111] + openImUserPort: [ 10110 ] + openImFriendPort: [ 10120 ] + openImMessagePort: [ 10130 ] + openImMessageGatewayPort: [ 10140 ] + openImGroupPort: [ 10150 ] + openImAuthPort: [ 10160 ] + openImPushPort: [ 10170 ] + openImConversationPort: [ 10180 ] + openImThirdPort: [ 10190 ] + + rpcRegisterName: #rpc注册服务名,不建议修改 + openImUserName: User + openImFriendName: Friend + openImMsgName: Msg + openImPushName: Push + openImMessageGatewayName: MessageGateway + openImGroupName: Group + openImAuthName: Auth + openImConversationName: Conversation + openImThirdName: Third + + log: + storageLocation: ../../../../../logs/ #存放目录 + rotationTime: 24 #日志旋转时间 + remainRotationCount: 2 #日志数量 + remainLogLevel: 6 #日志级别 6表示全都打印, + isStdout: false + isJson: false + withStack: false + + longConnSvr: + openImWsPort: [ 10001 ] #msg_gateway的websocket端口 + websocketMaxConnNum: 100000 #websocket最大连接数 + websocketMaxMsgLen: 4096 #websocket请求包最大长度 + websocketTimeout: 10 #websocket连接握手超时时间 + + push: + enable: getui + geTui: #个推离线推送 + pushUrl: "https://restapi.getui.com/v2/$appId" + masterSecret: "" + appKey: "" + intent: "" + channelID: "" + channelName: "" + fcm: #fcm离线推送 + serviceAccount: "x.json" #帐号文件,并放在 config目录下 + jpns: #极光推送 在极光后台申请后,修改以下四项 + appKey: + masterSecret: + pushUrl: + pushIntent: + + manager: + userID: [ "openIM123456","openIM654321","openIMAdmin" ] #内置的app管理员userID + nickname: [ "system1","system2", "system3" ] #内置的app管理员nickname + + + + + multiLoginPolicy: 1 #多平台登录:Android、iOS、Windows、Mac、web 每种平台只能有一个在线 + + + chatPersistenceMysql: true #消息是否存入mysql,mysql中的消息仅用于管理后台使用 + msgCacheTimeout: 86400 #信消息缓存时间秒,不建议修改 + groupMessageHasReadReceiptEnable: true #群聊已读是否开启 + singleMessageHasReadReceiptEnable: true #单聊已读是否开启 + + retainChatRecords: 365 #mongo保存离线消息时间(天) + chatRecordsClearTime: "0 2 * * 3" #每周三凌晨2点清理mongo中的过期(超过retainChatRecords时间)消息,这个删除是为了清理满足上个配置retainChatRecords的过期消息,不会发送通知,仅仅作为清理磁盘使用 + msgDestructTime: "0 2 * * *" #消息自动删除时间,每天凌晨2点删除过期消息,这个删除是为了删除保留时间超过超过会话字段msg_destruct_time(秒)的消息。 + + secret: tuoyun #秘钥,获取token时校验 + + tokenPolicy: + expire: 90 #过期时间(天) + + messageVerify: + friendVerify: false #发送消息时是否验证好友关系 + + #ios系统推送声音以及标记计数 + iosPush: + pushSound: "xxx" + badgeCount: true + production: false + + callback: + # 回调callback + url: + beforeSendSingleMsg: + enable: false #是否启用此回调事件 + timeout: 5 #超时时间(秒) + failedContinue: true #如回调失败是否继续往后执行 + afterSendSingleMsg: + enable: false + timeout: 5 + beforeSendGroupMsg: + enable: false + timeout: 5 + failedContinue: true + afterSendGroupMsg: + enable: false + timeout: 5 + msgModify: + enable: false + timeout: 5 + failedContinue: true + userOnline: + enable: false + timeout: 5 + userOffline: + enable: false + timeout: 5 + userKickOff: + enable: false + timeout: 5 + offlinePush: + enable: false + timeout: 5 + failedContinue: true + onlinePush: + enable: false + timeout: 5 + failedContinue: true + superGroupOnlinePush: + enable: false + timeout: 5 + failedContinue: true + beforeAddFriend: + enable: false + timeout: 5 + failedContinue: true + beforeCreateGroup: + enable: false + timeout: 5 + failedContinue: true + beforeMemberJoinGroup: + enable: false + timeout: 5 + failedContinue: true + beforeSetGroupMemberInfo: + enable: false + timeout: 5 + failedContinue: true + setMessageReactionExtensions: + enable: false + timeout: 5 + failedContinue: true + + + prometheus: #prometheus每个服务的端口数量需要和rpcPort保持对应 + enable: false + userPrometheusPort: [ 20110 ] + friendPrometheusPort: [ 20120 ] + messagePrometheusPort: [ 20130 ] + messageGatewayPrometheusPort: [ 20140 ] + groupPrometheusPort: [ 20150 ] + authPrometheusPort: [ 20160 ] + pushPrometheusPort: [ 20170 ] + conversationPrometheusPort: [ 20230 ] + rtcPrometheusPort: [ 21300 ] + thirdPrometheusPort: [ 21301 ] + messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] #端口数量需要和script/path_info.sh中的msg_transfer_service_num保持一致 + notification.yaml: | + # Copyright © 2023 OpenIM. All rights reserved. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + + groupCreated: + isSendMsg: true #是否发送消息,false不发消息为无声的触发同步。true发消息需要触发会话,rpc notification直接发两次,一次消息一次通知, options字段isNotification是否为通知 + reliabilityLevel: 1 # 1为online才发送 2为必达 + unreadCount: false # 只在isSendMsg为true的情况下有作用 + offlinePush: + enable: false # 开启该开关 + title: "create group title" # xx create the group + desc: "create group desc" + ext: "create group ext" + + # 不加消息contentType,content统一json 结构体使用pb的 + + + groupInfoSet: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupInfoSet title" + desc: "groupInfoSet desc" + ext: "groupInfoSet ext" + + + joinGroupApplication: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "joinGroupApplication title" + desc: "joinGroupApplication desc" + ext: "joinGroupApplication ext" + + memberQuit: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "memberQuit title" + desc: "memberQuit desc" + ext: "memberQuit ext" + + groupApplicationAccepted: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupApplicationAccepted title" + desc: "groupApplicationAccepted desc" + ext: "groupApplicationAccepted ext" + + groupApplicationRejected: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: " title" + desc: " desc" + ext: " ext" + + + groupOwnerTransferred: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupOwnerTransferred title" + desc: "groupOwnerTransferred desc" + ext: "groupOwnerTransferred ext" + + memberKicked: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "memberKicked title" + desc: "memberKicked desc" + ext: "memberKicked ext" + + memberInvited: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "memberInvited title" + desc: "memberInvited desc" + ext: "memberInvited ext" + + memberEnter: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "memberEnter title" + desc: "memberEnter desc" + ext: "memberEnter ext" + + groupDismissed: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupDismissed title" + desc: "groupDismissed desc" + ext: "groupDismissed ext" + + groupMuted: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupMuted title" + desc: "groupMuted desc" + ext: "groupMuted ext" + + groupCancelMuted: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupCancelMuted title" + desc: "groupCancelMuted desc" + ext: "groupCancelMuted ext" + defaultTips: + tips: "group Cancel Muted" + + + groupMemberMuted: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupMemberMuted title" + desc: "groupMemberMuted desc" + ext: "groupMemberMuted ext" + + groupMemberCancelMuted: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupMemberCancelMuted title" + desc: "groupMemberCancelMuted desc" + ext: "groupMemberCancelMuted ext" + + groupMemberInfoSet: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupMemberInfoSet title" + desc: "groupMemberInfoSet desc" + ext: "groupMemberInfoSet ext" + + groupInfoSetAnnouncement: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupInfoSetAnnouncement title" + desc: "groupInfoSetAnnouncement desc" + ext: "groupInfoSetAnnouncement ext" + + + groupInfoSetName: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "groupInfoSetName title" + desc: "groupInfoSetName desc" + ext: "groupInfoSetName ext" + + + #############################friend################################# + friendApplicationAdded: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "Somebody applies to add you as a friend" + desc: "Somebody applies to add you as a friend" + ext: "Somebody applies to add you as a friend" + + friendApplicationApproved: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "Someone applies to add your friend application" + desc: "Someone applies to add your friend application" + ext: "Someone applies to add your friend application" + + friendApplicationRejected: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "Someone rejected your friend application" + desc: "Someone rejected your friend application" + ext: "Someone rejected your friend application" + + friendAdded: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "We have become friends" + desc: "We have become friends" + ext: "We have become friends" + + friendDeleted: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "deleted a friend" + desc: "deleted a friend" + ext: "deleted a friend" + + friendRemarkSet: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "Your friend's profile has been changed" + desc: "Your friend's profile has been changed" + ext: "Your friend's profile has been changed" + + blackAdded: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "blocked a user" + desc: "blocked a user" + ext: "blocked a user" + + blackDeleted: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "Remove a blocked user" + desc: "Remove a blocked user" + ext: "Remove a blocked user" + + friendInfoUpdated: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "friend info updated" + desc: "friend info updated" + ext: "friend info updated" + + #####################user######################### + userInfoUpdated: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "Remove a blocked user" + desc: "Remove a blocked user" + ext: "Remove a blocked user" + + #####################conversation######################### + conversationChanged: + isSendMsg: false + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "conversation changed" + desc: "conversation changed" + ext: "conversation changed" + + conversationSetPrivate: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: true + title: "burn after reading" + desc: "burn after reading" + ext: "burn after reading" + + #####################msg######################### + msgQuoteMember: + isSendMsg: true + reliabilityLevel: 1 + unreadCount: false + offlinePush: + enable: false + title: "your msg has been quote" + desc: "your msg has been quote" + ext: "your msg has been quote" diff --git a/jenkins-deploy/k8sdeployment_dev/default-namespace-test.yaml b/jenkins-deploy/k8sdeployment_dev/default-namespace-test.yaml new file mode 100644 index 000000000..f77742fdb --- /dev/null +++ b/jenkins-deploy/k8sdeployment_dev/default-namespace-test.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: ${JOB_ENV} \ No newline at end of file diff --git a/jenkins-deploy/k8sdeployment_dev/msg_gateway.yaml b/jenkins-deploy/k8sdeployment_dev/msg_gateway.yaml new file mode 100644 index 000000000..1d1b85eed --- /dev/null +++ b/jenkins-deploy/k8sdeployment_dev/msg_gateway.yaml @@ -0,0 +1,66 @@ +# msg-gateway.yaml +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: msg-gateway + namespace: ${JOB_ENV} +spec: + replicas: 1 + selector: + matchLabels: + name: msg-gateway + template: + metadata: + labels: + name: msg-gateway + spec: + containers: + - name: msg-gateway + image: ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + imagePullPolicy: Always + resources: + limits: + memory: "1024Mi" + cpu: "200m" + requests: + memory: "500Mi" + cpu: "50m" + ports: + - containerPort: 10001 + name: ws + protocol: TCP + - containerPort: 10140 + name: rpc + protocol: TCP + volumeMounts: + - name: localtime + mountPath: /etc/localtime + - name: config + mountPath: ${CONF_PATH} + volumes: + - name: localtime + hostPath: + path: /usr/share/zoneinfo/UTC + - name: config + configMap: + name: ${CONFIGMAP_NAME} + restartPolicy: Always +--- +# 外部访问的服务 +kind: Service +apiVersion: v1 +metadata: + labels: + name: msg-gateway + name: msg-gateway + namespace: ${JOB_ENV} +spec: + type: NodePort + ports: + - name: msg-gateway-ws + port: 10001 + targetPort: 10001 + nodePort: 30031 + selector: + name: msg-gateway \ No newline at end of file diff --git a/jenkins-deploy/k8sdeployment_dev/rpc_deployment.yaml b/jenkins-deploy/k8sdeployment_dev/rpc_deployment.yaml new file mode 100644 index 000000000..6454d97dd --- /dev/null +++ b/jenkins-deploy/k8sdeployment_dev/rpc_deployment.yaml @@ -0,0 +1,59 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ${DEPLOYMENT_NAME} + namespace: ${JOB_ENV} +spec: + replicas: 1 + selector: + matchLabels: + name: ${DEPLOYMENT_NAME} + template: + metadata: + labels: + name: ${DEPLOYMENT_NAME} + spec: + containers: + - name: ${DEPLOYMENT_NAME} + image: ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + imagePullPolicy: Always + resources: + limits: + memory: ${DOCKER_MEM} + cpu: ${DOCKER_CPU} + requests: + memory: 100Mi + cpu: 80m + ports: + - containerPort: ${EXPOSED_PORT} + protocol: TCP + livenessProbe: + tcpSocket: + port: ${EXPOSED_PORT} + initialDelaySeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + periodSeconds: 300 + readinessProbe: + tcpSocket: + port: ${EXPOSED_PORT} + initialDelaySeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + periodSeconds: 60 + volumeMounts: + - name: localtime + mountPath: /etc/localtime + - name: config + mountPath: ${CONF_PATH} + volumes: + - name: localtime + hostPath: + path: /usr/share/zoneinfo/UTC + - name: config + configMap: + name: ${CONFIGMAP_NAME} + restartPolicy: Always diff --git a/jenkins-deploy/k8sdeployment_dev/transfer.yaml b/jenkins-deploy/k8sdeployment_dev/transfer.yaml new file mode 100644 index 000000000..5c6acd0a5 --- /dev/null +++ b/jenkins-deploy/k8sdeployment_dev/transfer.yaml @@ -0,0 +1,41 @@ +# transfer don't need port, please handle it separately +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ${DEPLOYMENT_NAME} + namespace: ${JOB_ENV} +spec: + replicas: 1 + selector: + matchLabels: + name: ${DEPLOYMENT_NAME} + template: + metadata: + labels: + name: ${DEPLOYMENT_NAME} + spec: + containers: + - name: ${DEPLOYMENT_NAME} + image: ${HARBOR_URL}/${JOB_ENV}/${JOB_NAME}:${CommitHash}-${BUILD_NUM} + imagePullPolicy: Always + resources: + limits: + memory: ${DOCKER_MEM} + cpu: ${DOCKER_CPU} + requests: + memory: 100Mi + cpu: 80m + volumeMounts: + - name: localtime + mountPath: /etc/localtime + - name: config + mountPath: ${CONF_PATH} + volumes: + - name: localtime + hostPath: + path: /usr/share/zoneinfo/UTC + - name: config + configMap: + name: ${CONFIGMAP_NAME} + restartPolicy: Always