From 87766af02fb41fb004c720adf9fbb9ca84843562 Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751@qq.com> Date: Tue, 5 Sep 2023 16:31:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5Super=20feat:=20=20OpenIM=20CTL=20o?= =?UTF-8?q?ptimization=20is=20supported=20(#926)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add more test code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: init project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: init project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add versionchecker deploy Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: fix go work go version and build scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix actions no pass Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add test file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix chat bug Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: sava images file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add test file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set more help and port set Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: update slack link Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: update slack link Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: update openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set more help and port set Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: update openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: update openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker buildx images is openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker buildx images is openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: scripts fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: scripts fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: scripts fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set config file path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set config file path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set config file path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: docker compose Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: kafka environment port Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: kafka environment port Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: kafka environment port Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: kafka environment port Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * docs: fix docs link error issus:#968 Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * docs: add deployment docs Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more helm chart Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more helm chart Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: Optimize the functionality of iam Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: add iam super feat Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: add go format Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: add go format Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --------- Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .dockerignore | 1 + .env | 276 ++++++++++++- .github/sync-release.yml | 18 +- .github/workflows/auto-invite.yml | 4 +- .github/workflows/deploy.yml | 3 +- .github/workflows/docker-buildx.yml | 65 +++ .github/workflows/greetings.yml | 20 +- .github/workflows/help-comment-issue.yml | 4 +- .github/workflows/project-progress.yml | 2 +- .github/workflows/scripts-verify.yml | 4 +- .github/workflows/sync.yml | 4 - CONTRIBUTING.md | 8 +- Dockerfile | 4 +- Makefile | 15 +- README-zh_CN.md | 10 +- README.md | 56 ++- build/README.md | 65 +++ build/goreleaser.yaml | 151 ++++++- build/images/openim-api/Dockerfile | 5 +- build/images/openim-api/Dockerfile.release | 8 + build/images/openim-cmdutils/Dockerfile | 6 +- build/images/openim-crontask/Dockerfile | 6 +- build/images/openim-msggateway/Dockerfile | 8 +- build/images/openim-msgtransfer/Dockerfile | 7 +- build/images/openim-push/Dockerfile | 11 +- build/images/openim-rpc-auth/Dockerfile | 14 +- .../images/openim-rpc-conversation/Dockerfile | 21 +- build/images/openim-rpc-friend/Dockerfile | 21 +- build/images/openim-rpc-group/Dockerfile | 21 +- build/images/openim-rpc-msg/Dockerfile | 21 +- build/images/openim-rpc-third/Dockerfile | 21 +- build/images/openim-rpc-user/Dockerfile | 20 +- .../images/openim-tools/component/Dockerfile | 49 +++ .../images/openim-tools/openim-web/Dockerfile | 57 +++ cmd/openim-api/deploy.Dockerfile | 32 -- cmd/openim-crontask/deploy.Dockerfile | 32 -- cmd/openim-msggateway/deploy.Dockerfile | 32 -- cmd/openim-msgtransfer/deploy.Dockerfile | 32 -- cmd/openim-push/deploy.Dockerfile | 32 -- .../openim-rpc-auth/deploy.Dockerfile | 32 -- .../openim-rpc-conversation/deploy.Dockerfile | 32 -- .../openim-rpc-friend/deploy.Dockerfile | 32 -- .../openim-rpc-group/deploy.Dockerfile | 32 -- .../openim-rpc-msg/deploy.Dockerfile | 32 -- .../openim-rpc-third/deploy.Dockerfile | 32 -- .../openim-rpc-user/deploy.Dockerfile | 32 -- config/config-copy.yaml | 378 ------------------ config/config.yaml | 51 +-- deployments/README.md | 20 +- deployments/openim-chat/.helmignore | 23 ++ deployments/openim-chat/Chart.yaml | 38 ++ deployments/openim-chat/templates/NOTES.txt | 22 + .../openim-chat/templates/_helpers.tpl | 62 +++ .../openim-chat/templates/deployment.yaml | 75 ++++ deployments/openim-chat/templates/hpa.yaml | 42 ++ .../openim-chat/templates/ingress.yaml | 75 ++++ .../openim-chat/templates/service.yaml | 29 ++ .../openim-chat/templates/serviceaccount.yaml | 26 ++ deployments/openim-chat/values.yaml | 96 +++++ deployments/openim-server/.helmignore | 23 ++ deployments/openim-server/Chart.yaml | 38 ++ deployments/openim-server/templates/NOTES.txt | 22 + .../openim-server/templates/_helpers.tpl | 62 +++ .../openim-server/templates/deployment.yaml | 75 ++++ deployments/openim-server/templates/hpa.yaml | 42 ++ .../openim-server/templates/ingress.yaml | 75 ++++ .../openim-server/templates/service.yaml | 29 ++ .../templates/serviceaccount.yaml | 26 ++ deployments/openim-server/values.yaml | 96 +++++ deployments/templates/chat.yaml | 124 ++++++ deployments/templates/env_template.yaml | 262 +++++++++++- deployments/templates/init/README.md | 4 +- deployments/templates/openim.yaml | 2 +- docker-compose.yaml | 188 --------- docker-compose.yml | 267 +++++++++++++ docs/README.md | 67 ++++ docs/contrib/code_conventions.md | 2 +- docs/contrib/development.md | 12 +- docs/contrib/git_cherry-pick.md | 5 +- docs/contrib/offline-deployment.md | 116 ++++++ docs/conversions/github-workflow.md | 284 +++++++++++++ go.mod | 1 + go.work | 4 +- install.sh | 3 +- internal/msggateway/context.go | 3 + internal/msggateway/n_ws_server.go | 7 +- pkg/common/config/version | 2 +- pkg/common/http/http_client.go | 3 +- pkg/common/kafka/util.go | 14 + pkg/common/tls/tls.go | 14 + scripts/advertise.sh | 2 +- scripts/build-all-service.sh | 5 +- scripts/check-all.sh | 21 +- scripts/create_topic.sh | 27 ++ scripts/docker-start-all.sh | 12 +- .../githooks/{commit-msg => commit-msg.sh} | 0 scripts/init-config.sh | 29 +- scripts/init-env.sh | 2 + scripts/init-githooks.sh | 89 +++++ scripts/install/environment.sh | 307 +++++++++----- scripts/install/openim-api.sh | 2 +- scripts/install/openim-msggateway.sh | 30 +- scripts/install/openim-rpc.sh | 14 +- scripts/install/openim-tools.sh | 1 + scripts/lib/logging.sh | 2 +- scripts/lib/util.sh | 43 +- scripts/make-rules/common.mk | 4 - scripts/make-rules/gen.mk | 6 + scripts/start-all.sh | 9 +- scripts/stop-all.sh | 2 + scripts/template/footer.md.tmpl | 2 +- test/data-conversion/kafka-conversation.go | 9 +- test/data-conversion/mysql-conversion.go | 4 +- test/{README.md => readme} | 0 test/typecheck/go.mod | 2 +- tools/changelog/go.mod | 2 +- .../imctl.go => component/component_test.go} | 27 +- tools/component/go.mod | 2 +- tools/imctl/README.md | 47 --- tools/imctl/cmd/genman/README.md | 49 --- tools/imctl/cmd/genman/genman.go | 62 --- tools/imctl/go.mod | 19 - tools/imctl/go.sum | 26 -- tools/imctl/internal/imctl/cmd/cmd.go | 133 ------ tools/imctl/internal/imctl/cmd/profiling.go | 95 ----- .../imctl/util/interrupt/interrupt.go | 103 ----- .../imctl/util/templates/command_groups.go | 57 --- .../internal/imctl/util/templates/markdown.go | 149 ------- .../imctl/util/templates/normalizers.go | 99 ----- .../imctl/util/templates/templater.go | 296 -------------- .../imctl/util/templates/templates.go | 103 ----- .../imctl/internal/imctl/util/term/resize.go | 53 --- tools/imctl/internal/imctl/util/term/term.go | 37 -- .../internal/imctl/util/term/term_writer.go | 124 ------ .../imctl/util/term/term_writer_test.go | 114 ------ tools/infra/go.mod | 2 +- tools/ncpu/README.md | 8 - tools/ncpu/go.mod | 2 +- tools/openim-web/Dockerfile | 47 +++ tools/openim-web/README.md | 79 ++++ tools/openim-web/go.mod | 7 + tools/openim-web/go.sum | 10 + tools/openim-web/openim-web.go | 63 +++ tools/openim-web/openim-web_test.go | 71 ++++ tools/versionchecker/go.mod | 3 + tools/versionchecker/versionchecker.go | 115 ++++++ tools/yamlfmt/go.mod | 2 +- 147 files changed, 3863 insertions(+), 2966 deletions(-) create mode 100644 build/README.md create mode 100644 build/images/openim-api/Dockerfile.release create mode 100644 build/images/openim-tools/component/Dockerfile create mode 100644 build/images/openim-tools/openim-web/Dockerfile delete mode 100644 cmd/openim-api/deploy.Dockerfile delete mode 100644 cmd/openim-crontask/deploy.Dockerfile delete mode 100644 cmd/openim-msggateway/deploy.Dockerfile delete mode 100644 cmd/openim-msgtransfer/deploy.Dockerfile delete mode 100644 cmd/openim-push/deploy.Dockerfile delete mode 100644 cmd/openim-rpc/openim-rpc-auth/deploy.Dockerfile delete mode 100644 cmd/openim-rpc/openim-rpc-conversation/deploy.Dockerfile delete mode 100644 cmd/openim-rpc/openim-rpc-friend/deploy.Dockerfile delete mode 100644 cmd/openim-rpc/openim-rpc-group/deploy.Dockerfile delete mode 100644 cmd/openim-rpc/openim-rpc-msg/deploy.Dockerfile delete mode 100644 cmd/openim-rpc/openim-rpc-third/deploy.Dockerfile delete mode 100644 cmd/openim-rpc/openim-rpc-user/deploy.Dockerfile delete mode 100644 config/config-copy.yaml create mode 100644 deployments/openim-chat/.helmignore create mode 100644 deployments/openim-chat/Chart.yaml create mode 100644 deployments/openim-chat/templates/NOTES.txt create mode 100644 deployments/openim-chat/templates/_helpers.tpl create mode 100644 deployments/openim-chat/templates/deployment.yaml create mode 100644 deployments/openim-chat/templates/hpa.yaml create mode 100644 deployments/openim-chat/templates/ingress.yaml create mode 100644 deployments/openim-chat/templates/service.yaml create mode 100644 deployments/openim-chat/templates/serviceaccount.yaml create mode 100644 deployments/openim-chat/values.yaml create mode 100644 deployments/openim-server/.helmignore create mode 100644 deployments/openim-server/Chart.yaml create mode 100644 deployments/openim-server/templates/NOTES.txt create mode 100644 deployments/openim-server/templates/_helpers.tpl create mode 100644 deployments/openim-server/templates/deployment.yaml create mode 100644 deployments/openim-server/templates/hpa.yaml create mode 100644 deployments/openim-server/templates/ingress.yaml create mode 100644 deployments/openim-server/templates/service.yaml create mode 100644 deployments/openim-server/templates/serviceaccount.yaml create mode 100644 deployments/openim-server/values.yaml create mode 100644 deployments/templates/chat.yaml delete mode 100644 docker-compose.yaml create mode 100644 docker-compose.yml create mode 100644 docs/README.md create mode 100644 docs/contrib/offline-deployment.md create mode 100644 docs/conversions/github-workflow.md create mode 100755 scripts/create_topic.sh rename scripts/githooks/{commit-msg => commit-msg.sh} (100%) create mode 100755 scripts/init-githooks.sh rename test/{README.md => readme} (100%) rename tools/{imctl/cmd/imctl/imctl.go => component/component_test.go} (50%) delete mode 100644 tools/imctl/README.md delete mode 100644 tools/imctl/cmd/genman/README.md delete mode 100644 tools/imctl/cmd/genman/genman.go delete mode 100644 tools/imctl/go.mod delete mode 100644 tools/imctl/go.sum delete mode 100644 tools/imctl/internal/imctl/cmd/cmd.go delete mode 100644 tools/imctl/internal/imctl/cmd/profiling.go delete mode 100644 tools/imctl/internal/imctl/util/interrupt/interrupt.go delete mode 100644 tools/imctl/internal/imctl/util/templates/command_groups.go delete mode 100644 tools/imctl/internal/imctl/util/templates/markdown.go delete mode 100644 tools/imctl/internal/imctl/util/templates/normalizers.go delete mode 100644 tools/imctl/internal/imctl/util/templates/templater.go delete mode 100644 tools/imctl/internal/imctl/util/templates/templates.go delete mode 100644 tools/imctl/internal/imctl/util/term/resize.go delete mode 100644 tools/imctl/internal/imctl/util/term/term.go delete mode 100644 tools/imctl/internal/imctl/util/term/term_writer.go delete mode 100644 tools/imctl/internal/imctl/util/term/term_writer_test.go create mode 100644 tools/openim-web/Dockerfile create mode 100644 tools/openim-web/README.md create mode 100644 tools/openim-web/go.mod create mode 100644 tools/openim-web/go.sum create mode 100644 tools/openim-web/openim-web.go create mode 100644 tools/openim-web/openim-web_test.go create mode 100644 tools/versionchecker/go.mod create mode 100644 tools/versionchecker/versionchecker.go diff --git a/.dockerignore b/.dockerignore index d2e7354f5..c35303ed6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ # Ignore specific files .dockerignore +.git # Ignore build artifacts _output/ diff --git a/.env b/.env index 7ef344ac2..145d7e917 100644 --- a/.env +++ b/.env @@ -1,19 +1,265 @@ -# 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. +# ====================================== +# ========= Basic Configuration ======== +# ====================================== +# The user for authentication or system operations. +# Default: USER=root USER=root + +# Password associated with the specified user for authentication. +# Default: PASSWORD=openIM123 PASSWORD=openIM123 -MINIO_ENDPOINT=http://127.0.0.1:10005 -API_URL=http://127.0.0.1:10002 + +# Endpoint for the MinIO object storage service. +# Default: MINIO_ENDPOINT=http://172.28.0.1:10005 +MINIO_ENDPOINT=http://172.28.0.1:10005 + +# Base URL for the application programming interface (API). +# Default: API_URL=http://172.28.0.1:10002 +API_URL=http://172.28.0.1:10002 + +# Directory path for storing data files or related information. +# Default: DATA_DIR=./ DATA_DIR=./ + +# ====================================== +# ========= Network Configuration ====== +# ====================================== + +# Subnet for the Docker network. +# Default: DOCKER_BRIDGE_SUBNET=172.28.0.0/16 +DOCKER_BRIDGE_SUBNET=172.28.0.0/16 + +# Gateway for the Docker network. +# Default: DOCKER_BRIDGE_GATEWAY=172.28.0.1 +DOCKER_BRIDGE_GATEWAY=172.28.0.1 + +# Address or hostname for the MySQL network. +# Default: MYSQL_NETWORK_ADDRESS=172.28.0.2 +MYSQL_NETWORK_ADDRESS=172.28.0.2 + +# Address or hostname for the MongoDB network. +# Default: MONGO_NETWORK_ADDRESS=172.28.0.3 +MONGO_NETWORK_ADDRESS=172.28.0.3 + +# Address or hostname for the Redis network. +# Default: REDIS_NETWORK_ADDRESS=172.28.0.4 +REDIS_NETWORK_ADDRESS=172.28.0.4 + +# Address or hostname for the Kafka network. +# Default: KAFKA_NETWORK_ADDRESS=172.28.0.5 +KAFKA_NETWORK_ADDRESS=172.28.0.5 + +# Address or hostname for the ZooKeeper network. +# Default: ZOOKEEPER_NETWORK_ADDRESS=172.28.0.6 +ZOOKEEPER_NETWORK_ADDRESS=172.28.0.6 + +# Address or hostname for the MinIO network. +# Default: MINIO_NETWORK_ADDRESS=172.28.0.7 +MINIO_NETWORK_ADDRESS=172.28.0.7 + +# Address or hostname for the OpenIM web network. +# Default: OPENIM_WEB_NETWORK_ADDRESS=172.28.0.8 +OPENIM_WEB_NETWORK_ADDRESS=172.28.0.8 + +# Address or hostname for the OpenIM server network. +# Default: OPENIM_SERVER_NETWORK_ADDRESS=172.28.0.9 +OPENIM_SERVER_NETWORK_ADDRESS=172.28.0.9 + +# Address or hostname for the OpenIM chat network. +# Default: OPENIM_CHAT_NETWORK_ADDRESS=172.28.0.10 +OPENIM_CHAT_NETWORK_ADDRESS=172.28.0.10 + +# Address or hostname for the Prometheus network. +# Default: PROMETHEUS_NETWORK_ADDRESS=172.28.0.11 +PROMETHEUS_NETWORK_ADDRESS=172.28.0.11 + +# Address or hostname for the Grafana network. +# Default: GRAFANA_NETWORK_ADDRESS=172.28.0.12 +GRAFANA_NETWORK_ADDRESS=172.28.0.12 + + +# =============================================== +# = Component Extension Configuration = +# =============================================== + +# ============ Component Extension Configuration ========== +# ----- ZooKeeper Configuration ----- +# Address or hostname for the ZooKeeper service. +# Default: ZOOKEEPER_ADDRESS=172.28.0.1 +ZOOKEEPER_ADDRESS=172.28.0.6 + +# Port for ZooKeeper service. +# Default: ZOOKEEPER_PORT=12181 +ZOOKEEPER_PORT=12181 + +# ----- MySQL Configuration ----- + +# Address or hostname for the MySQL service. +# Default: MYSQL_ADDRESS=172.28.0.1 +MYSQL_ADDRESS=172.28.0.2 + +# Port on which MySQL database service is running. +# Default: MYSQL_PORT=13306 +MYSQL_PORT=13306 + +# Password to authenticate with the MySQL database service. +# Default: MYSQL_PASSWORD=openIM123 +MYSQL_PASSWORD=openIM123 + +# ----- MongoDB Configuration ----- +# Address or hostname for the MongoDB service. +# Default: MONGO_ADDRESS=172.28.0.1 +MONGO_ADDRESS=172.28.0.3 + +# Port on which MongoDB service is running. +# Default: MONGO_PORT=37017 +MONGO_PORT=37017 + +# Username to authenticate with the MongoDB service. +# Default: MONGO_USERNAME=root +MONGO_USERNAME=root + +# Password to authenticate with the MongoDB service. +# Default: MONGO_PASSWORD=openIM123 +MONGO_PASSWORD=openIM123 + +# Name of the database in MongoDB to be used. +# Default: MONGO_DATABASE=openIM_v3 +MONGO_DATABASE=openIM_v3 + +# ----- Redis Configuration ----- +# Address or hostname for the Redis service. +# Default: REDIS_ADDRESS=172.28.0.1 +REDIS_ADDRESS=172.28.0.4 + +# Port on which Redis in-memory data structure store is running. +# Default: REDIS_PORT=16379 +REDIS_PORT=16379 + +# Password to authenticate with the Redis service. +# Default: REDIS_PASSWORD=openIM123 +REDIS_PASSWORD=openIM123 + +# ----- Kafka Configuration ----- +# Address or hostname for the Kafka service. +# Default: KAFKA_ADDRESS=172.28.0.1 +KAFKA_ADDRESS=172.28.0.5 + +# Port on which Kafka distributed streaming platform is running. +# Default: KAFKA_PORT=19092 +KAFKA_PORT=19094 + +# Topic in Kafka for storing the latest messages in Redis. +# Default: KAFKA_LATESTMSG_REDIS_TOPIC=latestMsgToRedis +KAFKA_LATESTMSG_REDIS_TOPIC=latestMsgToRedis + +# Topic in Kafka for pushing messages (e.g. notifications or updates). +# Default: KAFKA_MSG_PUSH_TOPIC=msgToPush +KAFKA_MSG_PUSH_TOPIC=msgToPush + +# Topic in Kafka for storing offline messages in MongoDB. +# Default: KAFKA_OFFLINEMSG_MONGO_TOPIC=offlineMsgToMongoMysql +KAFKA_OFFLINEMSG_MONGO_TOPIC=offlineMsgToMongoMysql + +# ----- MinIO Configuration ---- +# Address or hostname for the MinIO object storage service. +# Default: MINIO_ADDRESS=172.28.0.1 +MINIO_ADDRESS=172.28.0.7 + +# Port on which MinIO object storage service is running. +# Default: MINIO_PORT=10005 +MINIO_PORT=10005 + +# Access key to authenticate with the MinIO service. +# Default: MINIO_ACCESS_KEY=root +MINIO_ACCESS_KEY=root + +# Secret key corresponding to the access key for MinIO authentication. +# Default: MINIO_SECRET_KEY=openIM123 +MINIO_SECRET_KEY=openIM123 + +# ----- Prometheus Configuration ----- +# Address or hostname for the Prometheus service. +# Default: PROMETHEUS_ADDRESS=172.28.0.1 +PROMETHEUS_ADDRESS=172.28.0.11 + +# Port on which Prometheus service is running. +# Default: PROMETHEUS_PORT=19090 +PROMETHEUS_PORT=19090 + +# ----- Grafana Configuration ----- +# Address or hostname for the Grafana service. +# Default: GRAFANA_ADDRESS=172.28.0.1 +GRAFANA_ADDRESS=172.28.0.12 + +# Port on which Grafana service is running. +# Default: GRAFANA_PORT=3000 +GRAFANA_PORT=3000 + +# ====================================== +# ============ OpenIM Web =============== +# ====================================== + +# Path to the OpenIM web distribution. +# Default: OPENIM_WEB_DIST_PATH=/app/dist +OPENIM_WEB_DIST_PATH=/app/dist + +# Port on which OpenIM web service is running. +# Default: OPENIM_WEB_PORT=11001 +OPENIM_WEB_PORT=11001 + +# Address or hostname for the OpenIM web service. +# Default: OPENIM_WEB_ADDRESS=172.28.0.1 +OPENIM_WEB_ADDRESS=172.28.0.8 + + +# ====================================== +# ========= OpenIM Server ============== +# ====================================== + +# Address or hostname for the OpenIM server. +# Default: OPENIM_SERVER_ADDRESS=172.28.0.1 +OPENIM_SERVER_ADDRESS=172.28.0.9 + +# Port for the OpenIM WebSockets. +# Default: OPENIM_WS_PORT=10001 +OPENIM_WS_PORT=10001 + +# Port for the OpenIM API. +# Default: API_OPENIM_PORT=10002 +API_OPENIM_PORT=10002 + + +# ====================================== +# ========== OpenIM Chat =============== +# ====================================== + +# Branch name for OpenIM chat. +# Default: CHAT_BRANCH=main +CHAT_BRANCH=main + +# Address or hostname for the OpenIM chat service. +# Default: OPENIM_CHAT_ADDRESS=172.28.0.1 +OPENIM_CHAT_ADDRESS=172.28.0.10 + +# Port for the OpenIM chat API. +# Default: OPENIM_CHAT_API_PORT=10008 +OPENIM_CHAT_API_PORT=10008 + +# Directory path for storing data files or related information for OpenIM chat. +# Default: OPENIM_CHAT_DATA_DIR=./openim-chat/main +OPENIM_CHAT_DATA_DIR=./openim-chat/main + + +# ====================================== +# ========== OpenIM Admin ============== +# ====================================== + +# Branch name for OpenIM server. +# Default: SERVER_BRANCH=main +SERVER_BRANCH=main + +# Port for the OpenIM admin API. +# Default: OPENIM_ADMIN_API_PORT=10009 +OPENIM_ADMIN_API_PORT=10009 diff --git a/.github/sync-release.yml b/.github/sync-release.yml index 9d111aefd..3800b4c24 100644 --- a/.github/sync-release.yml +++ b/.github/sync-release.yml @@ -1,3 +1,17 @@ +# 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. + OpenIMSDK/openim-docker: - source: ./config dest: ./openim-server/release/config @@ -10,7 +24,7 @@ OpenIMSDK/openim-docker: replace: true - source: ./scripts dest: ./scripts - replace: true + replace: false - source: ./Makefile dest: ./Makefile - replace: true + replace: false diff --git a/.github/workflows/auto-invite.yml b/.github/workflows/auto-invite.yml index 0fd9a4eab..79e84f301 100644 --- a/.github/workflows/auto-invite.yml +++ b/.github/workflows/auto-invite.yml @@ -34,11 +34,11 @@ jobs: body: | We value close connections with our users, developers, and contributors here at Open-IM-Server. With a large community and maintainer team, we're always here to help and support you. Whether you're looking to join our community or have any questions or suggestions, we welcome you to get in touch with us. - Our most recommended way to get in touch is through [Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg). Even if you're in China, Slack is usually not blocked by firewalls, making it an easy way to connect with us. Our Slack community is the ideal place to discuss and share ideas and suggestions with other users and developers of Open-IM-Server. You can ask technical questions, seek help, or share your experiences with other users of Open-IM-Server. + Our most recommended way to get in touch is through [Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q). Even if you're in China, Slack is usually not blocked by firewalls, making it an easy way to connect with us. Our Slack community is the ideal place to discuss and share ideas and suggestions with other users and developers of Open-IM-Server. You can ask technical questions, seek help, or share your experiences with other users of Open-IM-Server. In addition to Slack, we also offer the following ways to get in touch: - + We also have Slack channels for you to communicate and discuss. To join, visit https://slack.com/ and join our [👀 Open-IM-Server slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) team channel. + + We also have Slack channels for you to communicate and discuss. To join, visit https://slack.com/ and join our [👀 Open-IM-Server slack](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) team channel. + Get in touch with us on [Gmail](https://mail.google.com/mail/u/0/?fs=1&tf=cm&to=winxu81@gmail.com). If you have any questions or issues that need resolving, or any suggestions and feedback for our open source projects, please feel free to contact us via email. + Read our [blog](https://doc.rentsoft.cn/). Our blog is a great place to stay up-to-date with Open-IM-Server projects and trends. On the blog, we share our latest developments, tech trends, and other interesting information. + Add [Wechat](https://github.com/OpenIMSDK/OpenIM-Docs/blob/main/docs/images/WechatIMG20.jpeg) and indicate that you are a user or developer of Open-IM-Server. We will process your request as soon as possible. diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0efa1974b..e16297c4f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -51,4 +51,5 @@ jobs: echo "OWNER: $OWNER" echo "REPO: $REPO" git clone -b develop https://github.com/${OWNER}/${REPO}.git; cd ${REPO} - docker compose up -d \ No newline at end of file + docker compose up -d + continue-on-error: true \ No newline at end of file diff --git a/.github/workflows/docker-buildx.yml b/.github/workflows/docker-buildx.yml index 6ca47e924..9734e05e2 100644 --- a/.github/workflows/docker-buildx.yml +++ b/.github/workflows/docker-buildx.yml @@ -317,4 +317,69 @@ jobs: tags: ${{ steps.meta13.outputs.tags }} labels: ${{ steps.meta13.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + build-tools-ghcr: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + install: true + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker openim-web + id: meta1 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-web + + - name: Build and push Docker image for openim-web + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/images/openim-tools/openim-web/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta1.outputs.tags }} + labels: ${{ steps.meta1.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-web + id: meta2 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/component + + - name: Build and push Docker image for component + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/images/openim-tools/component/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta2.outputs.tags }} + labels: ${{ steps.meta2.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache \ No newline at end of file diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index 667b6af08..bed465cff 100644 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -28,13 +28,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/first-interaction@v1.1.1 with: - repo-token: ${{ secrets.REDBOT_GITHUB_TOKEN }} - issue-message: | - Hello! Thank you for filing an issue. - - If this is a bug report, please include relevant logs to help us debug the problem. - - [Join slack 🤖](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) to connect and communicate with our developers. + repo-token: ${{ secrets.BOT_GITHUB_TOKEN }} pr-message: | Hello! Thank you for your contribution. @@ -42,4 +36,14 @@ jobs: If you are implementing a feature request, please check with the maintainers that the feature will be accepted first. - [Join slack 🤖](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) to connect and communicate with our developers. \ No newline at end of file + [Join slack 🤖](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) to connect and communicate with our developers. + + Please leave your information in the [✨ discussions](https://github.com/orgs/OpenIMSDK/discussions/426), we expect anyone to join OpenIM developer community. + + issue-message: | + Hello! Thank you for filing an issue. + + If this is a bug report, please include relevant logs to help us debug the problem. + + [Join slack 🤖](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) to connect and communicate with our developers. + continue-on-error: true \ No newline at end of file diff --git a/.github/workflows/help-comment-issue.yml b/.github/workflows/help-comment-issue.yml index 755fb035d..73cf105a8 100644 --- a/.github/workflows/help-comment-issue.yml +++ b/.github/workflows/help-comment-issue.yml @@ -31,5 +31,5 @@ jobs: token: ${{ secrets.BOT_GITHUB_TOKEN }} body: | This issue is available for anyone to work on. **Make sure to reference this issue in your pull request.** :sparkles: Thank you for your contribution! :sparkles: - [Join slack 🤖](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) to connect and communicate with our developers. - If you wish to accept this assignment, please leave a comment in the comments section: `/accept`.🎯 \ No newline at end of file + [Join slack 🤖](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) to connect and communicate with our developers. + If you wish to accept this assignment, please leave a comment in the comments section: `/accept`.🎯 diff --git a/.github/workflows/project-progress.yml b/.github/workflows/project-progress.yml index d0cc10604..3ec8b7b1f 100644 --- a/.github/workflows/project-progress.yml +++ b/.github/workflows/project-progress.yml @@ -31,6 +31,6 @@ jobs: steps: - uses: alex-page/github-project-automation-plus@v0.8.3 with: - project: OpenIM-V3.1 + project: openim-powerful column: In Progress repo-token: ${{ secrets.BOT_GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/scripts-verify.yml b/.github/workflows/scripts-verify.yml index f3d885814..65d61d84b 100644 --- a/.github/workflows/scripts-verify.yml +++ b/.github/workflows/scripts-verify.yml @@ -68,7 +68,9 @@ jobs: - name: verify format run: | sudo make format + continue-on-error: true - name: verify license run: | - sudo make verify-copyright \ No newline at end of file + sudo make verify-copyright + continue-on-error: true \ No newline at end of file diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index b9e67d438..d6e15bf23 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -6,10 +6,6 @@ name: Synchronize kubecub public code to other repositories on: push: - paths: - - scripts/* - - docs/* - - config/* branches: - main workflow_dispatch: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 59c0c47db..a3ee8b8a6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,7 +72,7 @@ For any substantial design, there should be a well-crafted design document. This Anybody can access the shared Drive for reading. To get access to comment. Once you've done that, head to the [shared Drive](https://drive.google.com/) and behold all the docs. -In addition to that, we'd love to invite you to [join our Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) where you can play with your imagination, tell us what you're working on, and get a quick response. +In addition to that, we'd love to invite you to [join our Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) where you can play with your imagination, tell us what you're working on, and get a quick response. When documenting a new design, we recommend a 2-step approach: @@ -81,7 +81,7 @@ When documenting a new design, we recommend a 2-step approach: In order to contribute a feature to Open-IM-Server you'll need to go through the following steps: -+ Discuss your idea with the appropriate [working groups](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) on the working group's Slack channel. ++ Discuss your idea with the appropriate [working groups](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) on the working group's Slack channel. + Once there is general agreement that the feature is useful, create a GitHub issue to track the discussion. The issue should include information about the requirements and use cases that it is trying to address. + Include a discussion of the proposed design and technical details of the implementation in the issue. @@ -364,11 +364,11 @@ Such a commit can get produced as follows: We value close connections with our users, developers, and contributors here at Open-IM-Server. With a large community and maintainer team, we're always here to help and support you. Whether you're looking to join our community or have any questions or suggestions, we welcome you to get in touch with us. -Our most recommended way to get in touch is through [Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg). Even if you're in China, Slack is usually not blocked by firewalls, making it an easy way to connect with us. Our Slack community is the ideal place to discuss and share ideas and suggestions with other users and developers of Open-IM-Server. You can ask technical questions, seek help, or share your experiences with other users of Open-IM-Server. +Our most recommended way to get in touch is through [Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q). Even if you're in China, Slack is usually not blocked by firewalls, making it an easy way to connect with us. Our Slack community is the ideal place to discuss and share ideas and suggestions with other users and developers of Open-IM-Server. You can ask technical questions, seek help, or share your experiences with other users of Open-IM-Server. In addition to Slack, we also offer the following ways to get in touch: -+ : We also have Slack channels for you to communicate and discuss. To join, visit https://slack.com/ and join our [👀 Open-IM-Server slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) team channel. ++ : We also have Slack channels for you to communicate and discuss. To join, visit https://slack.com/ and join our [👀 Open-IM-Server slack](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) team channel. + : Get in touch with us on [Gmail](winxu81@gmail.com). If you have any questions or issues that need resolving, or any suggestions and feedback for our open source projects, please feel free to contact us via email. + : Read our [blog](https://doc.rentsoft.cn/). Our blog is a great place to stay up-to-date with Open-IM-Server projects and trends. On the blog, we share our latest developments, tech trends, and other interesting information. + : Add [Wechat](https://github.com/OpenIMSDK/OpenIM-Docs/blob/main/docs/images/WechatIMG20.jpeg) and indicate that you are a user or developer of Open-IM-Server. We will process your request as soon as possible. diff --git a/Dockerfile b/Dockerfile index ff5a3763e..5bd3930e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,8 @@ ENV GOPROXY=$GOPROXY # Set up the working directory WORKDIR /openim/openim-server -COPY go.mod go.sum go.work ./ -#RUN go mod download +COPY go.mod go.sum ./ +RUN go mod download # Copy all files to the container ADD . . diff --git a/Makefile b/Makefile index 7924599b4..e869ec111 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,16 @@ export USAGE_OPTIONS init: @$(MAKE) gen.init +## init-githooks: Initialize git hooks ✨ +.PHONY: init-githooks +init-githooks: + @$(MAKE) gen.init-githooks + +## gen: Generate all necessary files. ✨ +.PHONY: gen +gen: + @$(MAKE) gen.run + ## demo: Run demo get started with Makefiles quickly ✨ .PHONY: demo demo: @@ -190,11 +200,6 @@ push.multiarch: tools: @$(MAKE) tools.install -## gen: Generate all necessary files. ✨ -.PHONY: gen -gen: - @$(MAKE) gen.run - ## swagger: Generate swagger document. ✨ .PHONY: swagger swagger: diff --git a/README-zh_CN.md b/README-zh_CN.md index 3180b91f4..951112ae4 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -13,7 +13,7 @@ A+ good first - +

@@ -316,7 +316,7 @@ OpenIM 我们的目标是建立一个顶级的开源社区。我们有一套标 如果您想为这个 Open-IM-Server 仓库做贡献,请阅读我们的 [贡献者文档](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CONTRIBUTING.md)。 -在您开始之前,请确保您的更改是需要的。最好的方法是创建一个 [新的讨论](https://github.com/OpenIMSDK/Open-IM-Server/discussions/new/choose) 或 [Slack 通讯](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg),或者如果您发现一个问题,首先 [报告它](https://github.com/OpenIMSDK/Open-IM-Server/issues/new/choose)。 +在您开始之前,请确保您的更改是需要的。最好的方法是创建一个 [新的讨论](https://github.com/OpenIMSDK/Open-IM-Server/discussions/new/choose) 或 [Slack 通讯](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q),或者如果您发现一个问题,首先 [报告它](https://github.com/OpenIMSDK/Open-IM-Server/issues/new/choose)。 - [代码标准](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/go_code.md) - [Docker 图像标准](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) @@ -324,21 +324,21 @@ OpenIM 我们的目标是建立一个顶级的开源社区。我们有一套标 - [提交标准](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/commit.md) - [版本控制标准](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) - [接口标准](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/api.md) -- [日志标准](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/log.md) +- [日志标准](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/) - [错误代码标准](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/error_code.md) ## :busts_in_silhouette: 社区 - 📚 [OpenIM 社区](https://github.com/OpenIMSDK/community) - 💕 [OpenIM 兴趣小组](https://github.com/Openim-sigs) -- 🚀 [加入我们的 Slack 社区](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) +- 🚀 [加入我们的 Slack 社区](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) - :eyes: [加入我们的微信群 (微信群)](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg) ## :calendar: 社区会议 我们希望任何人都可以参与我们的社区并贡献代码,我们提供礼物和奖励,欢迎您每周四晚上加入我们。 -我们的会议在 [OpenIM Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) 🎯,然后您可以搜索 Open-IM-Server 管道加入。 +我们的会议在 [OpenIM Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) 🎯,然后您可以搜索 Open-IM-Server 管道加入。 我们在 [GitHub 讨论](https://github.com/OpenIMSDK/Open-IM-Server/discussions/categories/meeting) 中记下每次 [双周会议](https://github.com/orgs/OpenIMSDK/discussions/categories/meeting) 的笔记,我们的历史会议记录以及会议回放都可在 [Google Docs :bookmark_tabs:](https://docs.google.com/document/d/1nx8MDpuG74NASx081JcCpxPgDITNTpIIos0DS6Vr9GU/edit?usp=sharing) 中找到。 diff --git a/README.md b/README.md index 5a71bd527..e326e6486 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A+ good first - +

@@ -128,9 +128,7 @@ $ make demo ```bash -# choose what you need, We take branch 3.2 as an example -$ BRANCH=release-v3.2 -$ git clone -b $BRANCH https://github.com/OpenIMSDK/Open-IM-Server openim/openim-server && export openim_dir=$(pwd)/openim && cd ${openim_dir}/openim-server +git clone -b feat/test https://github.com/openim-sigs/openim-docker openim/openim-docker && export openim=$(pwd)/openim && cd $openim/openim-docker && ./scripts/init-config.sh && docker-compose up -d ``` > **Note** @@ -144,42 +142,36 @@ If you tried to get started quickly with `make demo`, then you know that our con You can use `make init` to quickly initialize a configuration file -```bash -$ make init -$ git diff -``` - -Then feel free to modify your current config file, you can also modify `/scripts/install/environment.sh` document template, `make init` is essentially rendering `environment.sh` template, and then through the `make init` to automatically generate a new configuration. - -If you only need to change the config file for a short time, or if you don't want to make any major changes in the future, you can modify the `.env file directly +Modify the automation script: ```bash -USER=root #no need to modify -PASSWORD=openIM123 #A combination of 8 or more numbers and letters, this password applies to redis, mysql, mongo, as well as accessSecret in config/config.yaml -ENDPOINT=http://127.0.0.1:10005 #minio's external service IP and port, or use the domain name storage.xx.xx, the app must be able to access this IP and port or domain, -API_URL=http://127.0.0.1:10002/object/ #the app must be able to access this IP and port or domain, -DATA_DIR=./ #designate large disk directory +cat scripts/install/environment.sh ``` -**3. Deploy and start** - -> **Note** -> -> You can deploy either directly with `make install` or with `docker compose up`, the logic is the same +1. Recommended using environment variables: ```bash -$ make install -# OR -$ docker-compose up +export PASSWORD="openIM123" # Set password +export USER="root" # Set username +# Choose chat version and server version https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md, eg: main, release-v*.* +export CHAT_BRANCH="main" +export SERVER_BRANCH="main" +#... Other environment variables +# MONGO_USERNAME: This sets the MongoDB username +# MONGO_PASSWORD: Set the MongoDB password +# MONGO_DATABASE: Sets the MongoDB database name +# MINIO_ENDPOINT: set the MinIO service address +# API_URL: under network environment, set OpenIM Server API address +export API_URL="http://127.0.0.1:10002" ``` -4. Check the service +Next, update the configuration using make init: ```bash -$ make check +$ make init +$ git diff ``` -Looking at the command line at this point, there are two items in the output, checking for the start of the component port that OpenIM depends on, and the start of the OpenIM core component @@ -349,7 +341,7 @@ OpenIM Our goal is to build a top-level open source community. We have a set of If you'd like to contribute to this Open-IM-Server repository, please read our [contributor documentation](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CONTRIBUTING.md). -Before you start, please make sure your changes are in demand. The best for that is to create a [new discussion](https://github.com/OpenIMSDK/Open-IM-Server/discussions/new/choose) OR [Slack Communication](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg), or if you find an issue, [report it](https://github.com/OpenIMSDK/Open-IM-Server/issues/new/choose) first. +Before you start, please make sure your changes are in demand. The best for that is to create a [new discussion](https://github.com/OpenIMSDK/Open-IM-Server/discussions/new/choose) OR [Slack Communication](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q), or if you find an issue, [report it](https://github.com/OpenIMSDK/Open-IM-Server/issues/new/choose) first. - [Code Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/go_code.md) - [Docker Images Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) @@ -357,21 +349,21 @@ Before you start, please make sure your changes are in demand. The best for that - [Commit Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/commit.md) - [Versioning Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) - [Interface Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/api.md) -- [Log Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/log.md) +- [Log Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/logging.md) - [Error Code Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/error_code.md) ## :busts_in_silhouette: Community + 📚 [OpenIM Community](https://github.com/OpenIMSDK/community) + 💕 [OpenIM Interest Group](https://github.com/Openim-sigs) -+ 🚀 [Join our Slack community](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) ++ 🚀 [Join our Slack community](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) + :eyes: [Join our wechat (微信群)](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg) ## :calendar: Community Meetings We want anyone to get involved in our community and contributing code, we offer gifts and rewards, and we welcome you to join us every Thursday night. -Our conference is in the [OpenIM Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) 🎯, then you can search the Open-IM-Server pipeline to join +Our conference is in the [OpenIM Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) 🎯, then you can search the Open-IM-Server pipeline to join We take notes of each [biweekly meeting](https://github.com/orgs/OpenIMSDK/discussions/categories/meeting) in [GitHub discussions](https://github.com/OpenIMSDK/Open-IM-Server/discussions/categories/meeting), Our historical meeting notes, as well as replays of the meetings are available at [Google Docs :bookmark_tabs:](https://docs.google.com/document/d/1nx8MDpuG74NASx081JcCpxPgDITNTpIIos0DS6Vr9GU/edit?usp=sharing). diff --git a/build/README.md b/build/README.md new file mode 100644 index 000000000..8da6082d9 --- /dev/null +++ b/build/README.md @@ -0,0 +1,65 @@ +# Building OpenIM + +Building OpenIM is easy if you take advantage of the containerized build environment. This document will help guide you through understanding this build process. + +## Requirements + +1. Docker, using one of the following configurations: + * **macOS** Install Docker for Mac. See installation instructions [here](https://docs.docker.com/docker-for-mac/). + **Note**: You will want to set the Docker VM to have at least 4GB of initial memory or building will likely fail. + * **Linux with local Docker** Install Docker according to the [instructions](https://docs.docker.com/installation/#installation) for your OS. + * **Windows with Docker Desktop WSL2 backend** Install Docker according to the [instructions](https://docs.docker.com/docker-for-windows/wsl-tech-preview/). Be sure to store your sources in the local Linux file system, not the Windows remote mount at `/mnt/c`. + + **Note**: You will need to check if Docker CLI plugin buildx is properly installed (`docker-buildx` file should be present in `~/.docker/cli-plugins`). You can install buildx according to the [instructions](https://github.com/docker/buildx/blob/master/README.md#installing). + +2. **Optional** [Google Cloud SDK](https://developers.google.com/cloud/sdk/) + +You must install and configure Google Cloud SDK if you want to upload your release to Google Cloud Storage and may safely omit this otherwise. + +## Actions + +About [Images packages](https://github.com/orgs/OpenIMSDK/packages?repo_name=Open-IM-Server) + +All files in the `build/images` directory are not templated and are instead rendered by Github Actions, which is an automated process. + +Trigger condition: +1. create a new tag with the format `vX.Y.Z` (e.g. `v1.0.0`) +2. push the tag to the remote repository +3. wait for the build to finish +4. download the artifacts from the release page + +## Make images + +**help info:** + +```bash +$ make image.help +``` + +**build images:** + +```bash +$ make image +``` + +## Overview + +While it is possible to build OpenIM using a local golang installation, we have a build process that runs in a Docker container. This simplifies initial set up and provides for a very consistent build and test environment. + + +## Basic Flow + +The scripts directly under [`build/`](.) are used to build and test. They will ensure that the `kube-build` Docker image is built (based on [`build/build-image/Dockerfile`](build-image/Dockerfile) and after base image's `KUBE_BUILD_IMAGE_CROSS_TAG` from Dockerfile is replaced with one of those actual tags of the base image, like `v1.13.9-2`) and then execute the appropriate command in that container. These scripts will both ensure that the right data is cached from run to run for incremental builds and will copy the results back out of the container. You can specify a different registry/name and version for `kube-cross` by setting `KUBE_CROSS_IMAGE` and `KUBE_CROSS_VERSION`, see [`common.sh`](common.sh) for more details. + +The `kube-build` container image is built by first creating a "context" directory in `_output/images/build-image`. It is done there instead of at the root of the OpenIM repo to minimize the amount of data we need to package up when building the image. + +There are 3 different containers instances that are run from this image. The first is a "data" container to store all data that needs to persist across to support incremental builds. Next there is an "rsync" container that is used to transfer data in and out to the data container. Lastly there is a "build" container that is used for actually doing build actions. The data container persists across runs while the rsync and build containers are deleted after each use. + +`rsync` is used transparently behind the scenes to efficiently move data in and out of the container. This will use an ephemeral port picked by Docker. You can modify this by setting the `KUBE_RSYNC_PORT` env variable. + +All Docker names are suffixed with a hash derived from the file path (to allow concurrent usage on things like CI machines) and a version number. When the version number changes all state is cleared and clean build is started. This allows the build infrastructure to be changed and signal to CI systems that old artifacts need to be deleted. + +## Build artifacts +The build system output all its products to a top level directory in the source repository named `_output`. +These include the binary compiled packages (e.g. kubectl, kube-scheduler etc.) and archived Docker images. +If you intend to run a component with a docker image you will need to import it from this directory with diff --git a/build/goreleaser.yaml b/build/goreleaser.yaml index 906f49d78..ecd031921 100644 --- a/build/goreleaser.yaml +++ b/build/goreleaser.yaml @@ -255,6 +255,134 @@ builds: - "6" - "7" + - binary: infra + id: infra + main: ./tools/infra/infra.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: ncpu + id: ncpu + main: ./tools/ncpu/ncpu.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-web + id: openim-web + main: ./tools/openim-web/openim-web.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: component + id: component + main: ./tools/component/component.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: versionchecker + id: versionchecker + main: ./tools/versionchecker/versionchecker.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: changelog + id: changelog + main: ./tools/changelog/changelog.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: yamlfmt + id: yamlfmt + main: ./tools/yamlfmt/yamlfmt.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + +# TODO:Need a script, such as the init - release to help binary to find the right directory +# ,which can be compiled binary archives: - format: tar.gz # this name template makes the OS and Arch compatible with the results of uname. @@ -265,12 +393,23 @@ archives: {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}v{{ .Arm }}{{ end }} + + # Set this to true if you want all files in the archive to be in a single directory. + # If set to true and you extract the archive 'goreleaser_Linux_arm64.tar.gz', + # you'll get a folder 'goreleaser_Linux_arm64'. + # If set to false, all files are extracted separately. + # You can also set it to a custom folder name (templating is supported). + wrap_in_directory: true + # use zip for windows archives files: - - LICENSE - - README.md - CHANGELOG/* - - CONTRIBUTING.md + - deployment/* + - config/* + - build/* + - scripts/* + - Makefile + - install.sh - docs/* - src: "*.md" dst: docs @@ -339,7 +478,9 @@ changelog: # - image_templates: # - "openimsdk/open-im-server:{{ .Tag }}-amd64" # - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" -# dockerfile: Dockerfile +# dockerfile: build/images/openim-api/Dockerfile.release +# ids: +# - openim-api # use: buildx # build_flag_templates: # - "--pull" @@ -359,7 +500,7 @@ changelog: # - image_templates: # - "goreleaser/goreleaser:{{ .Tag }}-arm64" # - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" -# dockerfile: Dockerfile +# dockerfile: build/images/openim-api/Dockerfile.release # use: buildx # build_flag_templates: # - "--pull" diff --git a/build/images/openim-api/Dockerfile b/build/images/openim-api/Dockerfile index 0d738e5bb..44d4c6ba4 100644 --- a/build/images/openim-api/Dockerfile +++ b/build/images/openim-api/Dockerfile @@ -43,7 +43,8 @@ COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-s COPY --from=builder /openim/openim-server/config /openim/openim-server/config ENV PORT 10002 +EXPOSE 10002 -EXPOSE ${PORT} +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-api /usr/bin/openim-api -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-api --port ${PORT} -c ${SERVER_WORKDIR}/config"] \ No newline at end of file +ENTRYPOINT ["bash", "-c", "openim-api -c $OPENIM_SERVER_CONFIG_NAME --port $PORT"] diff --git a/build/images/openim-api/Dockerfile.release b/build/images/openim-api/Dockerfile.release new file mode 100644 index 000000000..8d06221a7 --- /dev/null +++ b/build/images/openim-api/Dockerfile.release @@ -0,0 +1,8 @@ +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +COPY openim-api /usr/bin/ + +# nosemgrep: dockerfile.security.missing-user.missing-user +ENTRYPOINT ["/usr/bin/openim-api"] +# nosemgrep: dockerfile.security.missing-user.missing-user +CMD ["--help"] \ No newline at end of file diff --git a/build/images/openim-cmdutils/Dockerfile b/build/images/openim-cmdutils/Dockerfile index 47c4cf7be..56923fe8a 100644 --- a/build/images/openim-cmdutils/Dockerfile +++ b/build/images/openim-cmdutils/Dockerfile @@ -42,4 +42,8 @@ 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 -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-cmdutils"] +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-cmdutils /usr/bin/openim-cmdutils + +ENTRYPOINT ["openim-cmdutils"] + +CMD ["--help"] diff --git a/build/images/openim-crontask/Dockerfile b/build/images/openim-crontask/Dockerfile index b517c48ea..04334e4ff 100644 --- a/build/images/openim-crontask/Dockerfile +++ b/build/images/openim-crontask/Dockerfile @@ -41,4 +41,8 @@ WORKDIR /openim/openim-server COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms COPY --from=builder /openim/openim-server/config /openim/openim-server/config -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-crontask"] +ENV OPENIM_SERVER_CONFIG_NAME=/openim/openim-server/config + +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-crontask /usr/bin/openim-crontask + +CMD ["bash", "-c", "openim-crontask -c $OPENIM_SERVER_CONFIG_NAME"] diff --git a/build/images/openim-msggateway/Dockerfile b/build/images/openim-msggateway/Dockerfile index de6762114..35c4c7a1d 100644 --- a/build/images/openim-msggateway/Dockerfile +++ b/build/images/openim-msggateway/Dockerfile @@ -41,10 +41,12 @@ WORKDIR /openim/openim-server COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms COPY --from=builder /openim/openim-server/config /openim/openim-server/config -ENV OS ${OS} -ENV ARCH ${ARCH} +ENV PORT 10140 \ + WS_PORT 10001 EXPOSE 10140 EXPOSE 10001 -CMD ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-msggateway --port 10140 --ws_port 10001 \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-msggateway /usr/bin/openim-msggateway + +CMD ["bash", "-c", "openim-msggateway -c $OPENIM_SERVER_CONFIG_NAME --port $PORT --ws_port $WS_PORT"] \ No newline at end of file diff --git a/build/images/openim-msgtransfer/Dockerfile b/build/images/openim-msgtransfer/Dockerfile index 1f22b5c95..57d11be52 100644 --- a/build/images/openim-msgtransfer/Dockerfile +++ b/build/images/openim-msgtransfer/Dockerfile @@ -36,12 +36,11 @@ RUN make build BINS=openim-msgtransfer FROM ghcr.io/openim-sigs/openim-bash-image:latest -ENV OS ${OS} -ENV ARCH ${ARCH} - WORKDIR /openim/openim-server COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms COPY --from=builder /openim/openim-server/config /openim/openim-server/config -CMD ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-msgtransfer \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-msgtransfer /usr/bin/openim-msgtransfer + +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then openim-msgtransfer -c $OPENIM_SERVER_CONFIG_NAME --prometheus_port $PROMETHEUS_PORT; else openim-msgtransfer -c $OPENIM_SERVER_CONFIG_NAME; fi"] \ No newline at end of file diff --git a/build/images/openim-push/Dockerfile b/build/images/openim-push/Dockerfile index a5072bbb4..287c43450 100644 --- a/build/images/openim-push/Dockerfile +++ b/build/images/openim-push/Dockerfile @@ -15,6 +15,7 @@ # OpenIM base image: https://github.com/openim-sigs/openim-base-image # Set go mod installation source and proxy +# docker run -e "PORT=10003" -e "PROMETHEUSORT=4321" --network host -it 67ef891ad1ff FROM golang:1.20 AS builder @@ -38,12 +39,14 @@ FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -ENV OS ${OS} -ENV ARCH ${ARCH} - COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms COPY --from=builder /openim/openim-server/config /openim/openim-server/config +ENV PORT 10170 \ + PROMETHEUS_PORT 20170 + EXPOSE 10170 -CMD ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-push --port 10170 \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-push /usr/bin/openim-push + +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then openim-push -c $OPENIM_SERVER_CONFIG_NAME --port $PORT --prometheus_port $PROMETHEUS_PORT; else openim-push -c $OPENIM_SERVER_CONFIG_NAME --port $PORT; fi"] \ No newline at end of file diff --git a/build/images/openim-rpc-auth/Dockerfile b/build/images/openim-rpc-auth/Dockerfile index 427483db3..a581bfc04 100644 --- a/build/images/openim-rpc-auth/Dockerfile +++ b/build/images/openim-rpc-auth/Dockerfile @@ -33,20 +33,20 @@ COPY . . RUN make clean -# RUN make build BINS=openim-rpc - -RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth ./cmd/openim-rpc/openim-rpc-auth +RUN make build BINS=openim-rpc-auth FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -ENV OS ${OS} -ENV ARCH ${ARCH} - COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ COPY --from=builder /openim/openim-server/config /openim/openim-server/config +ENV PORT 10160 \ + PROMETHEUS_PORT 20160 + EXPOSE 10160 -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-auth --port 10160 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-auth /usr/bin/openim-rpc-auth + +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then "openim-rpc-auth --port $PORT -c $OPENIM_SERVER_CONFIG_NAME" --prometheus_port $PROMETHEUS_PORT; else "openim-rpc-auth --port $PORT -c $OPENIM_SERVER_CONFIG_NAME"; fi"] \ No newline at end of file diff --git a/build/images/openim-rpc-conversation/Dockerfile b/build/images/openim-rpc-conversation/Dockerfile index 1764a69df..887a77f36 100644 --- a/build/images/openim-rpc-conversation/Dockerfile +++ b/build/images/openim-rpc-conversation/Dockerfile @@ -33,27 +33,20 @@ COPY . . RUN make clean -RUN make build BINS=openim-rpc -# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation ./cmd/openim-rpc/openim-rpc-conversation - -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth +RUN make build BINS=openim-rpc-conversation FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -ENV OS ${OS} -ENV ARCH ${ARCH} - COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ COPY --from=builder /openim/openim-server/config /openim/openim-server/config +ENV PORT 10230 \ + PROMETHEUS_PORT 20230 + EXPOSE 10230 -EXPOSE 20230 -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-conversation --port 10230 --prometheus_port 20230 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-conversation /usr/bin/openim-rpc-conversation + +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then "openim-rpc-conversation --port $PORT -c $OPENIM_SERVER_CONFIG_NAME" --prometheus_port $PROMETHEUS_PORT; else "openim-rpc-conversation --port $PORT -c $OPENIM_SERVER_CONFIG_NAME"; fi"] \ No newline at end of file diff --git a/build/images/openim-rpc-friend/Dockerfile b/build/images/openim-rpc-friend/Dockerfile index efc34c4e5..9954daf99 100644 --- a/build/images/openim-rpc-friend/Dockerfile +++ b/build/images/openim-rpc-friend/Dockerfile @@ -33,27 +33,20 @@ COPY . . RUN make clean -RUN make build BINS=openim-rpc -# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend ./cmd/openim-rpc/openim-rpc-friend - -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth +RUN make build BINS=openim-rpc-friend FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -ENV OS ${OS} -ENV ARCH ${ARCH} - COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ COPY --from=builder /openim/openim-server/config /openim/openim-server/config +ENV PORT 10120 \ + PROMETHEUS_PORT 20120 + EXPOSE 10120 -EXPOSE 20120 -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-friend --port 10120 --prometheus_port 20120 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-friend /usr/bin/openim-rpc-friend + +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then "openim-rpc-friend --port $PORT -c $OPENIM_SERVER_CONFIG_NAME" --prometheus_port $PROMETHEUS_PORT; else "openim-rpc-friend --port $PORT -c $OPENIM_SERVER_CONFIG_NAME"; fi"] diff --git a/build/images/openim-rpc-group/Dockerfile b/build/images/openim-rpc-group/Dockerfile index 55a3a800c..627560075 100644 --- a/build/images/openim-rpc-group/Dockerfile +++ b/build/images/openim-rpc-group/Dockerfile @@ -33,27 +33,20 @@ COPY . . RUN make clean -RUN make build BINS=openim-rpc -# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group ./cmd/openim-rpc/openim-rpc-group - -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth +RUN make build BINS=openim-rpc-group FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -ENV OS ${OS} -ENV ARCH ${ARCH} - COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ COPY --from=builder /openim/openim-server/config /openim/openim-server/config +ENV PORT 10150 \ + PROMETHEUS_PORT 20150 + EXPOSE 10150 -EXPOSE 20150 -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-group --port 10150 --prometheus_port 20150 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-group /usr/bin/openim-rpc-group + +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then "openim-rpc-group --port $PORT -c $OPENIM_SERVER_CONFIG_NAME" --prometheus_port $PROMETHEUS_PORT; else "openim-rpc-group --port $PORT -c $OPENIM_SERVER_CONFIG_NAME"; fi"] \ No newline at end of file diff --git a/build/images/openim-rpc-msg/Dockerfile b/build/images/openim-rpc-msg/Dockerfile index 0058450e6..e7426bcf0 100644 --- a/build/images/openim-rpc-msg/Dockerfile +++ b/build/images/openim-rpc-msg/Dockerfile @@ -33,27 +33,20 @@ COPY . . RUN make clean -RUN make build BINS=openim-rpc -# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg ./cmd/openim-rpc/openim-rpc-msg - -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth +RUN make build BINS=openim-rpc-msg FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -ENV OS ${OS} -ENV ARCH ${ARCH} - COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ COPY --from=builder /openim/openim-server/config /openim/openim-server/config +ENV PORT 10130 \ + PROMETHEUS_PORT 20130 + EXPOSE 10130 -EXPOSE 20130 -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-msg --port 10130 --prometheus_port 20130 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-msg /usr/bin/openim-rpc-msg + +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then "openim-rpc-msg --port $PORT -c $OPENIM_SERVER_CONFIG_NAME" --prometheus_port $PROMETHEUS_PORT; else "openim-rpc-msg --port $PORT -c $OPENIM_SERVER_CONFIG_NAME"; fi"] \ No newline at end of file diff --git a/build/images/openim-rpc-third/Dockerfile b/build/images/openim-rpc-third/Dockerfile index f1d5fcc8c..700fd2918 100644 --- a/build/images/openim-rpc-third/Dockerfile +++ b/build/images/openim-rpc-third/Dockerfile @@ -33,26 +33,21 @@ COPY . . RUN make clean -RUN make build BINS=openim-rpc -# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third ./cmd/openim-rpc/openim-rpc-third +RUN make build BINS=openim-rpc-third -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -ENV OS ${OS} -ENV ARCH ${ARCH} - COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ COPY --from=builder /openim/openim-server/config /openim/openim-server/config -EXPOSE 10200 +ENV PORT 10190 \ + PROMETHEUS_PORT 21301 + +EXPOSE 10190 + +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-third /usr/bin/openim-rpc-third -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-third --port 10200 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then "openim-rpc-third --port $PORT -c $OPENIM_SERVER_CONFIG_NAME" --prometheus_port $PROMETHEUS_PORT; else "openim-rpc-third --port $PORT -c $OPENIM_SERVER_CONFIG_NAME"; fi"] diff --git a/build/images/openim-rpc-user/Dockerfile b/build/images/openim-rpc-user/Dockerfile index 338bf1305..00804f2bf 100644 --- a/build/images/openim-rpc-user/Dockerfile +++ b/build/images/openim-rpc-user/Dockerfile @@ -33,26 +33,20 @@ COPY . . RUN make clean -RUN make build BINS=openim-rpc -# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user ./cmd/openim-rpc/openim-rpc-user - -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ - rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth +RUN make build BINS=openim-rpc-user FROM ghcr.io/openim-sigs/openim-bash-image:latest WORKDIR /openim/openim-server -ENV OS ${OS} -ENV ARCH ${ARCH} - COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ COPY --from=builder /openim/openim-server/config /openim/openim-server/config +ENV PORT 10110 \ + PROMETHEUS_PORT 20110 + EXPOSE 10110 -CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-user --port 10110 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-rpc-user /usr/bin/openim-rpc-user + +ENTRYPOINT ["bash", "-c", "if [[ -n $PROMETHEUS_PORT ]]; then "openim-rpc-user --port $PORT -c $OPENIM_SERVER_CONFIG_NAME" --prometheus_port $PROMETHEUS_PORT; else "openim-rpc-user --port $PORT -c $OPENIM_SERVER_CONFIG_NAME"; fi"] diff --git a/build/images/openim-tools/component/Dockerfile b/build/images/openim-tools/component/Dockerfile new file mode 100644 index 000000000..1be6e776f --- /dev/null +++ b/build/images/openim-tools/component/Dockerfile @@ -0,0 +1,49 @@ +# 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. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean +RUN make build BINS=component + +# FROM ghcr.io/openim-sigs/openim-bash-image:latest +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +COPY --from=builder /openim/openim-server/_output/bin/tools /openim/openim-server/_output/bin/tools/ +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +ENV OPENIM_SERVER_CONFIG_NAME=/openim/openim-server/config + +RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/component /usr/bin/component + +ENTRYPOINT ["bash", "-c", "component -c $OPENIM_SERVER_CONFIG_NAME"] diff --git a/build/images/openim-tools/openim-web/Dockerfile b/build/images/openim-tools/openim-web/Dockerfile new file mode 100644 index 000000000..77ca4cf49 --- /dev/null +++ b/build/images/openim-tools/openim-web/Dockerfile @@ -0,0 +1,57 @@ +# 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. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +RUN apt-get update && apt-get install -y curl unzip + +RUN curl -LO https://app-1302656840.cos.ap-nanjing.myqcloud.com/dist.zip \ + && unzip dist.zip -d ./ \ + && rm dist.zip + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean +RUN make build BINS=openim-web + +FROM ghcr.io/openim-sigs/openim-ubuntu-image:latest + +WORKDIR /openim/openim-server + +COPY --from=builder /openim/openim-server/_output/bin/tools /openim/openim-server/_output/bin/tools/ +COPY --from=builder /openim/openim-server/dist /openim/openim-server/dist + +ENV PORT 11001 +ENV DISTPATH /openim/openim-server/dist + +EXPOSE 11001 + +RUN mv ${OPENIM_SERVER_BINDIR}/tools/$(get_os)/$(get_arch)/openim-web /usr/bin/openim-web + +ENTRYPOINT ["bash", "-c", "openim-web -port $PORT -distPath $DISTPATH"] \ No newline at end of file diff --git a/cmd/openim-api/deploy.Dockerfile b/cmd/openim-api/deploy.Dockerfile deleted file mode 100644 index 56dd4a106..000000000 --- a/cmd/openim-api/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-api ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-api","--port", "10002"] diff --git a/cmd/openim-crontask/deploy.Dockerfile b/cmd/openim-crontask/deploy.Dockerfile deleted file mode 100644 index 9ada56d26..000000000 --- a/cmd/openim-crontask/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-crontask ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-crontask"] diff --git a/cmd/openim-msggateway/deploy.Dockerfile b/cmd/openim-msggateway/deploy.Dockerfile deleted file mode 100644 index 31a30ff4b..000000000 --- a/cmd/openim-msggateway/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-rpc-msg_gateway ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-rpc-msg_gateway","--port", "10140" "--ws_port", "10001", "--prometheus_port", "20240"] diff --git a/cmd/openim-msgtransfer/deploy.Dockerfile b/cmd/openim-msgtransfer/deploy.Dockerfile deleted file mode 100644 index 7eedcbdbc..000000000 --- a/cmd/openim-msgtransfer/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-msgtransfer ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-msgtransfer","--prometheus_port", "21400"] diff --git a/cmd/openim-push/deploy.Dockerfile b/cmd/openim-push/deploy.Dockerfile deleted file mode 100644 index 6e4e44525..000000000 --- a/cmd/openim-push/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-push ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-push", "--port", "10170", "--prometheus_port", "20170"] diff --git a/cmd/openim-rpc/openim-rpc-auth/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-auth/deploy.Dockerfile deleted file mode 100644 index 6d034303c..000000000 --- a/cmd/openim-rpc/openim-rpc-auth/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-rpc-auth ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-rpc-auth", "--port", "10160"] diff --git a/cmd/openim-rpc/openim-rpc-conversation/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-conversation/deploy.Dockerfile deleted file mode 100644 index 8245e3ca1..000000000 --- a/cmd/openim-rpc/openim-rpc-conversation/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-rpc-conversation ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-rpc-conversation", "--port", "10230", "--prometheus_port","20230"] diff --git a/cmd/openim-rpc/openim-rpc-friend/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-friend/deploy.Dockerfile deleted file mode 100644 index 5f842a631..000000000 --- a/cmd/openim-rpc/openim-rpc-friend/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-rpc-friend ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-rpc-friend", "--port", "10120", "--prometheus_port","20120"] diff --git a/cmd/openim-rpc/openim-rpc-group/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-group/deploy.Dockerfile deleted file mode 100644 index 42fe164df..000000000 --- a/cmd/openim-rpc/openim-rpc-group/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-rpc-group ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-rpc-group", "--port", "10150", "--prometheus_port","20150"] diff --git a/cmd/openim-rpc/openim-rpc-msg/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-msg/deploy.Dockerfile deleted file mode 100644 index 754d782a0..000000000 --- a/cmd/openim-rpc/openim-rpc-msg/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-rpc-msg ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-rpc-msg", "--port", "10130", "--prometheus_port","20130"] diff --git a/cmd/openim-rpc/openim-rpc-third/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-third/deploy.Dockerfile deleted file mode 100644 index 664ad452c..000000000 --- a/cmd/openim-rpc/openim-rpc-third/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-rpc-third ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-rpc-third", "--port", "10200"] diff --git a/cmd/openim-rpc/openim-rpc-user/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-user/deploy.Dockerfile deleted file mode 100644 index f9663c9ba..000000000 --- a/cmd/openim-rpc/openim-rpc-user/deploy.Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -FROM ubuntu - -WORKDIR /openim/openim-server/bin - -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl -COPY ./openim-rpc-user ./ - -VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] - -CMD ["./openim-rpc-user", "--port", "10110"] diff --git a/config/config-copy.yaml b/config/config-copy.yaml deleted file mode 100644 index 27f01fb8b..000000000 --- a/config/config-copy.yaml +++ /dev/null @@ -1,378 +0,0 @@ -# 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. - -# ----------------------------------------------------------------- -# Infrastructural configurations, please modify based on your setup -# ----------------------------------------------------------------- - -###################### Zookeeper ###################### -# Zookeeper configuration -# It's not recommended to modify the schema -# -# Zookeeper address -# Zookeeper username -# Zookeeper password -zookeeper: - schema: openim - address: [ 127.0.0.1:2181 ] - username: - password: - -###################### Mysql ###################### -# MySQL configuration -# Currently, only single machine setup is supported -# -# Maximum number of open connections -# Maximum number of idle connections -# Maximum lifetime in seconds a connection can be reused -# Log level: 1=slient, 2=error, 3=warn, 4=info -# Slow query threshold in milliseconds -mysql: - address: [ 127.0.0.1:13306 ] - username: root - password: openIM123 - database: openIM_v3 - maxOpenConn: 1000 - maxIdleConn: 100 - maxLifeTime: 60 - logLevel: 4 - slowThreshold: 500 - -###################### Mongo ###################### -# MongoDB configuration -# If uri is not empty, it will be used directly -# -# MongoDB address for standalone setup, Mongos address for sharded cluster setup -# Default MongoDB database name -# Maximum connection pool size -mongo: - uri: - address: [ 127.0.0.1:37017 ] - database: openIM_v3 - username: root - password: openIM123 - maxPoolSize: 100 - -###################### Redis ###################### -# Redis configuration -# -# Username is required only for Redis version 6.0+ -redis: - address: [ 127.0.0.1:16379 ] - username: - password: openIM123 - -###################### Kafka ###################### -# Kafka configuration -# -# Kafka username -# Kafka password -# It's not recommended to modify this topic name -# Consumer group ID, it's not recommended to modify -kafka: - username: - password: - addr: [ 127.0.0.1:9092 ] - latestMsgToRedis: - topic: "latestMsgToRedis" - offlineMsgToMongo: - topic: "offlineMsgToMongoMysql" - msgToPush: - topic: "msgToPush" - consumerGroupID: - msgToRedis: redis - msgToMongo: mongo - msgToMySql: mysql - msgToPush: push - -###################### RPC ###################### -# RPC configuration -# -# IP address to register with zookeeper when starting RPC, the IP and corresponding rpcPort should be accessible by api/gateway -# Default listen IP is 0.0.0.0 -rpc: - registerIP: - listenIP: 0.0.0.0 - -###################### API ###################### -# API configuration -# -# API service port -# Default listen IP is 0.0.0.0 -api: - openImApiPort: [ 10002 ] - listenIP: 0.0.0.0 - -###################### Gateway ###################### -# Object storage configuration -# -# Use minio for object storage -# API URL should be accessible by the app -# It's not recommended to modify the bucket name -# Endpoint should be accessible by the app -# Session token -# Configuration for Tencent COS -# Configuration for Aliyun OSS -# apiURL is the address of the api, the access address of the app, use s3 must be configured -# minio.endpoint can be configured as an intranet address, -# minio.signEndpoint is minio public network address -object: - enable: "minio" - apiURL: "http://127.0.0.1:10002" - minio: - bucket: "openim" - endpoint: "http://127.0.0.1:10005" - accessKeyID: "root" - secretAccessKey: "openIM123" - sessionToken: "" - signEndpoint: "http://127.0.0.1:10005" - cos: - bucketURL: "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" - secretID: "" - secretKey: "" - sessionToken: "" - oss: - endpoint: "https://oss-cn-chengdu.aliyuncs.com" - bucket: "demo-9999999" - bucketURL: "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" - accessKeyID: "" - accessKeySecret: "" - sessionToken: "" - -# RPC service ports -# These ports are passed into the program by the script and are not recommended to modify -# For launching multiple programs, just fill in multiple ports separated by commas -# For example, [10110, 10111] -rpcPort: - openImUserPort: [ 10110 ] - openImFriendPort: [ 10120 ] - openImMessagePort: [ 10130 ] - openImMessageGatewayPort: [ 10140 ] - openImGroupPort: [ 10150 ] - openImAuthPort: [ 10160 ] - openImPushPort: [ 10170 ] - openImConversationPort: [ 10180 ] - openImThirdPort: [ 10190 ] - -# RPC service names for registration, it's not recommended to modify these -rpcRegisterName: - openImUserName: User - openImFriendName: Friend - openImMsgName: Msg - openImPushName: Push - openImMessageGatewayName: MessageGateway - openImGroupName: Group - openImAuthName: Auth - openImConversationName: Conversation - openImThirdName: Third - -# Log configuration -# -# Storage directory -# Log rotation time -# Maximum number of logs to retain -# Log level, 6 means all levels -# Whether to output to stdout -# Whether to output in json format -# Whether to include stack trace in logs -log: - storageLocation: ../../../../../logs/ - rotationTime: 24 - remainRotationCount: 2 - remainLogLevel: 6 - isStdout: false - isJson: false - withStack: false - -# Long connection server configuration -# -# Websocket port for msg_gateway -# Maximum number of websocket connections -# Maximum length of websocket request package -# Websocket connection handshake timeout -longConnSvr: - openImWsPort: [ 10001 ] - websocketMaxConnNum: 100000 - websocketMaxMsgLen: 4096 - websocketTimeout: 10 - -# Push notification service configuration -# -# Use GeTui for push notifications -# GeTui offline push configuration -# FCM offline push configuration -# Account file, place it in the config directory -# JPush configuration, modify these after applying in JPush backend -push: - enable: getui - geTui: - pushUrl: "https://restapi.getui.com/v2/$appId" - masterSecret: "" - appKey: "" - intent: "" - channelID: "" - channelName: "" - fcm: - serviceAccount: "x.json" - jpns: - appKey: - masterSecret: - pushUrl: - pushIntent: - -# App manager configuration -# -# Built-in app manager user IDs -# Built-in app manager nicknames -manager: - userID: [ "openIM123456","openIM654321","openIMAdmin" ] - nickname: [ "system1","system2", "system3" ] - -# Multi-platform login policy -# For each platform(Android, iOS, Windows, Mac, web), only one can be online at a time -multiLoginPolicy: 1 - -# Whether to store messages in MySQL, messages in MySQL are only used for management background -chatPersistenceMysql: true - -# Message cache timeout in seconds, it's not recommended to modify -msgCacheTimeout: 86400 - -# Whether to enable read receipts for group chat -groupMessageHasReadReceiptEnable: true - -# Whether to enable read receipts for single chat -singleMessageHasReadReceiptEnable: true - -# MongoDB offline message retention period in days -retainChatRecords: 365 - -# Schedule to clear expired messages(older than retainChatRecords days) in MongoDB every Wednesday at 2am -# This deletion is just for cleaning up disk usage according to previous configuration retainChatRecords, no notification will be sent -chatRecordsClearTime: "0 2 * * 3" - -# Schedule to auto delete messages every day at 2am -# This deletion is for messages that have been retained for more than msg_destruct_time (seconds) in the conversation field -msgDestructTime: "0 2 * * *" - -# Secret key -secret: openIM123 - -# Token policy -# -# Token expiration period in days -tokenPolicy: - expire: 90 - -# Message verification policy -# -# Whether to verify friendship when sending messages -messageVerify: - friendVerify: false - -# iOS push notification configuration -# -# iOS push notification sound -# Whether to count badge -# Whether it's production environment -iosPush: - pushSound: "xxx" - badgeCount: true - production: false - -# Callback configuration -# -# Callback URL -# Whether to enable this callback event -# Timeout in seconds -# Whether to continue execution if callback fails -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 configuration -# The number of Prometheus ports per service needs to correspond to rpcPort -# The number of ports needs to be consistent with msg_transfer_service_num in script/path_info.sh -prometheus: - 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 ] \ No newline at end of file diff --git a/config/config.yaml b/config/config.yaml index c23b094ff..c8c994c36 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -28,9 +28,9 @@ # Zookeeper password zookeeper: schema: openim - address: [ 127.0.0.1:2181 ] - username: - password: + address: [ 172.28.0.1:12181 ] + username: '' + password: '' ###################### Mysql ###################### # MySQL configuration @@ -42,7 +42,7 @@ zookeeper: # Log level: 1=slient, 2=error, 3=warn, 4=info # Slow query threshold in milliseconds mysql: - address: [ 127.0.0.1:13306 ] + address: [ 172.28.0.1:13306 ] username: root password: openIM123 database: openIM_v3 @@ -60,8 +60,8 @@ mysql: # Default MongoDB database name # Maximum connection pool size mongo: - uri: - address: [ 127.0.0.1:37017 ] + uri: '' + address: [ 172.28.0.1:37017 ] database: openIM_v3 username: root password: openIM123 @@ -72,8 +72,8 @@ mongo: # # Username is required only for Redis version 6.0+ redis: - address: [ 127.0.0.1:16379 ] - username: + address: [ 172.28.0.1:16379 ] + username: '' password: openIM123 ###################### Kafka configuration information ###################### @@ -84,9 +84,9 @@ redis: # It's not recommended to modify this topic name # Consumer group ID, it's not recommended to modify kafka: - username: - password: - addr: [ 127.0.0.1:9092 ] + username: '' + password: '' + addr: [ 172.28.0.1:19094 ] latestMsgToRedis: topic: "latestMsgToRedis" offlineMsgToMongo: @@ -105,7 +105,7 @@ kafka: # IP address to register with zookeeper when starting RPC, the IP and corresponding rpcPort should be accessible by api/gateway # Default listen IP is 0.0.0.0 rpc: - registerIP: + registerIP: '' listenIP: 0.0.0.0 ###################### API configuration information ###################### @@ -132,26 +132,27 @@ api: # minio.signEndpoint is minio public network address object: enable: "minio" - apiURL: "http://127.0.0.1:10002" + apiURL: "http://14.153.6.114:10002" minio: bucket: "openim" - endpoint: "http://127.0.0.1:10005" + endpoint: "http://172.28.0.1:10005" accessKeyID: "root" secretAccessKey: "openIM123" - sessionToken: "" - signEndpoint: "http://127.0.0.1:10005" + sessionToken: '' + signEndpoint: "http://14.153.6.114:10005" cos: - bucketURL: "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" - secretID: "" - secretKey: "" - sessionToken: "" + bucketURL: https://temp-1252357374.cos.ap-chengdu.myqcloud.com + secretID: '' + secretKey: '' + sessionToken: '' oss: endpoint: "https://oss-cn-chengdu.aliyuncs.com" bucket: "demo-9999999" bucketURL: "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" - accessKeyID: "" - accessKeySecret: "" - sessionToken: "" + accessKeyID: '' + accessKeySecret: '' + sessionToken: '' + ###################### RPC Port Configuration ###################### # RPC service ports @@ -193,11 +194,11 @@ rpcRegisterName: # Whether to output in json format # Whether to include stack trace in logs log: - storageLocation: ../../../../../logs/ + storageLocation: ../logs rotationTime: 24 remainRotationCount: 2 remainLogLevel: 6 - isStdout: false + isStdout: false isJson: false withStack: false diff --git a/deployments/README.md b/deployments/README.md index dd59f09cf..4e4beda9f 100644 --- a/deployments/README.md +++ b/deployments/README.md @@ -19,13 +19,27 @@ Kubernetes: >= 1.16.0-0 Helm: >= 3.0 ``` -假设 OpenIM 项目根目录路径为 `OpenIM_ROOT` -进入 OpenIM 项目根目录 +### 最低配置 -$ cd ${OpenIM_ROOT} +建议生产环境的最低配置如下: +```bash +CPU: 4 +Memory: 8G +Disk: 100G +``` + +## 生成配置文件 +我们将自动文件全部自动化处理了,所以生成配置文件对于 openim 来说是可选的,但是如果你想要自定义配置,可以参考下面的步骤: + +```bash +$ make init +# 或者是使用脚本: +# ./scripts/init-config.sh +``` +此时会帮你在 `deployments/openim/config` 目录下生成配置文件,你可以根据自己的需求进行修改。 ### 容器化安装 diff --git a/deployments/openim-chat/.helmignore b/deployments/openim-chat/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/deployments/openim-chat/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/deployments/openim-chat/Chart.yaml b/deployments/openim-chat/Chart.yaml new file mode 100644 index 000000000..4466fc928 --- /dev/null +++ b/deployments/openim-chat/Chart.yaml @@ -0,0 +1,38 @@ +# 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. + +apiVersion: v2 +name: openim-chat +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/deployments/openim-chat/templates/NOTES.txt b/deployments/openim-chat/templates/NOTES.txt new file mode 100644 index 000000000..17cfb43fe --- /dev/null +++ b/deployments/openim-chat/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "openim-chat.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "openim-chat.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "openim-chat.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "openim-chat.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/deployments/openim-chat/templates/_helpers.tpl b/deployments/openim-chat/templates/_helpers.tpl new file mode 100644 index 000000000..3177accfb --- /dev/null +++ b/deployments/openim-chat/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "openim-chat.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "openim-chat.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "openim-chat.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "openim-chat.labels" -}} +helm.sh/chart: {{ include "openim-chat.chart" . }} +{{ include "openim-chat.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "openim-chat.selectorLabels" -}} +app.kubernetes.io/name: {{ include "openim-chat.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "openim-chat.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "openim-chat.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deployments/openim-chat/templates/deployment.yaml b/deployments/openim-chat/templates/deployment.yaml new file mode 100644 index 000000000..47d88c590 --- /dev/null +++ b/deployments/openim-chat/templates/deployment.yaml @@ -0,0 +1,75 @@ +# 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. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "openim-chat.fullname" . }} + labels: + {{- include "openim-chat.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "openim-chat.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "openim-chat.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "openim-chat.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/deployments/openim-chat/templates/hpa.yaml b/deployments/openim-chat/templates/hpa.yaml new file mode 100644 index 000000000..5f28b13fe --- /dev/null +++ b/deployments/openim-chat/templates/hpa.yaml @@ -0,0 +1,42 @@ +# 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. + +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "openim-chat.fullname" . }} + labels: + {{- include "openim-chat.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "openim-chat.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/deployments/openim-chat/templates/ingress.yaml b/deployments/openim-chat/templates/ingress.yaml new file mode 100644 index 000000000..3faa231d0 --- /dev/null +++ b/deployments/openim-chat/templates/ingress.yaml @@ -0,0 +1,75 @@ +# 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. + +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "openim-chat.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "openim-chat.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployments/openim-chat/templates/service.yaml b/deployments/openim-chat/templates/service.yaml new file mode 100644 index 000000000..c504be550 --- /dev/null +++ b/deployments/openim-chat/templates/service.yaml @@ -0,0 +1,29 @@ +# 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. + +apiVersion: v1 +kind: Service +metadata: + name: {{ include "openim-chat.fullname" . }} + labels: + {{- include "openim-chat.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "openim-chat.selectorLabels" . | nindent 4 }} diff --git a/deployments/openim-chat/templates/serviceaccount.yaml b/deployments/openim-chat/templates/serviceaccount.yaml new file mode 100644 index 000000000..8fd4f4e21 --- /dev/null +++ b/deployments/openim-chat/templates/serviceaccount.yaml @@ -0,0 +1,26 @@ +# 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. + +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "openim-chat.serviceAccountName" . }} + labels: + {{- include "openim-chat.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/deployments/openim-chat/values.yaml b/deployments/openim-chat/values.yaml new file mode 100644 index 000000000..b1c083fee --- /dev/null +++ b/deployments/openim-chat/values.yaml @@ -0,0 +1,96 @@ +# 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. + +# Default values for openim-chat. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/deployments/openim-server/.helmignore b/deployments/openim-server/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/deployments/openim-server/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/deployments/openim-server/Chart.yaml b/deployments/openim-server/Chart.yaml new file mode 100644 index 000000000..d9d07eccb --- /dev/null +++ b/deployments/openim-server/Chart.yaml @@ -0,0 +1,38 @@ +# 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. + +apiVersion: v2 +name: openim-server +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/deployments/openim-server/templates/NOTES.txt b/deployments/openim-server/templates/NOTES.txt new file mode 100644 index 000000000..edb391088 --- /dev/null +++ b/deployments/openim-server/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "openim-server.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "openim-server.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "openim-server.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "openim-server.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/deployments/openim-server/templates/_helpers.tpl b/deployments/openim-server/templates/_helpers.tpl new file mode 100644 index 000000000..79f4ebd6a --- /dev/null +++ b/deployments/openim-server/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "openim-server.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "openim-server.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "openim-server.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "openim-server.labels" -}} +helm.sh/chart: {{ include "openim-server.chart" . }} +{{ include "openim-server.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "openim-server.selectorLabels" -}} +app.kubernetes.io/name: {{ include "openim-server.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "openim-server.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "openim-server.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deployments/openim-server/templates/deployment.yaml b/deployments/openim-server/templates/deployment.yaml new file mode 100644 index 000000000..9c630e89a --- /dev/null +++ b/deployments/openim-server/templates/deployment.yaml @@ -0,0 +1,75 @@ +# 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. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "openim-server.fullname" . }} + labels: + {{- include "openim-server.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "openim-server.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "openim-server.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "openim-server.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/deployments/openim-server/templates/hpa.yaml b/deployments/openim-server/templates/hpa.yaml new file mode 100644 index 000000000..c7726c969 --- /dev/null +++ b/deployments/openim-server/templates/hpa.yaml @@ -0,0 +1,42 @@ +# 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. + +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "openim-server.fullname" . }} + labels: + {{- include "openim-server.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "openim-server.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/deployments/openim-server/templates/ingress.yaml b/deployments/openim-server/templates/ingress.yaml new file mode 100644 index 000000000..c269ecc26 --- /dev/null +++ b/deployments/openim-server/templates/ingress.yaml @@ -0,0 +1,75 @@ +# 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. + +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "openim-server.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "openim-server.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployments/openim-server/templates/service.yaml b/deployments/openim-server/templates/service.yaml new file mode 100644 index 000000000..a12825bfb --- /dev/null +++ b/deployments/openim-server/templates/service.yaml @@ -0,0 +1,29 @@ +# 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. + +apiVersion: v1 +kind: Service +metadata: + name: {{ include "openim-server.fullname" . }} + labels: + {{- include "openim-server.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "openim-server.selectorLabels" . | nindent 4 }} diff --git a/deployments/openim-server/templates/serviceaccount.yaml b/deployments/openim-server/templates/serviceaccount.yaml new file mode 100644 index 000000000..6e31d9c83 --- /dev/null +++ b/deployments/openim-server/templates/serviceaccount.yaml @@ -0,0 +1,26 @@ +# 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. + +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "openim-server.serviceAccountName" . }} + labels: + {{- include "openim-server.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/deployments/openim-server/values.yaml b/deployments/openim-server/values.yaml new file mode 100644 index 000000000..99bddb99b --- /dev/null +++ b/deployments/openim-server/values.yaml @@ -0,0 +1,96 @@ +# 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. + +# Default values for openim-server. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/deployments/templates/chat.yaml b/deployments/templates/chat.yaml new file mode 100644 index 000000000..4f4936b13 --- /dev/null +++ b/deployments/templates/chat.yaml @@ -0,0 +1,124 @@ +# 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. + +# Configuration for OpenIMServer + +# ----------------------------------------------------------------- +# TODO: This config file is the template file +# --| source: deployments/templates/chat.yaml +# --| env: scripts/install/environment +# --| target: config/config.yaml +# ----------------------------------------------------------------- + +###################### Zookeeper ###################### +# Zookeeper configuration +# It's not recommended to modify the schema +zookeeper: + schema: ${ZOOKEEPER_SCHEMA} + zkAddr: + - ${ZOOKEEPER_ADDRESS}:${ZOOKEEPER_PORT} + username: ${ZOOKEEPER_USERNAME} + password: ${ZOOKEEPER_PASSWORD} + +###################### Chat API ###################### +chatApi: + openImChatApiPort: [ ${OPENIM_CHAT_API_PORT} ] + listenIP: ${CHAT_API_LISTEN_IP} + +###################### Admin API ###################### +adminApi: + openImAdminApiPort: [ ${OPENIM_ADMIN_API_PORT} ] + listenIP: ${ADMIN_API_LISTEN_IP} + +###################### RPC ###################### +rpc: + registerIP: #作为rpc启动时,注册到zookeeper的IP,api/gateway能访问到此ip和对应的rpcPort中的端口 + listenIP: #默认为0.0.0.0 + +rpcPort: + openImAdminPort: [ ${OPENIM_ADMIN_PORT} ] + openImChatPort: [ ${OPENIM_CHAT_PORT} ] +rpcRegisterName: + openImAdminName: ${OPENIM_ADMIN_NAME} + openImChatName: ${OPENIM_CHAT_NAME} + +###################### MySQL ###################### +mysql: + # address: [ 127.0.0.1:13306 ] #目前仅支持单机 + # username: root #用户名 + # password: openIM123 #密码 + # database: openIM_v2 #不建议修改 + # maxOpenConn: 1000 #最大连接数 + # maxIdleConn: 100 #最大空闲连接数 + # maxLifeTime: 60 #连接可以重复使用的最长时间(秒) + # logLevel: 4 #日志级别 1=slient 2=error 3=warn 4=info + # slowThreshold: 500 #慢语句阈值 (毫秒) + database: openim_enterprise + +###################### Log ###################### +log: + storageLocation: ../logs/ #存放目录 +# rotationTime: 24 #日志旋转时间 +# remainRotationCount: 2 #日志数量 +# remainLogLevel: 6 #日志级别 6表示全都打印, +# isStdout: false +# isJson: false +# withStack: false + +###################### Secret & Token Policy ###################### +# secret: openIM123 +#tokenPolicy: +# expire: 86400 + +###################### Verify Code ###################### +verifyCode: + validTime: 300 # 验证码有效时间 + validCount: 5 # 验证码有效次数 + uintTime: 86400 # 单位时间间隔 + maxCount: 10 # 单位时间内最大获取次数 + superCode: "666666" # 超级验证码(只有use为空时使用) + len: 6 # 验证码长度 + use: "" # 使用的验证码服务(use: "ali") + ali: + endpoint: "dysmsapi.aliyuncs.com" + accessKeyId: "" + accessKeySecret: "" + signName: "" + verificationCodeTemplateCode: "" + + +###################### Proxy Header ###################### +# 获取ip的header,没有配置直接获取远程地址 +#proxyHeader: "X-Forwarded-For" + +###################### Admin List ###################### +adminList: + - adminID: admin1 + nickname: chat1 + imAdmin: openIM123456 + - adminID: admin2 + nickname: chat2 + imAdmin: openIM654321 + - adminID: admin3 + nickname: chat3 + imAdmin: openIMAdmin + +###################### OpenIM URL ###################### +openIMUrl: ${OPENIM_SERVER_ADDRESS}:${API_OPENIM_PORT} + +###################### Redis ###################### +redis: + # address: [ 127.0.0.1:16379 ] + # username: + # password: openIM123 diff --git a/deployments/templates/env_template.yaml b/deployments/templates/env_template.yaml index 687c04453..c6a2d7465 100644 --- a/deployments/templates/env_template.yaml +++ b/deployments/templates/env_template.yaml @@ -12,8 +12,268 @@ # See the License for the specific language governing permissions and # limitations under the License. +# ====================================== +# ========= Basic Configuration ======== +# ====================================== + +# The user for authentication or system operations. +# Default: USER=root USER=${USER} + +# Password associated with the specified user for authentication. +# Default: PASSWORD=openIM123 PASSWORD=${PASSWORD} + +# Endpoint for the MinIO object storage service. +# Default: MINIO_ENDPOINT=http://172.28.0.1:10005 MINIO_ENDPOINT=${MINIO_ENDPOINT} + +# Base URL for the application programming interface (API). +# Default: API_URL=http://172.28.0.1:10002 API_URL=${API_URL} -DATA_DIR=${DATA_DIR} \ No newline at end of file + +# Directory path for storing data files or related information. +# Default: DATA_DIR=./ +DATA_DIR=${DATA_DIR} + +# ====================================== +# ========= Network Configuration ====== +# ====================================== + +# Subnet for the Docker network. +# Default: DOCKER_BRIDGE_SUBNET=172.28.0.0/16 +DOCKER_BRIDGE_SUBNET=${DOCKER_BRIDGE_SUBNET} + +# Gateway for the Docker network. +# Default: DOCKER_BRIDGE_GATEWAY=172.28.0.1 +DOCKER_BRIDGE_GATEWAY=${DOCKER_BRIDGE_GATEWAY} + +# Address or hostname for the MySQL network. +# Default: MYSQL_NETWORK_ADDRESS=172.28.0.2 +MYSQL_NETWORK_ADDRESS=${MYSQL_NETWORK_ADDRESS} + +# Address or hostname for the MongoDB network. +# Default: MONGO_NETWORK_ADDRESS=172.28.0.3 +MONGO_NETWORK_ADDRESS=${MONGO_NETWORK_ADDRESS} + +# Address or hostname for the Redis network. +# Default: REDIS_NETWORK_ADDRESS=172.28.0.4 +REDIS_NETWORK_ADDRESS=${REDIS_NETWORK_ADDRESS} + +# Address or hostname for the Kafka network. +# Default: KAFKA_NETWORK_ADDRESS=172.28.0.5 +KAFKA_NETWORK_ADDRESS=${KAFKA_NETWORK_ADDRESS} + +# Address or hostname for the ZooKeeper network. +# Default: ZOOKEEPER_NETWORK_ADDRESS=172.28.0.6 +ZOOKEEPER_NETWORK_ADDRESS=${ZOOKEEPER_NETWORK_ADDRESS} + +# Address or hostname for the MinIO network. +# Default: MINIO_NETWORK_ADDRESS=172.28.0.7 +MINIO_NETWORK_ADDRESS=${MINIO_NETWORK_ADDRESS} + +# Address or hostname for the OpenIM web network. +# Default: OPENIM_WEB_NETWORK_ADDRESS=172.28.0.8 +OPENIM_WEB_NETWORK_ADDRESS=${OPENIM_WEB_NETWORK_ADDRESS} + +# Address or hostname for the OpenIM server network. +# Default: OPENIM_SERVER_NETWORK_ADDRESS=172.28.0.9 +OPENIM_SERVER_NETWORK_ADDRESS=${OPENIM_SERVER_NETWORK_ADDRESS} + +# Address or hostname for the OpenIM chat network. +# Default: OPENIM_CHAT_NETWORK_ADDRESS=172.28.0.10 +OPENIM_CHAT_NETWORK_ADDRESS=${OPENIM_CHAT_NETWORK_ADDRESS} + +# Address or hostname for the Prometheus network. +# Default: PROMETHEUS_NETWORK_ADDRESS=172.28.0.11 +PROMETHEUS_NETWORK_ADDRESS=${PROMETHEUS_NETWORK_ADDRESS} + +# Address or hostname for the Grafana network. +# Default: GRAFANA_NETWORK_ADDRESS=172.28.0.12 +GRAFANA_NETWORK_ADDRESS=${GRAFANA_NETWORK_ADDRESS} + + +# =============================================== +# = Component Extension Configuration = +# =============================================== + +# ============ Component Extension Configuration ========== +# ----- ZooKeeper Configuration ----- +# Address or hostname for the ZooKeeper service. +# Default: ZOOKEEPER_ADDRESS=172.28.0.1 +ZOOKEEPER_ADDRESS=${ZOOKEEPER_NETWORK_ADDRESS} + +# Port for ZooKeeper service. +# Default: ZOOKEEPER_PORT=12181 +ZOOKEEPER_PORT=${ZOOKEEPER_PORT} + +# ----- MySQL Configuration ----- + +# Address or hostname for the MySQL service. +# Default: MYSQL_ADDRESS=172.28.0.1 +MYSQL_ADDRESS=${MYSQL_NETWORK_ADDRESS} + +# Port on which MySQL database service is running. +# Default: MYSQL_PORT=13306 +MYSQL_PORT=${MYSQL_PORT} + +# Password to authenticate with the MySQL database service. +# Default: MYSQL_PASSWORD=openIM123 +MYSQL_PASSWORD=${MYSQL_PASSWORD} + +# ----- MongoDB Configuration ----- +# Address or hostname for the MongoDB service. +# Default: MONGO_ADDRESS=172.28.0.1 +MONGO_ADDRESS=${MONGO_NETWORK_ADDRESS} + +# Port on which MongoDB service is running. +# Default: MONGO_PORT=37017 +MONGO_PORT=${MONGO_PORT} + +# Username to authenticate with the MongoDB service. +# Default: MONGO_USERNAME=root +MONGO_USERNAME=${MONGO_USERNAME} + +# Password to authenticate with the MongoDB service. +# Default: MONGO_PASSWORD=openIM123 +MONGO_PASSWORD=${MONGO_PASSWORD} + +# Name of the database in MongoDB to be used. +# Default: MONGO_DATABASE=openIM_v3 +MONGO_DATABASE=${MONGO_DATABASE} + +# ----- Redis Configuration ----- +# Address or hostname for the Redis service. +# Default: REDIS_ADDRESS=172.28.0.1 +REDIS_ADDRESS=${REDIS_NETWORK_ADDRESS} + +# Port on which Redis in-memory data structure store is running. +# Default: REDIS_PORT=16379 +REDIS_PORT=${REDIS_PORT} + +# Password to authenticate with the Redis service. +# Default: REDIS_PASSWORD=openIM123 +REDIS_PASSWORD=${REDIS_PASSWORD} + +# ----- Kafka Configuration ----- +# Address or hostname for the Kafka service. +# Default: KAFKA_ADDRESS=172.28.0.1 +KAFKA_ADDRESS=${KAFKA_NETWORK_ADDRESS} + +# Port on which Kafka distributed streaming platform is running. +# Default: KAFKA_PORT=19092 +KAFKA_PORT=${KAFKA_PORT} + +# Topic in Kafka for storing the latest messages in Redis. +# Default: KAFKA_LATESTMSG_REDIS_TOPIC=latestMsgToRedis +KAFKA_LATESTMSG_REDIS_TOPIC=${KAFKA_LATESTMSG_REDIS_TOPIC} + +# Topic in Kafka for pushing messages (e.g. notifications or updates). +# Default: KAFKA_MSG_PUSH_TOPIC=msgToPush +KAFKA_MSG_PUSH_TOPIC=${KAFKA_MSG_PUSH_TOPIC} + +# Topic in Kafka for storing offline messages in MongoDB. +# Default: KAFKA_OFFLINEMSG_MONGO_TOPIC=offlineMsgToMongoMysql +KAFKA_OFFLINEMSG_MONGO_TOPIC=${KAFKA_OFFLINEMSG_MONGO_TOPIC} + +# ----- MinIO Configuration ---- +# Address or hostname for the MinIO object storage service. +# Default: MINIO_ADDRESS=172.28.0.1 +MINIO_ADDRESS=${MINIO_NETWORK_ADDRESS} + +# Port on which MinIO object storage service is running. +# Default: MINIO_PORT=10005 +MINIO_PORT=${MINIO_PORT} + +# Access key to authenticate with the MinIO service. +# Default: MINIO_ACCESS_KEY=root +MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY} + +# Secret key corresponding to the access key for MinIO authentication. +# Default: MINIO_SECRET_KEY=openIM123 +MINIO_SECRET_KEY=${MINIO_SECRET_KEY} + +# ----- Prometheus Configuration ----- +# Address or hostname for the Prometheus service. +# Default: PROMETHEUS_ADDRESS=172.28.0.1 +PROMETHEUS_ADDRESS=${PROMETHEUS_NETWORK_ADDRESS} + +# Port on which Prometheus service is running. +# Default: PROMETHEUS_PORT=19090 +PROMETHEUS_PORT=${PROMETHEUS_PORT} + +# ----- Grafana Configuration ----- +# Address or hostname for the Grafana service. +# Default: GRAFANA_ADDRESS=172.28.0.1 +GRAFANA_ADDRESS=${GRAFANA_NETWORK_ADDRESS} + +# Port on which Grafana service is running. +# Default: GRAFANA_PORT=3000 +GRAFANA_PORT=${GRAFANA_PORT} + +# ====================================== +# ============ OpenIM Web =============== +# ====================================== + +# Path to the OpenIM web distribution. +# Default: OPENIM_WEB_DIST_PATH=/app/dist +OPENIM_WEB_DIST_PATH=${OPENIM_WEB_DIST_PATH} + +# Port on which OpenIM web service is running. +# Default: OPENIM_WEB_PORT=11001 +OPENIM_WEB_PORT=${OPENIM_WEB_PORT} + +# Address or hostname for the OpenIM web service. +# Default: OPENIM_WEB_ADDRESS=172.28.0.1 +OPENIM_WEB_ADDRESS=${OPENIM_WEB_NETWORK_ADDRESS} + + +# ====================================== +# ========= OpenIM Server ============== +# ====================================== + +# Address or hostname for the OpenIM server. +# Default: OPENIM_SERVER_ADDRESS=172.28.0.1 +OPENIM_SERVER_ADDRESS=${OPENIM_SERVER_NETWORK_ADDRESS} + +# Port for the OpenIM WebSockets. +# Default: OPENIM_WS_PORT=10001 +OPENIM_WS_PORT=${OPENIM_WS_PORT} + +# Port for the OpenIM API. +# Default: API_OPENIM_PORT=10002 +API_OPENIM_PORT=${API_OPENIM_PORT} + + +# ====================================== +# ========== OpenIM Chat =============== +# ====================================== + +# Branch name for OpenIM chat. +# Default: CHAT_BRANCH=main +CHAT_BRANCH=${CHAT_BRANCH} + +# Address or hostname for the OpenIM chat service. +# Default: OPENIM_CHAT_ADDRESS=172.28.0.1 +OPENIM_CHAT_ADDRESS=${OPENIM_CHAT_NETWORK_ADDRESS} + +# Port for the OpenIM chat API. +# Default: OPENIM_CHAT_API_PORT=10008 +OPENIM_CHAT_API_PORT=${OPENIM_CHAT_API_PORT} + +# Directory path for storing data files or related information for OpenIM chat. +# Default: OPENIM_CHAT_DATA_DIR=./openim-chat/main +OPENIM_CHAT_DATA_DIR=${OPENIM_CHAT_DATA_DIR} + + +# ====================================== +# ========== OpenIM Admin ============== +# ====================================== + +# Branch name for OpenIM server. +# Default: SERVER_BRANCH=main +SERVER_BRANCH=${SERVER_BRANCH} + +# Port for the OpenIM admin API. +# Default: OPENIM_ADMIN_API_PORT=10009 +OPENIM_ADMIN_API_PORT=${OPENIM_ADMIN_API_PORT} diff --git a/deployments/templates/init/README.md b/deployments/templates/init/README.md index 460739372..b9957dadc 100644 --- a/deployments/templates/init/README.md +++ b/deployments/templates/init/README.md @@ -144,7 +144,7 @@ source ./environment.sh cat > openim-api.service.template < $service.service.template < + bash -c " + /opt/bitnami/scripts/kafka/run.sh & sleep 5; /opt/bitnami/kafka/create_topic.sh; wait + " + extra_hosts: + - "host.docker.internal:host-gateway" + environment: + - TZ=Asia/Shanghai + - KAFKA_CFG_NODE_ID=0 + - KAFKA_CFG_PROCESS_ROLES=controller,broker + - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@:9093 + - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094 + - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,EXTERNAL://${DOCKER_BRIDGE_GATEWAY}:${KAFKA_PORT} + - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT + - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER + networks: + server: + ipv4_address: ${KAFKA_NETWORK_ADDRESS} + + minio: + image: minio/minio + ports: + - "${MINIO_PORT}:9000" + - "9090:9090" + container_name: minio + volumes: + - minio_data:/data + - minio_config:/root/.minio + environment: + MINIO_ROOT_USER: "${MINIO_ACCESS_KEY}" + MINIO_ROOT_PASSWORD: "${MINIO_SECRET_KEY}" + restart: always + command: minio server /data --console-address ':9090' + networks: + server: + ipv4_address: ${MINIO_NETWORK_ADDRESS} + + openim-web: + image: ghcr.io/openimsdk/openim-web:latest + container_name: openim-web + environment: + - OPENIM_WEB_DIST_PATH=${OPENIM_WEB_DIST_PATH} + - OPENIM_WEB_PORT=${OPENIM_WEB_PORT} + restart: always + ports: + - "${OPENIM_WEB_PORT}:11001" + networks: + server: + ipv4_address: ${OPENIM_WEB_NETWORK_ADDRESS} + + openim-server: + # image: ghcr.io/openimsdk/openim-server:main + image: registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server:main + # image: openim/openim-server:main +# build: . + container_name: openim-server + ports: + - ${OPENIM_WS_PORT}:10001 + - ${API_OPENIM_PORT}:10002 + healthcheck: + test: ["CMD", "/openim/openim-server/scripts/check-all.sh"] + interval: 300s + timeout: 10s + retries: 5 + volumes: + - ./logs:/openim/openim-server/logs + - ./_output:/openim/openim-server/_output + - ./config:/openim/openim-server/config + - ./scripts:/openim/openim-server/scripts + restart: always + depends_on: + - kafka + - mysql + - mongodb + - redis + - minio + logging: + driver: json-file + options: + max-size: "1g" + max-file: "2" + networks: + server: + ipv4_address: ${OPENIM_SERVER_NETWORK_ADDRESS} + + # openim-chat: + # # image: ghcr.io/openimsdk/openim-chat:main + # image: registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:main + # # image: ghcr.io/openimsdk/openim-chat:main + # container_name: openim-chat + # healthcheck: + # test: ["CMD", "/openim/openim-chat/scripts/check_all.sh"] + # interval: 300s + # timeout: 10s + # retries: 5 + # ports: + # - ${OPENIM_CHAT_API_PORT}:10008 + # - ${OPENIM_ADMIN_API_PORT}:10009 + # volumes: + # - openim_chat_logs:/openim/openim-chat/logs + # - openim_chat_output:/openim/openim-chat/_output + # - openim_chat_config:/openim/openim-chat/config + # - openim_chat_scripts:/openim/openim-chat/scripts + # restart: always + # user: root:root + # depends_on: + # - mysql + # - mongodb + # - redis + # - minio + # - server + # logging: + # driver: json-file + # options: + # max-size: "1g" + # max-file: "2" + # networks: + # server: + # ipv4_address: ${OPENIM_CHAT_NETWORK_ADDRESS} + + # prometheus: + # image: prom/prometheus + # volumes: + # - openim_server_prometheus_config:/etc/prometheus + # container_name: prometheus + # ports: + # - ${PROMETHEUS_PORT}:9091 + # command: --web.listen-address=:9091 --config.file="/etc/prometheus" + # networks: + # server: + # ipv4_address: ${PROMETHEUS_NETWORK_ADDRESS} + + # grafana: + # image: grafana/grafana + # volumes: + # - openim_server_grafana_datasource:/etc/grafana/provisioning/datasources + # - openim_server_grafana_config:/etc/grafana + # - openim_server_grafana_dashboard:/var/lib/grafana/dashboards + # container_name: grafana + # ports: + # - ${GRAFANA_PORT}:3000 + # networks: + # server: + # ipv4_address: ${GRAFANA_NETWORK_ADDRESS} + + # node-exporter: + # image: quay.io/prometheus/node-exporter + # container_name: node-exporter + # restart: always + # ports: + # - "9100:9100" diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..e1d8c5d58 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,67 @@ +# OpenIM Server Docs + +Welcome to the OpenIM Documentation hub! This center provides a comprehensive range of guides and manuals designed to help you get the most out of your OpenIM experience. + +## Table of Contents + +1. [Contrib](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib) - Guidance on contributing and configurations for developers +2. [Conversions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions) - Coding conventions, logging policies, and other transformation tools + +------ + +## Contrib + +This section offers developers a detailed guide on how to contribute code, set up their environment, and follow the associated processes. + +- [Code Conventions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/code_conventions.md) - Rules and conventions for writing code in OpenIM. +- [Development Guide](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/development.md) - A guide on how to carry out development within OpenIM. +- [Git Cherry Pick](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/git_cherry-pick.md) - Guidelines on cherry-picking operations. +- [Git Workflow](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/git_workflow.md) - The git workflow in OpenIM. +- [Initialization Configurations](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/init_config.md) - Guidance on setting up and initializing OpenIM. +- [Docker Installation](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/install_docker.md) - How to install Docker on your machine. +- [Linux Development Environment](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/linux_development.md) - Guide to set up the development environment on Linux. +- [Local Actions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/local_actions.md) - Guidelines on how to carry out certain common actions locally. +- [Offline Deployment](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/offline-deployment.md) - Methods of deploying OpenIM offline. +- [Protoc Tools](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/protoc_tools.md) - Guide on using protoc tools. +- [Go Tools](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/util_go.md) - Tools and libraries in OpenIM for Go. +- [Makefile Tools](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/util_makefile.md) - Best practices and tools for Makefile. +- [Script Tools](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/util_scripts.md) - Best practices and tools for scripts. + +## Conversions + +This section introduces various conventions and policies within OpenIM, encompassing code, logs, versions, and more. + +- [API Conversions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/api.md) - Guidelines and methods for API conversions. +- [Logging Policy](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/bash_log.md) - Logging policies and conventions in OpenIM. +- [CI/CD Actions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/cicd_actions.md) - Procedures and conventions for CI/CD. +- [Commit Conventions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/commit.md) - Conventions for code commits in OpenIM. +- [Directory Conventions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/directory.md) - Directory structure and conventions within OpenIM. +- [Error Codes](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/error_code.md) - List and descriptions of error codes. +- [Go Code Conversions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/go_code.md) - Conventions and conversions for Go code. +- [Docker Image Strategy](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) - Management strategies for OpenIM Docker images, spanning multiple architectures and image repositories. +- [Logging Conventions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/logging.md) - Further detailed conventions on logging. +- [Version Conventions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) - Naming and management strategies for OpenIM versions. + + +## For Developers, Contributors, and Community Maintainers + +### Developers & Contributors + +If you're a developer or someone keen on contributing: + +- Familiarize yourself with our [Code Conventions](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/code_conventions.md) and [Git Workflow](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/git_workflow.md) to ensure smooth contributions. +- Dive into the [Development Guide](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/development.md) to get a hang of the development practices in OpenIM. + +### Community Maintainers + +As a community maintainer: + +- Ensure that contributions align with the standards outlined in our documentation. +- Regularly review the [Logging Policy](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/bash_log.md) and [Error Codes](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/error_code.md) to stay updated. + +## For Users + +Users should pay particular attention to: + +- [Docker Installation](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/install_docker.md) - Necessary if you're planning to use Docker images of OpenIM. +- [Docker Image Strategy](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) - To understand the different images available and how to choose the right one for your architecture. \ No newline at end of file diff --git a/docs/contrib/code_conventions.md b/docs/contrib/code_conventions.md index 1387da2f7..94478e6ff 100644 --- a/docs/contrib/code_conventions.md +++ b/docs/contrib/code_conventions.md @@ -35,4 +35,4 @@ ## Testing conventions -Please refer to [TESTING.md](../../tests/TESTING.md) document. +Please refer to [TESTING.md](https://github.com/OpenIMSDK/Open-IM-Server/tree/main/test/readme) document. diff --git a/docs/contrib/development.md b/docs/contrib/development.md index 64aa08cda..a8c640570 100644 --- a/docs/contrib/development.md +++ b/docs/contrib/development.md @@ -10,12 +10,11 @@ Since OpenIM is written in Go, it is fair to assume that the Go tools are all on - [Go](#go) - [Docker](#docker) - [Vagrant](#vagrant) - - [Cloning, Building and Testing OpenIM](#cloning-building-and-testing-openim) - [Dependency management](#dependency-management) ## Non-Linux environment prerequisites -All the test and build scripts within this repository were created to be run on GNU Linux development environments. Due to this, it is suggested to use the virtual machine defined on this repository's [Vagrantfile](../../Vagrantfile) to use them. +All the test and build scripts within this repository were created to be run on GNU Linux development environments. Due to this, it is suggested to use the virtual machine defined on this repository's [Vagrantfile](https://developer.hashicorp.com/vagrant/docs/vagrantfile) to use them. Either way, if one still wants to build and test OpenIM on non-Linux environments, specific setups are to be followed. @@ -62,18 +61,11 @@ OpenIM build and test processes development require Docker to run certain steps. ### Vagrant -As described in the [Testing documentation](../../tests/TESTING.md), all the smoke tests are run in virtual machines managed by Vagrant. To install Vagrant in the development environment, [follow the instructions from the Hashicorp website](https://www.vagrantup.com/downloads), alongside any of the following hypervisors: +As described in the [Testing documentation](https://github.com/OpenIMSDK/Open-IM-Server/tree/main/test/readme), all the smoke tests are run in virtual machines managed by Vagrant. To install Vagrant in the development environment, [follow the instructions from the Hashicorp website](https://www.vagrantup.com/downloads), alongside any of the following hypervisors: - [VirtualBox](https://www.virtualbox.org/) - [libvirt](https://libvirt.org/) and the [vagrant-libvirt plugin](https://github.com/vagrant-libvirt/vagrant-libvirt#installation) -## Cloning, Building and Testing OpenIM - -These topics already have been addressed on their respective documents: - -- [Git Workflow](./git-workflow.md) -- [Building](../../BUILDING.md) -- [Testing](../../tests/TESTING.md) ## Dependency management diff --git a/docs/contrib/git_cherry-pick.md b/docs/contrib/git_cherry-pick.md index ffa02eda2..9afb9c232 100644 --- a/docs/contrib/git_cherry-pick.md +++ b/docs/contrib/git_cherry-pick.md @@ -75,15 +75,14 @@ It is critical that our full community is actively engaged on enhancements in th - Be aware the cherry pick script assumes you have a git remote called `upstream` that points at the openim-server github org. - Please see our [recommended Git workflow](https://github.com/openim-server/community/blob/main/contributors/guide/github-workflow.md#workflow). + Please see our [recommended Git workflow](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contributors/github-workflow.md#workflow). - - You will need to run the cherry pick script separately for each patch release you want to cherry pick to. Cherry picks should be applied to all [active](https://github.com/openim-server/website/blob/main/content/en/releases/patch-releases.md#detailed-release-history-for-active-branches) release branches where the fix is applicable. + - You will need to run the cherry pick script separately for each patch release you want to cherry pick to. Cherry picks should be applied to all [active](https://github.com/OpenIMSDK/Open-IM-Server/releases) release branches where the fix is applicable. - If `GITHUB_TOKEN` is not set you will be asked for your github password: provide the github [personal access token](https://github.com/settings/tokens) rather than your actual github password. If you can securely set the environment variable `GITHUB_TOKEN` to your personal access token then you can avoid an interactive prompt. Refer [mislav/hub#2655 (comment)](https://github.com/mislav/hub/issues/2655#issuecomment-735836048) - Your cherry pick PR will immediately get the `do-not-merge/cherry-pick-not-approved` label. - [Normal rules apply for code merge](https://github.com/openim-server/community/blob/main/contributors/devel/sig-release/release.md#tldr), with some additional caveats outlined in the next section of this document. ## Cherry Pick Review diff --git a/docs/contrib/offline-deployment.md b/docs/contrib/offline-deployment.md new file mode 100644 index 000000000..6272c7499 --- /dev/null +++ b/docs/contrib/offline-deployment.md @@ -0,0 +1,116 @@ + + +# OpenIM Offline Deployment Design + +## 1. Base Images + +Below are the base images and their versions you'll need: + +- wurstmeister/kafka +- redis:7.0.0 +- mongo:6.0.2 +- mysql:5.7 +- wurstmeister/zookeeper +- minio/minio + +Use the following commands to pull these base images: + +``` +docker pull wurstmeister/kafka +docker pull redis:7.0.0 +docker pull mongo:6.0.2 +docker pull mysql:5.7 +docker pull wurstmeister/zookeeper +docker pull minio/minio +``` + +## 2. OpenIM & Chat Images + +**For detailed understanding of version management and storage of OpenIM and Chat**: [version.md](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) + +### OpenIM Image + +- Get image version info: [images.md](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) +- Depending on the required version, execute the following command: + +```bash +docker pull ghcr.io/openimsdk/openim-server: +``` + +### Chat Image + +- Execute the following command to pull the image: + +```bash +docker pull ghcr.io/openimsdk/openim-server: +``` + +## 3. Image Storage Selection + +**Repositories**: + +- Alibaba Cloud: `registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server` +- Docker Hub: `openim/openim-server` + +**Version Selection**: + +- Stable: e.g. release-v3.2 (or 3.1, 3.3) +- Latest: latest +- Latest of main: main + +## 4. Version Selection + +You can select from the following versions: + +- Stable: e.g. release-v3.2 +- Latest: latest +- Latest from main branch: main + +## 5. Offline Deployment Steps + +1. **Pull images**: Execute the above `docker pull` commands to pull all required images locally. +2. **Save images**: + +``` +docker save -o .tar +``` + +1. **Fetch code**: Clone the repository: + +``` +git clone https://github.com/OpenIMSDK/openim-docker.git +``` + +Or download the code from [Releases](https://github.com/OpenIMSDK/openim-docker/releases/). + +1. **Transfer files**: Use `scp` to transfer all images and code to the intranet server. + +``` +scp .tar user@remote-ip:/path/on/remote/server +``` + +Or choose other transfer methods such as a hard drive. + +1. **Import images**: On the intranet server: + +``` +docker load -i .tar +``` + +1. **Deploy**: Navigate to the `openim-docker` repository directory and follow the README guide for deployment. +2. **Deploy using Docker-compose**: + +``` +docker-compose up -d + +# Verify +docker-compose ps +``` + +> **Note**: If you're using a version of Docker prior to 20, make sure you've installed `docker-compose`. + +## 6. Reference Links + +- [OpenIMSDK Issue #432](https://github.com/OpenIMSDK/Open-IM-Server/issues/432) +- [Notion Link](https://nsddd.notion.site/435ee747c0bc44048da9300a2d745ad3?pvs=25) +- [OpenIMSDK Issue #474](https://github.com/OpenIMSDK/Open-IM-Server/issues/474) \ No newline at end of file diff --git a/docs/conversions/github-workflow.md b/docs/conversions/github-workflow.md new file mode 100644 index 000000000..013495e5e --- /dev/null +++ b/docs/conversions/github-workflow.md @@ -0,0 +1,284 @@ +--- +title: "GitHub Workflow" +weight: 6 +description: | + This document is an overview of the GitHub workflow used by the + open-im-server project. It includes tips and suggestions on keeping your + local environment in sync with upstream and how to maintain good + commit hygiene. +--- + +![Git workflow](git_workflow.png) + +## 1. Fork in the cloud + +1. Visit https://github.com/openimsdk/open-im-server +2. Click `Fork` button (top right) to establish a cloud-based fork. + +## 2. Clone fork to local storage + +Per Go's [workspace instructions][go-workspace], place open-im-server' code on your +`GOPATH` using the following cloning procedure. + +[go-workspace]: https://golang.org/doc/code.html#Workspaces + +In your shell, define a local working directory as `working_dir`. If your `GOPATH` has multiple paths, pick +just one and use it instead of `$GOPATH`. You must follow exactly this pattern, +neither `$GOPATH/src/github.com/${your github profile name}/` +nor any other pattern will work. + +```sh +export working_dir="$(go env GOPATH)/src/k8s.io" +``` + +If you already do Go development on github, the `k8s.io` directory +will be a sibling to your existing `github.com` directory. + +Set `user` to match your github profile name: + +```sh +export user= +``` + +Both `$working_dir` and `$user` are mentioned in the figure above. + +Create your clone: + +```sh +mkdir -p $working_dir +cd $working_dir +git clone https://github.com/$user/open-im-server.git +# or: git clone git@github.com:$user/open-im-server.git + +cd $working_dir/open-im-server +git remote add upstream https://github.com/openimsdk/open-im-server.git +# or: git remote add upstream git@github.com:openimsdk/open-im-server.git + +# Never push to upstream master +git remote set-url --push upstream no_push + +# Confirm that your remotes make sense: +git remote -v +``` + +## 3. Create a Working Branch + +Get your local master up to date. Note that depending on which repository you are working from, +the default branch may be called "main" instead of "master". + +```sh +cd $working_dir/open-im-server +git fetch upstream +git checkout master +git rebase upstream/master +``` + +Create your new branch. + +```sh +git checkout -b myfeature +``` + +You may now edit files on the `myfeature` branch. + +### Building open-im-server + +This workflow is process-specific. For quick-start build instructions for [openimsdk/open-im-server](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/util_makefile.md) + +## 4. Keep your branch in sync + +You will need to periodically fetch changes from the `upstream` +repository to keep your working branch in sync. Note that depending on which repository you are working from, +the default branch may be called 'main' instead of 'master'. + +Make sure your local repository is on your working branch and run the +following commands to keep it in sync: + +```sh +git fetch upstream +git rebase upstream/master +``` + +Please don't use `git pull` instead of the above `fetch` and +`rebase`. Since `git pull` executes a merge, it creates merge commits. These make the commit history messy +and violate the principle that commits ought to be individually understandable +and useful (see below). + +You might also consider changing your `.git/config` file via +`git config branch.autoSetupRebase always` to change the behavior of `git pull`, or another non-merge option such as `git pull --rebase`. + +## 5. Commit Your Changes + +You will probably want to regularly commit your changes. It is likely that you will go back and edit, +build, and test multiple times. After a few cycles of this, you might +[amend your previous commit](https://www.w3schools.com/git/git_amend.asp). + +```sh +git commit +``` + +## 6. Push to GitHub + +When your changes are ready for review, push your working branch to +your fork on GitHub. + +```sh +git push -f myfeature +``` + +## 7. Create a Pull Request + +1. Visit your fork at `https://github.com//open-im-server` +2. Click the **Compare & Pull Request** button next to your `myfeature` branch. +3. Check out the pull request process for more details and + advice. + +_If you have upstream write access_, please refrain from using the GitHub UI for +creating PRs, because GitHub will create the PR branch inside the main +repository rather than inside your fork. + +### Get a code review + +Once your pull request has been opened it will be assigned to one or more +reviewers. Those reviewers will do a thorough code review, looking for +correctness, bugs, opportunities for improvement, documentation and comments, +and style. + +Commit changes made in response to review comments to the same branch on your +fork. + +Very small PRs are easy to review. Very large PRs are very difficult to review. + +### Squash commits + +After a review, prepare your PR for merging by squashing your commits. + +All commits left on your branch after a review should represent meaningful milestones or units of work. Use commits to add clarity to the development and review process. + +Before merging a PR, squash the following kinds of commits: + +- Fixes/review feedback +- Typos +- Merges and rebases +- Work in progress + +Aim to have every commit in a PR compile and pass tests independently if you can, but it's not a requirement. In particular, `merge` commits must be removed, as they will not pass tests. + +To squash your commits, perform an [interactive rebase](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History): + +1. Check your git branch: + + ``` + git status + ``` + + The output should be similar to this: + + ``` + On branch your-contribution + Your branch is up to date with 'origin/your-contribution'. + ``` + +2. Start an interactive rebase using a specific commit hash, or count backwards from your last commit using `HEAD~`, where `` represents the number of commits to include in the rebase. + + ``` + git rebase -i HEAD~3 + ``` + + The output should be similar to this: + + ``` + pick 2ebe926 Original commit + pick 31f33e9 Address feedback + pick b0315fe Second unit of work + + # Rebase 7c34fc9..b0315ff onto 7c34fc9 (3 commands) + # + # Commands: + # p, pick = use commit + # r, reword = use commit, but edit the commit message + # e, edit = use commit, but stop for amending + # s, squash = use commit, but meld into previous commit + # f, fixup = like "squash", but discard this commit's log message + + ... + + ``` + +3. Use a command line text editor to change the word `pick` to `squash` for the commits you want to squash, then save your changes and continue the rebase: + + ``` + pick 2ebe926 Original commit + squash 31f33e9 Address feedback + pick b0315fe Second unit of work + + ... + + ``` + + The output after saving changes should look similar to this: + + ``` + [detached HEAD 61fdded] Second unit of work + Date: Thu Mar 5 19:01:32 2020 +0100 + 2 files changed, 15 insertions(+), 1 deletion(-) + + ... + + Successfully rebased and updated refs/heads/master. + ``` +4. Force push your changes to your remote branch: + + ``` + git push --force + ``` + +For mass automated fixups such as automated doc formatting, use one or more +commits for the changes to tooling and a final commit to apply the fixup en +masse. This makes reviews easier. + +An alternative to this manual squashing process is to use the Prow and Tide based automation that is configured in GitHub: adding a comment to your PR with `/label tide/merge-method-squash` will trigger the automation so that GitHub squash your commits onto the target branch once the PR is approved. Using this approach simplifies things for those less familiar with Git, but there are situations in where it's better to squash locally; reviewers will have this in mind and can ask for manual squashing to be done. + +By squashing locally, you control the commit message(s) for your work, and can separate a large PR into logically separate changes. +For example: you have a pull request that is code complete and has 24 commits. You rebase this against the same merge base, simplifying the change to two commits. Each of those two commits represents a single logical change and each commit message summarizes what changes. Reviewers see that the set of changes are now understandable, and approve your PR. + +## Merging a commit + +Once you've received review and approval, your commits are squashed, your PR is ready for merging. + +Merging happens automatically after both a Reviewer and Approver have approved the PR. If you haven't squashed your commits, they may ask you to do so before approving a PR. + +## Reverting a commit + +In case you wish to revert a commit, use the following instructions. + +_If you have upstream write access_, please refrain from using the +`Revert` button in the GitHub UI for creating the PR, because GitHub +will create the PR branch inside the main repository rather than inside your fork. + +- Create a branch and sync it with upstream. Note that depending on which repository you are working from, the default branch may be called 'main' instead of 'master'. + ```sh + # create a branch + git checkout -b myrevert + + # sync the branch with upstream + git fetch upstream + git rebase upstream/master + ``` +- If the commit you wish to revert is a *merge commit*, use this command: + ```sh + # SHA is the hash of the merge commit you wish to revert + git revert -m 1 + ``` + If it is a *single commit*, use this command: + ```sh + # SHA is the hash of the single commit you wish to revert + git revert + ``` + +- This will create a new commit reverting the changes. Push this new commit to your remote. + ```sh + git push myrevert + ``` + +- Finally, [create a Pull Request](#7-create-a-pull-request) using this branch. \ No newline at end of file diff --git a/go.mod b/go.mod index 1e2fd2c9c..1ea2ac71b 100644 --- a/go.mod +++ b/go.mod @@ -54,6 +54,7 @@ require ( cloud.google.com/go/iam v1.1.1 // indirect cloud.google.com/go/longrunning v0.5.1 // indirect cloud.google.com/go/storage v1.30.1 // indirect + github.com/NYTimes/gziphandler v1.1.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect diff --git a/go.work b/go.work index ce1770c8e..4bc5b345f 100644 --- a/go.work +++ b/go.work @@ -1,4 +1,4 @@ -go 1.20 +go 1.18 use ( . @@ -7,5 +7,7 @@ use ( ./tools/imctl ./tools/infra ./tools/ncpu + ./tools/versionchecker + ./tools/openim-web ./tools/yamlfmt ) diff --git a/install.sh b/install.sh index 38db46ed4..7dba0a39e 100755 --- a/install.sh +++ b/install.sh @@ -20,7 +20,6 @@ set -e set -o pipefail - ############################## OpenIM Github ############################## # ... rest of the script ... @@ -537,7 +536,7 @@ O:::::::OOO:::::::O p:::::ppppp:::::::pe::::::::e n::::n n::::nII: # Set text color to yellow for the Slack link echo -e "\033[1;33m" - print_with_delay "Join our developer community on Slack: https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg" 0.01 + print_with_delay "Join our developer community on Slack: https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q" 0.01 # Reset text color back to normal echo -e "\033[0m" diff --git a/internal/msggateway/context.go b/internal/msggateway/context.go index 1d32ff71c..b9ad47864 100644 --- a/internal/msggateway/context.go +++ b/internal/msggateway/context.go @@ -72,6 +72,7 @@ func newContext(respWriter http.ResponseWriter, req *http.Request) *UserConnCont ConnID: utils.Md5(req.RemoteAddr + "_" + strconv.Itoa(int(utils.GetCurrentTimestampByMill()))), } } + func newTempContext() *UserConnContext { return &UserConnContext{ Req: &http.Request{URL: &url.URL{}}, @@ -125,9 +126,11 @@ func (c *UserConnContext) GetOperationID() string { func (c *UserConnContext) SetOperationID(operationID string) { c.Req.URL.Query().Set(OperationID, operationID) } + func (c *UserConnContext) GetToken() string { return c.Req.URL.Query().Get(Token) } + func (c *UserConnContext) SetToken(token string) { c.Req.URL.RawQuery = Token + "=" + token } diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index 124898f7a..22e04b011 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -197,8 +197,10 @@ func (ws *WsServer) sendUserOnlineInfoToOtherNode(ctx context.Context, client *C continue } msgClient := msggateway.NewMsgGatewayClient(v) - _, err := msgClient.MultiTerminalLoginCheck(ctx, &msggateway.MultiTerminalLoginCheckReq{UserID: client.UserID, - PlatformID: int32(client.PlatformID), Token: client.token}) + _, err := msgClient.MultiTerminalLoginCheck(ctx, &msggateway.MultiTerminalLoginCheckReq{ + UserID: client.UserID, + PlatformID: int32(client.PlatformID), Token: client.token, + }) if err != nil { log.ZWarn(ctx, "MultiTerminalLoginCheck err", err, "node", v.Target()) continue @@ -206,6 +208,7 @@ func (ws *WsServer) sendUserOnlineInfoToOtherNode(ctx context.Context, client *C } return nil } + func (ws *WsServer) SetKickHandlerInfo(i *kickHandler) { ws.kickHandlerChan <- i } diff --git a/pkg/common/config/version b/pkg/common/config/version index 3a285c2be..aa6c89679 100644 --- a/pkg/common/config/version +++ b/pkg/common/config/version @@ -1 +1 @@ -v3.1.0 \ No newline at end of file +v3.2.0 \ No newline at end of file diff --git a/pkg/common/http/http_client.go b/pkg/common/http/http_client.go index bfb35609d..7a0b7f037 100644 --- a/pkg/common/http/http_client.go +++ b/pkg/common/http/http_client.go @@ -19,7 +19,6 @@ import ( "context" "encoding/json" "io" - "io/ioutil" "net/http" urllib "net/url" "time" @@ -41,7 +40,7 @@ func Get(url string) (response []byte, err error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/pkg/common/kafka/util.go b/pkg/common/kafka/util.go index 9d5678648..cc3dc64c6 100644 --- a/pkg/common/kafka/util.go +++ b/pkg/common/kafka/util.go @@ -1,3 +1,17 @@ +// 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. + package kafka import ( diff --git a/pkg/common/tls/tls.go b/pkg/common/tls/tls.go index 5f84f87e3..c473ca573 100644 --- a/pkg/common/tls/tls.go +++ b/pkg/common/tls/tls.go @@ -1,3 +1,17 @@ +// 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. + package tls import ( diff --git a/scripts/advertise.sh b/scripts/advertise.sh index 165fa397d..fbb68b4cc 100755 --- a/scripts/advertise.sh +++ b/scripts/advertise.sh @@ -100,7 +100,7 @@ O:::::::OOO:::::::O p:::::ppppp:::::::pe::::::::e n::::n n::::nII: # Set text color to yellow for the Slack link echo -e "\033[1;33m" - print_with_delay "Join our developer community on Slack: https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg" 0.01 + print_with_delay "Join our developer community on Slack: https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q" 0.01 # Reset text color back to normal echo -e "\033[0m" diff --git a/scripts/build-all-service.sh b/scripts/build-all-service.sh index 201694be1..c79018a87 100755 --- a/scripts/build-all-service.sh +++ b/scripts/build-all-service.sh @@ -20,7 +20,7 @@ # package, the build will produce executable files under $(OUT_DIR)/bin/platforms OR $(OUT_DIR)/bin—tools/platforms. # If not specified, "everything" will be built. # Usage: `scripts/build-all-service.sh`. -# Example: `hack/build-go.sh WHAT=cmd/kubelet`. +# Example: `scripts/build-go.sh WHAT=cmd/kubelet`. set -o errexit set -o nounset @@ -30,9 +30,6 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/lib/init.sh" # CPU core number -# Check the system type -system_type=$(uname) - pushd ""${OPENIM_ROOT}"/tools/ncpu" >/dev/null cpu_count=$(go run .) popd >/dev/null diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 17fd923c1..d40e5a479 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -28,6 +28,8 @@ source "${OPENIM_ROOT}/scripts/install/common.sh" OPENIM_VERBOSE=4 +openim::log::info "\n# Begin to check all openim service" + # OpenIM status # Elegant printing function print_services_and_ports() { @@ -55,11 +57,17 @@ print_services_and_ports OPENIM_DEPENDENCY_TARGETS OPENIM_DEPENDENCY_PORT_TARGET # OpenIM check echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}" -echo "## Check all dependent service ports" +openim::log::info "\n## Check all dependent service ports" echo "+++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}" set +e -openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]} + +if grep -qE 'docker|kubepods' /proc/1/cgroup || [ -f /.dockerenv ]; then + openim::color::echo ${COLOR_BLUE} "Environment in the interior of the container" +else + openim::color::echo ${COLOR_BLUE} "The environment is outside the container" + openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]} || return 0 +fi if [[ $? -ne 0 ]]; then openim::log::error_exit "The service does not start properly, please check the port, query variable definition!" @@ -67,12 +75,11 @@ if [[ $? -ne 0 ]]; then else echo "++++ Check all dependent service ports successfully !" fi -set -e -echo -e "\n## Check OpenIM service name" +openim::log::info "\n## Check OpenIM service name" . $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check -echo -e "\n## Check all OpenIM service ports" +openim::log::info "\n## Check all OpenIM service ports" echo "+++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}" openim::util::check_ports ${OPENIM_SERVER_PORT_LISTARIES[@]} if [[ $? -ne 0 ]]; then @@ -80,4 +87,6 @@ if [[ $? -ne 0 ]]; then openim::log::error_exit "The service does not start properly, please check the port, query variable definition!" else echo "++++ Check all openim service ports successfully !" -fi \ No newline at end of file +fi + +set -e \ No newline at end of file diff --git a/scripts/create_topic.sh b/scripts/create_topic.sh new file mode 100755 index 000000000..5c291ff08 --- /dev/null +++ b/scripts/create_topic.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# 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. + +# Wait for Kafka to be ready +until /opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092; do + echo "Waiting for Kafka to be ready..." + sleep 2 +done + +# Create topics +/opt/bitnami/kafka/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 8 --topic latestMsgToRedis +/opt/bitnami/kafka/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 8 --topic msgToPush +/opt/bitnami/kafka/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 8 --topic offlineMsgToMongoMysql + +echo "Topics created." \ No newline at end of file diff --git a/scripts/docker-start-all.sh b/scripts/docker-start-all.sh index f87f4689f..6ad277815 100755 --- a/scripts/docker-start-all.sh +++ b/scripts/docker-start-all.sh @@ -14,18 +14,24 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -o errexit +set -o nounset +set -o pipefail + #fixme This scripts is the total startup scripts #fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/install/common.sh" +openim::log::info "\n# Use Docker to start all openim service" + trap 'openim::util::onCtrlC' INT -nohup "${OPENIM_ROOT}"/scripts/start-all.sh >> ${LOG_FILE} 2>&1 & +"${OPENIM_ROOT}"/scripts/start-all.sh -sleep 15 +sleep 5 -nohup "${OPENIM_ROOT}"/scripts/check-all.sh >> ${LOG_FILE} 2>&1 & +"${OPENIM_ROOT}"/scripts/check-all.sh tail -f ${LOG_FILE} \ No newline at end of file diff --git a/scripts/githooks/commit-msg b/scripts/githooks/commit-msg.sh similarity index 100% rename from scripts/githooks/commit-msg rename to scripts/githooks/commit-msg.sh diff --git a/scripts/init-config.sh b/scripts/init-config.sh index 38b7e809f..db77e7e76 100755 --- a/scripts/init-config.sh +++ b/scripts/init-config.sh @@ -24,27 +24,30 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/lib/init.sh" -# 定义一个配置文件数组,其中包含需要生成的配置文件的名称路径 (en: Define a profile array that contains the name path of the profile to be generated.) -readonly ENV_FILE=${ENV_FILE:-"${OPENIM_ROOT}"/scripts/install/environment.sh} +# 定义一个配置文件数组,其中包含需要生成的配置文件的名称路径 +# (en: Define a profile array that contains the name path of the profile to be generated.) +readonly ENV_FILE=${ENV_FILE:-"${OPENIM_ROOT}/scripts/install/environment.sh"} -# 定义关联数组,其中键是模板文件,值是对应的输出文件 (en: Defines an associative array where the keys are the template files and the values are the corresponding output files.) +# 定义关联数组,其中键是模板文件,值是对应的输出文件 +# (en: Defines an associative array where the keys are the template files and the values are the corresponding output files.) declare -A TEMPLATES=( - [""${OPENIM_ROOT}"/deployments/templates/env_template.yaml"]=""${OPENIM_ROOT}"/.env" - [""${OPENIM_ROOT}"/deployments/templates/openim.yaml"]=""${OPENIM_ROOT}"/config/config.yaml" + ["${OPENIM_ROOT}/deployments/templates/env_template.yaml"]="${OPENIM_ROOT}/.env" + ["${OPENIM_ROOT}/deployments/templates/openim.yaml"]="${OPENIM_ROOT}/config/config.yaml" ) for template in "${!TEMPLATES[@]}"; do - output_file=${TEMPLATES[$template]} - if [[ ! -f "${template}" ]]; then openim::log::error_exit "template file ${template} does not exist..." fi - openim::log::info "⌚ Working with template file: ${template} to ${output_file}..." - ""${OPENIM_ROOT}"/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${output_file}" || { - openim::log::error "Error processing template file ${template}" - exit 1 - } + IFS=';' read -ra OUTPUT_FILES <<< "${TEMPLATES[$template]}" + for output_file in "${OUTPUT_FILES[@]}"; do + openim::log::info "⌚ Working with template file: ${template} to ${output_file}..." + "${OPENIM_ROOT}/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${output_file}" || { + openim::log::error "Error processing template file ${template}" + exit 1 + } + done done -openim::log::success "✨ All configuration files have been successfully generated!" \ No newline at end of file +openim::log::success "✨ All configuration files have been successfully generated!" diff --git a/scripts/init-env.sh b/scripts/init-env.sh index f127a46f3..ca0c471ad 100755 --- a/scripts/init-env.sh +++ b/scripts/init-env.sh @@ -22,6 +22,8 @@ set -o pipefail OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P) source "${OPENIM_ROOT}/scripts/install/common.sh" +openim::log::info "\n# Begin Install OpenIM Config" + for file in "${OPENIM_SERVER_TARGETS[@]}"; do VARNAME="$(echo $file | tr '[:lower:]' '[:upper:]' | tr '.' '_' | tr '-' '_')" VARVALUE="$OPENIM_OUTPUT_HOSTBIN/$file" diff --git a/scripts/init-githooks.sh b/scripts/init-githooks.sh new file mode 100755 index 000000000..9d1675c8e --- /dev/null +++ b/scripts/init-githooks.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# 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. +# +# ----------------------------------------------------------------------------- +# init-githooks.sh +# +# This script assists in managing Git hooks for the OpenIM project. +# When executed: +# 1. It prompts the user to enable git hooks. +# 2. If the user accepts, it copies predefined hook scripts to the appropriate +# Git directory, making them executable. +# 3. If requested, it can delete the added hooks. +# +# This script equal runs `make init-githooks` command. +# Usage: +# ./init-githooks.sh Prompt to enable git hooks. +# ./init-githooks.sh --delete Delete previously added git hooks. +# ./init-githooks.sh --help Show the help message. +# +# Example: `scripts/build-go.sh --help`. +# Documentation & related context can be found at: +# https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694 +# +# ----------------------------------------------------------------------------- + +OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +HOOKS_DIR=".git/hooks" + +help_info() { + echo "Usage: $0 [options]" + echo + echo "This script helps to manage git hooks." + echo + echo "Options:" + echo " -h, --help Show this help message and exit." + echo " -d, --delete Delete the hooks that have been added." + echo " By default, it will prompt to enable git hooks." +} + +delete_hooks() { + for file in scripts/githooks/*.sh; do + hook_name=$(basename "$file" .sh) + rm -f "$HOOKS_DIR/$hook_name" + done + echo "Git hooks have been deleted." +} + +enable_hooks() { + echo "Would you like to enable git hooks mode? [y/n]" + read -r choice + + if [[ $choice == "y" || $choice == "Y" ]]; then + for file in scripts/githooks/*.sh; do + cp -f "$file" "$HOOKS_DIR/$(basename "$file" .sh)" + done + + chmod +x $HOOKS_DIR/* + + echo "Git hooks mode has been enabled." + echo "With git hooks enabled, every time you perform a git action (e.g. git commit), the corresponding hooks script will be triggered automatically." + echo "This means that if the size of the file you're committing exceeds the set limit (e.g. 42MB), the commit will be rejected." + else + echo "Git hooks mode remains disabled." + fi +} + +case "$1" in + -h|--help) + help_info + ;; + -d|--delete) + delete_hooks + ;; + *) + enable_hooks + ;; +esac \ No newline at end of file diff --git a/scripts/install/environment.sh b/scripts/install/environment.sh index 1e09b7e72..2967d825c 100755 --- a/scripts/install/environment.sh +++ b/scripts/install/environment.sh @@ -24,12 +24,17 @@ OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" LOCAL_OUTPUT_ROOT=""${OPENIM_ROOT}"/${OUT_DIR:-_output}" source "${OPENIM_ROOT}/scripts/lib/init.sh" -#TODO +#TODO: Access to the IP networks outside, or you want to use the IP network # IP=http://127.0.0.1 if [ -z "${IP}" ]; then - IP=$(openim::util::get_server_ip) + IP=$(openim::util::get_server_ip) fi +# config.gateway custom bridge modes +# if [ -z "{IP_GATEWAY}" ] then +# IP_GATEWAY=$(openim::util::get_local_ip) +# fi + function def() { local var_name="$1" local default_value="${2:-}" @@ -37,7 +42,9 @@ function def() { } # app要能访问到此ip和端口或域名 -def "API_URL" "http://${IP}:10002" +readonly API_URL=${API_URL:-"http://${IP}:10002"} + +# OpenIM Docker Compose 数据存储的默认路径 def "DATA_DIR" "${OPENIM_ROOT}" # 设置统一的用户名,方便记忆 @@ -59,6 +66,47 @@ mkdir -p ${INSTALL_DIR} def "ENV_FILE" ""${OPENIM_ROOT}"/scripts/install/environment.sh" +###################### Docker compose ################### +# OPENIM AND CHAT +def "CHAT_BRANCH" "main" +def "SERVER_BRANCH" "main" + +###################### OpenIM Docker Network ###################### +# 设置 Docker 网络的网段 +readonly DOCKER_BRIDGE_SUBNET=${DOCKER_BRIDGE_SUBNET:-'172.28.0.0/16'} +IP_PREFIX=$(echo $DOCKER_BRIDGE_SUBNET | cut -d '/' -f 1) +SUBNET=$(echo $DOCKER_BRIDGE_SUBNET | cut -d '/' -f 2) +LAST_OCTET=$(echo $IP_PREFIX | cut -d '.' -f 4) + +generate_ip() { + local NEW_IP="$(echo $IP_PREFIX | cut -d '.' -f 1-3).$((LAST_OCTET++))" + echo $NEW_IP +} +LAST_OCTET=$((LAST_OCTET + 1)) +DOCKER_BRIDGE_GATEWAY=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +MYSQL_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +MONGO_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +REDIS_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +KAFKA_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +ZOOKEEPER_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +MINIO_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +OPENIM_WEB_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +OPENIM_SERVER_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +OPENIM_CHAT_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +PROMETHEUS_NETWORK_ADDRESS=$(generate_ip) +LAST_OCTET=$((LAST_OCTET + 1)) +GRAFANA_NETWORK_ADDRESS=$(generate_ip) + ###################### openim 配置 ###################### # read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/deployment/init/README.md def "OPENIM_DATA_DIR" "/data/openim" @@ -68,87 +116,122 @@ def "OPENIM_LOG_DIR" "/var/log/openim" def "CA_FILE" "${OPENIM_CONFIG_DIR}/cert/ca.pem" def "OPNEIM_CONFIG" ""${OPENIM_ROOT}"/config" +def "OPENIM_SERVER_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # OpenIM服务地址 + +# OpenIM Websocket端口 +readonly OPENIM_WS_PORT=${OPENIM_WS_PORT:-'10001'} + +# OpenIM API端口 +readonly API_OPENIM_PORT=${API_OPENIM_PORT:-'10002'} +def "API_LISTEN_IP" "0.0.0.0" # API的监听IP + +###################### openim-chat 配置信息 ###################### +def "OPENIM_CHAT_DATA_DIR" "./openim-chat/${CHAT_BRANCH}" +def "OPENIM_CHAT_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # OpenIM服务地址 +def "OPENIM_CHAT_API_PORT" "10008" # OpenIM API端口 +def "CHAT_API_LISTEN_IP" "" # OpenIM API的监听IP + +def "OPENIM_ADMIN_API_PORT" "10009" # OpenIM Admin API端口 +def "ADMIN_API_LISTEN_IP" "" # OpenIM Admin API的监听IP + +def "OPENIM_ADMIN_PORT" "30200" # OpenIM chat Admin端口 +def "OPENIM_CHAT_PORT" "30300" # OpenIM chat Admin的监听IP + +def "OPENIM_ADMIN_NAME" "admin" # openim-chat Admin用户名 +def "OPENIM_CHAT_NAME" "chat" # openim-chat chat用户名 + # TODO 注意: 一般的配置都可以使用 def 函数来定义,如果是包含特殊字符,比如说: # TODO readonly MSG_DESTRUCT_TIME=${MSG_DESTRUCT_TIME:-'0 2 * * *'} # TODO 使用 readonly 来定义合适,负责无法正常解析, 并且 yaml 模板需要加 "" 来包裹 ###################### Zookeeper 配置信息 ###################### -def "ZOOKEEPER_SCHEMA" "openim" # Zookeeper的模式 -def "ZOOKEEPER_PORT" "2181" # Zookeeper的端口 -def "ZOOKEEPER_ADDRESS" "127.0.0.1" # Zookeeper的地址 -def "ZOOKEEPER_USERNAME" "" # Zookeeper的用户名 -def "ZOOKEEPER_PASSWORD" "" # Zookeeper的密码 +def "ZOOKEEPER_SCHEMA" "openim" # Zookeeper的模式 +def "ZOOKEEPER_PORT" "12181" # Zookeeper的端口 +def "ZOOKEEPER_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # Zookeeper的地址 +def "ZOOKEEPER_USERNAME" "" # Zookeeper的用户名 +def "ZOOKEEPER_PASSWORD" "" # Zookeeper的密码 ###################### MySQL 配置信息 ###################### -def "MYSQL_PORT" "13306" # MySQL的端口 -def "MYSQL_ADDRESS" "127.0.0.1" # MySQL的地址 -def "MYSQL_USERNAME" "${USER}" # MySQL的用户名 -def "MYSQL_PASSWORD" "${PASSWORD}" # MySQL的密码 -def "MYSQL_DATABASE" "${DATABASE_NAME}" # MySQL的数据库名 -def "MYSQL_MAX_OPEN_CONN" "1000" # 最大打开的连接数 -def "MYSQL_MAX_IDLE_CONN" "100" # 最大空闲连接数 -def "MYSQL_MAX_LIFETIME" "60" # 连接可以重用的最大生命周期(秒) -def "MYSQL_LOG_LEVEL" "4" # 日志级别 -def "MYSQL_SLOW_THRESHOLD" "500" # 慢查询阈值(毫秒) +def "MYSQL_PORT" "13306" # MySQL的端口 +def "MYSQL_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # MySQL的地址 +def "MYSQL_USERNAME" "${USER}" # MySQL的用户名 +def "MYSQL_PASSWORD" "${PASSWORD}" # MySQL的密码 +def "MYSQL_DATABASE" "${DATABASE_NAME}" # MySQL的数据库名 +def "MYSQL_MAX_OPEN_CONN" "1000" # 最大打开的连接数 +def "MYSQL_MAX_IDLE_CONN" "100" # 最大空闲连接数 +def "MYSQL_MAX_LIFETIME" "60" # 连接可以重用的最大生命周期(秒) +def "MYSQL_LOG_LEVEL" "4" # 日志级别 +def "MYSQL_SLOW_THRESHOLD" "500" # 慢查询阈值(毫秒) ###################### MongoDB 配置信息 ###################### -def "MONGO_URI" # MongoDB的URI -def "MONGO_PORT" "37017" # MongoDB的端口 -def "MONGO_ADDRESS" "127.0.0.1" # MongoDB的地址 -def "MONGO_DATABASE" "${DATABASE_NAME}" # MongoDB的数据库名 -def "MONGO_USERNAME" "${USER}" # MongoDB的用户名 -def "MONGO_PASSWORD" "${PASSWORD}" # MongoDB的密码 -def "MONGO_MAX_POOL_SIZE" "100" # 最大连接池大小 +def "MONGO_URI" # MongoDB的URI +def "MONGO_PORT" "37017" # MongoDB的端口 +def "MONGO_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # MongoDB的地址 +def "MONGO_DATABASE" "${DATABASE_NAME}" # MongoDB的数据库名 +def "MONGO_USERNAME" "${USER}" # MongoDB的用户名 +def "MONGO_PASSWORD" "${PASSWORD}" # MongoDB的密码 +def "MONGO_MAX_POOL_SIZE" "100" # 最大连接池大小 ###################### Object 配置信息 ###################### -def "OBJECT_ENABLE" "minio" # 对象是否启用 -def "OBJECT_APIURL" "http://${IP}:10002" # 对象的API地址 -def "MINIO_BUCKET" "openim" # MinIO的存储桶名称 -def "MINIO_PORT" "10005" # MinIO的端口 +def "OBJECT_ENABLE" "minio" # 对象是否启用 +# 对象的API地址 +readonly OBJECT_APIURL=${OBJECT_APIURL:-"http://${IP}:10002"} +def "MINIO_BUCKET" "openim" # MinIO的存储桶名称 +def "MINIO_PORT" "10005" # MinIO的端口 # MinIO的端点URL -readonly MINIO_ENDPOINT=${MINIO_ENDPOINT:-"http://127.0.0.1:${MINIO_PORT}"} -def "MINIO_ACCESS_KEY" "${USER}" # MinIO的访问密钥ID -def "MINIO_SECRET_KEY" "${PASSWORD}" # MinIO的密钥 -def "MINIO_SESSION_TOKEN" # MinIO的会话令牌 +def MINIO_ADDRESS "${DOCKER_BRIDGE_GATEWAY}" +readonly MINIO_ENDPOINT=${MINIO_ENDPOINT:-"http://${MINIO_ADDRESS}:${MINIO_PORT}"} +def "MINIO_ACCESS_KEY" "${USER}" # MinIO的访问密钥ID +def "MINIO_SECRET_KEY" "${PASSWORD}" # MinIO的密钥 +def "MINIO_SESSION_TOKEN" # MinIO的会话令牌 readonly MINIO_SIGN_ENDPOINT=${MINIO_SIGN_ENDPOINT:-"http://${IP}:${MINIO_PORT}"} # signEndpoint为minio公网地址 # MinIO的会话令牌 -def "COS_BUCKET_URL" "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" # 腾讯云COS的存储桶URL -def "COS_SECRET_ID" # 腾讯云COS的密钥ID -def "COS_SECRET_KEY" # 腾讯云COS的密钥 -def "COS_SESSION_TOKEN" # 腾讯云COS的会话令牌 -def "OSS_ENDPOINT" "https://oss-cn-chengdu.aliyuncs.com" # 阿里云OSS的端点URL -def "OSS_BUCKET" "demo-9999999" # 阿里云OSS的存储桶名称 -def "OSS_BUCKET_URL" "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" # 阿里云OSS的存储桶URL -def "OSS_ACCESS_KEY_ID" # 阿里云OSS的访问密钥ID -def "OSS_ACCESS_KEY_SECRET" # 阿里云OSS的密钥 -def "OSS_SESSION_TOKEN" # 阿里云OSS的会话令牌 +# 腾讯云COS的存储桶URL +def "COS_BUCKET_URL" "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" +def "COS_SECRET_ID" # 腾讯云COS的密钥ID +def "COS_SECRET_KEY" # 腾讯云COS的密钥 +def "COS_SESSION_TOKEN" # 腾讯云COS的会话令牌 +def "OSS_ENDPOINT" "https://oss-cn-chengdu.aliyuncs.com" # 阿里云OSS的端点URL +def "OSS_BUCKET" "demo-9999999" # 阿里云OSS的存储桶名称 +def "OSS_BUCKET_URL" "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" # 阿里云OSS的存储桶URL +def "OSS_ACCESS_KEY_ID" # 阿里云OSS的访问密钥ID +def "OSS_ACCESS_KEY_SECRET" # 阿里云OSS的密钥 +def "OSS_SESSION_TOKEN" # 阿里云OSS的会话令牌 ###################### Redis 配置信息 ###################### -def "REDIS_PORT" "16379" # Redis的端口 -def "REDIS_ADDRESS" "127.0.0.1" # Redis的地址 +def "REDIS_PORT" "16379" # Redis的端口 +def "REDIS_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # Redis的地址 def "REDIS_USERNAME" # Redis的用户名 def "REDIS_PASSWORD" "${PASSWORD}" # Redis的密码 ###################### Kafka 配置信息 ###################### -def "KAFKA_USERNAME" # Kafka的用户名 -def "KAFKA_PASSWORD" # Kafka的密码 -def "KAFKA_PORT" "9092" # Kafka的端口 -def "KAFKA_ADDR" "127.0.0.1" # Kafka的地址 -def "KAFKA_LATESTMSG_REDIS_TOPIC" "latestMsgToRedis" # Kafka的最新消息到Redis的主题 -def "KAFKA_OFFLINEMSG_MONGO_TOPIC" "offlineMsgToMongoMysql" # Kafka的离线消息到Mongo的主题 -def "KAFKA_MSG_PUSH_TOPIC" "msgToPush" # Kafka的消息到推送的主题 -def "KAFKA_CONSUMERGROUPID_REDIS" "redis" # Kafka的消费组ID到Redis -def "KAFKA_CONSUMERGROUPID_MONGO" "mongo" # Kafka的消费组ID到Mongo -def "KAFKA_CONSUMERGROUPID_MYSQL" "mysql" # Kafka的消费组ID到MySql -def "KAFKA_CONSUMERGROUPID_PUSH" "push" # Kafka的消费组ID到推送 +def "KAFKA_USERNAME" # `Kafka` 的用户名 +def "KAFKA_PASSWORD" # `Kafka` 的密码 +def "KAFKA_PORT" "19094" # `Kafka` 的端口 +def "KAFKA_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # `Kafka` 的地址 +def "KAFKA_LATESTMSG_REDIS_TOPIC" "latestMsgToRedis" # `Kafka` 的最新消息到Redis的主题 +def "KAFKA_OFFLINEMSG_MONGO_TOPIC" "offlineMsgToMongoMysql" # `Kafka` 的离线消息到Mongo的主题 +def "KAFKA_MSG_PUSH_TOPIC" "msgToPush" # `Kafka` 的消息到推送的主题 +def "KAFKA_CONSUMERGROUPID_REDIS" "redis" # `Kafka` 的消费组ID到Redis +def "KAFKA_CONSUMERGROUPID_MONGO" "mongo" # `Kafka` 的消费组ID到Mongo +def "KAFKA_CONSUMERGROUPID_MYSQL" "mysql" # `Kafka` 的消费组ID到MySql +def "KAFKA_CONSUMERGROUPID_PUSH" "push" # `Kafka` 的消费组ID到推送 + +###################### openim-web 配置信息 ###################### +def "OPENIM_WEB_PORT" "11001" # openim-web的端口 +def "OPENIM_WEB_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # openim-web的地址 +def "OPENIM_WEB_DIST_PATH" "/app/dist" # openim-web的dist路径 ###################### RPC 配置信息 ###################### -def "RPC_REGISTER_IP" # RPC的注册IP -def "RPC_LISTEN_IP" "0.0.0.0" # RPC的监听IP +def "RPC_REGISTER_IP" # RPC的注册IP +def "RPC_LISTEN_IP" "0.0.0.0" # RPC的监听IP -###################### API 配置信息 ###################### -# API的开放端口, 只能设置一个端口 -def "API_OPENIM_PORT" "10002" -def "API_LISTEN_IP" "0.0.0.0" # API的监听IP +###################### prometheus 配置 ###################### +def "PROMETHEUS_PORT" "19090" # Prometheus的端口 +def "PROMETHEUS_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # Prometheus的地址 + +###################### Grafana 配置信息 ###################### +def "GRAFANA_PORT" "3000" # Grafana的端口 +def "GRAFANA_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # Grafana的地址 ###################### RPC Port Configuration Variables ###################### # For launching multiple programs, just fill in multiple ports separated by commas @@ -175,27 +258,26 @@ readonly OPENIM_CONVERSATION_PORT=${OPENIM_CONVERSATION_PORT:-'10180'} readonly OPENIM_THIRD_PORT=${OPENIM_THIRD_PORT:-'10190'} ###################### RPC Register Name Variables ###################### -def "OPENIM_USER_NAME" "User" # OpenIM用户服务名称 -def "OPENIM_FRIEND_NAME" "Friend" # OpenIM朋友服务名称 -def "OPENIM_MSG_NAME" "Msg" # OpenIM消息服务名称 -def "OPENIM_PUSH_NAME" "Push" # OpenIM推送服务名称 -def "OPENIM_MESSAGE_GATEWAY_NAME" "MessageGateway" # OpenIM消息网关服务名称 -def "OPENIM_GROUP_NAME" "Group" # OpenIM组服务名称 -def "OPENIM_AUTH_NAME" "Auth" # OpenIM授权服务名称 -def "OPENIM_CONVERSATION_NAME" "Conversation" # OpenIM对话服务名称 -def "OPENIM_THIRD_NAME" "Third" # OpenIM第三方服务名称 +def "OPENIM_USER_NAME" "User" # OpenIM用户服务名称 +def "OPENIM_FRIEND_NAME" "Friend" # OpenIM朋友服务名称 +def "OPENIM_MSG_NAME" "Msg" # OpenIM消息服务名称 +def "OPENIM_PUSH_NAME" "Push" # OpenIM推送服务名称 +def "OPENIM_MESSAGE_GATEWAY_NAME" "MessageGateway" # OpenIM消息网关服务名称 +def "OPENIM_GROUP_NAME" "Group" # OpenIM组服务名称 +def "OPENIM_AUTH_NAME" "Auth" # OpenIM授权服务名称 +def "OPENIM_CONVERSATION_NAME" "Conversation" # OpenIM对话服务名称 +def "OPENIM_THIRD_NAME" "Third" # OpenIM第三方服务名称 ###################### Log Configuration Variables ###################### def "LOG_STORAGE_LOCATION" ""${OPENIM_ROOT}"/logs/" # 日志存储位置 -def "LOG_ROTATION_TIME" "24" # 日志轮替时间 -def "LOG_REMAIN_ROTATION_COUNT" "2" # 保留的日志轮替数量 -def "LOG_REMAIN_LOG_LEVEL" "6" # 保留的日志级别 -def "LOG_IS_STDOUT" "false" # 是否将日志输出到标准输出 -def "LOG_IS_JSON" "false" # 日志是否为JSON格式 -def "LOG_WITH_STACK" "false" # 日志是否带有堆栈信息 +def "LOG_ROTATION_TIME" "24" # 日志轮替时间 +def "LOG_REMAIN_ROTATION_COUNT" "2" # 保留的日志轮替数量 +def "LOG_REMAIN_LOG_LEVEL" "6" # 保留的日志级别 +def "LOG_IS_STDOUT" "false" # 是否将日志输出到标准输出 +def "LOG_IS_JSON" "false" # 日志是否为JSON格式 +def "LOG_WITH_STACK" "false" # 日志是否带有堆栈信息 ###################### Variables definition ###################### -def "OPENIM_WS_PORT" "10001" # OpenIM WS端口 def "WEBSOCKET_MAX_CONN_NUM" "100000" # Websocket最大连接数 def "WEBSOCKET_MAX_MSG_LEN" "4096" # Websocket最大消息长度 def "WEBSOCKET_TIMEOUT" "10" # Websocket超时 @@ -223,32 +305,43 @@ def "RETAIN_CHAT_RECORDS" "365" # 保留聊天记录 readonly CHAT_RECORDS_CLEAR_TIME=${CHAT_RECORDS_CLEAR_TIME:-'0 2 * * 3'} # 消息销毁时间 readonly MSG_DESTRUCT_TIME=${MSG_DESTRUCT_TIME:-'0 2 * * *'} -def "SECRET" "${PASSWORD}" # 密钥 -def "TOKEN_EXPIRE" "90" # Token到期时间 -def "FRIEND_VERIFY" "false" # 朋友验证 -def "IOS_PUSH_SOUND" "xxx" # IOS推送声音 -def "IOS_BADGE_COUNT" "true" # IOS徽章计数 -def "IOS_PRODUCTION" "false" # IOS生产 +def "SECRET" "${PASSWORD}" # 密钥 +def "TOKEN_EXPIRE" "90" # Token到期时间 +def "FRIEND_VERIFY" "false" # 朋友验证 +def "IOS_PUSH_SOUND" "xxx" # IOS推送声音 +def "IOS_BADGE_COUNT" "true" # IOS徽章计数 +def "IOS_PRODUCTION" "false" # IOS生产 ###################### Prometheus 配置信息 ###################### -def "PROMETHEUS_ENABLE" "false" # 是否启用 Prometheus -def "USER_PROM_PORT" "20110" # User 服务的 Prometheus 端口 -def "FRIEND_PROM_PORT" "20120" # Friend 服务的 Prometheus 端口 -def "MESSAGE_PROM_PORT" "20130" # Message 服务的 Prometheus 端口 -def "MSG_GATEWAY_PROM_PORT" "20140" # Message Gateway 服务的 Prometheus 端口 -def "GROUP_PROM_PORT" "20150" # Group 服务的 Prometheus 端口 -def "AUTH_PROM_PORT" "20160" # Auth 服务的 Prometheus 端口 -def "PUSH_PROM_PORT" "20170" # Push 服务的 Prometheus 端口 -def "CONVERSATION_PROM_PORT" "20230" # Conversation 服务的 Prometheus 端口 -def "RTC_PROM_PORT" "21300" # RTC 服务的 Prometheus 端口 -def "THIRD_PROM_PORT" "21301" # Third 服务的 Prometheus 端口 +def "PROMETHEUS_ENABLE" "false" # 是否启用 Prometheus +# User 服务的 Prometheus 端口 +readonly USER_PROM_PORT=${USER_PROM_PORT:-'20110'} +# Friend 服务的 Prometheus 端口 +readonly FRIEND_PROM_PORT=${FRIEND_PROM_PORT:-'20120'} +# Message 服务的 Prometheus 端口 +readonly MESSAGE_PROM_PORT=${MESSAGE_PROM_PORT:-'20130'} +# Message Gateway 服务的 Prometheus 端口 +readonly MSG_GATEWAY_PROM_PORT=${MSG_GATEWAY_PROM_PORT:-'20140'} +# Group 服务的 Prometheus 端口 +readonly GROUP_PROM_PORT=${GROUP_PROM_PORT:-'20150'} +# Auth 服务的 Prometheus 端口 +readonly AUTH_PROM_PORT=${AUTH_PROM_PORT:-'20160'} +# Push 服务的 Prometheus 端口 +readonly PUSH_PROM_PORT=${PUSH_PROM_PORT:-'20170'} +# Conversation 服务的 Prometheus 端口 +readonly CONVERSATION_PROM_PORT=${CONVERSATION_PROM_PORT:-'20230'} +# RTC 服务的 Prometheus 端口 +readonly RTC_PROM_PORT=${RTC_PROM_PORT:-'21300'} +# Third 服务的 Prometheus 端口 +readonly THIRD_PROM_PORT=${THIRD_PROM_PORT:-'21301'} + # Message Transfer 服务的 Prometheus 端口列表 readonly MSG_TRANSFER_PROM_PORT=${MSG_TRANSFER_PROM_PORT:-'21400, 21401, 21402, 21403'} ###################### OpenIM openim-api ###################### def "OPENIM_API_HOST" "127.0.0.1" def "OPENIM_API_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-api" # OpenIM openim-api 二进制文件路径 -def "OPENIM_API_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-api 配置文件路径 +def "OPENIM_API_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-api 配置文件路径 def "OPENIM_API_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-api" # OpenIM openim-api 日志存储路径 def "OPENIM_API_LOG_LEVEL" "info" # OpenIM openim-api 日志级别 def "OPENIM_API_LOG_MAX_SIZE" "100" # OpenIM openim-api 日志最大大小(MB) @@ -260,7 +353,7 @@ def "OPENIM_API_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-ap ###################### OpenIM openim-cmdutils ###################### def "OPENIM_CMDUTILS_HOST" "127.0.0.1" def "OPENIM_CMDUTILS_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-cmdutils" # OpenIM openim-cmdutils 二进制文件路径 -def "OPENIM_CMDUTILS_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-cmdutils 配置文件路径 +def "OPENIM_CMDUTILS_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-cmdutils 配置文件路径 def "OPENIM_CMDUTILS_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-cmdutils" # OpenIM openim-cmdutils 日志存储路径 def "OPENIM_CMDUTILS_LOG_LEVEL" "info" # OpenIM openim-cmdutils 日志级别 def "OPENIM_CMDUTILS_LOG_MAX_SIZE" "100" # OpenIM openim-cmdutils 日志最大大小(MB) @@ -272,7 +365,7 @@ def "OPENIM_CMDUTILS_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM ###################### OpenIM openim-crontask ###################### def "OPENIM_CRONTASK_HOST" "127.0.0.1" def "OPENIM_CRONTASK_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-crontask" # OpenIM openim-crontask 二进制文件路径 -def "OPENIM_CRONTASK_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-crontask 配置文件路径 +def "OPENIM_CRONTASK_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-crontask 配置文件路径 def "OPENIM_CRONTASK_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-crontask" # OpenIM openim-crontask 日志存储路径 def "OPENIM_CRONTASK_LOG_LEVEL" "info" # OpenIM openim-crontask 日志级别 def "OPENIM_CRONTASK_LOG_MAX_SIZE" "100" # OpenIM openim-crontask 日志最大大小(MB) @@ -299,7 +392,7 @@ readonly OPENIM_MSGGATEWAY_NUM=${OPENIM_MSGGATEWAY_NUM:-'4'} ###################### OpenIM openim-msgtransfer ###################### def "OPENIM_MSGTRANSFER_HOST" "127.0.0.1" def "OPENIM_MSGTRANSFER_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer" # OpenIM openim-msgtransfer 二进制文件路径 -def "OPENIM_MSGTRANSFER_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-msgtransfer 配置文件路径 +def "OPENIM_MSGTRANSFER_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-msgtransfer 配置文件路径 def "OPENIM_MSGTRANSFER_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-msgtransfer" # OpenIM openim-msgtransfer 日志存储路径 def "OPENIM_MSGTRANSFER_LOG_LEVEL" "info" # OpenIM openim-msgtransfer 日志级别 def "OPENIM_MSGTRANSFER_LOG_MAX_SIZE" "100" # OpenIM openim-msgtransfer 日志最大大小(MB) @@ -311,7 +404,7 @@ def "OPENIM_MSGTRANSFER_LOG_WITH_STACK" "${LOG_WITH_STACK}" # ###################### OpenIM openim-push ###################### def "OPENIM_PUSH_HOST" "127.0.0.1" def "OPENIM_PUSH_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-push" # OpenIM openim-push 二进制文件路径 -def "OPENIM_PUSH_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-push 配置文件路径 +def "OPENIM_PUSH_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-push 配置文件路径 def "OPENIM_PUSH_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-push" # OpenIM openim-push 日志存储路径 def "OPENIM_PUSH_LOG_LEVEL" "info" # OpenIM openim-push 日志级别 def "OPENIM_PUSH_LOG_MAX_SIZE" "100" # OpenIM openim-push 日志最大大小(MB) @@ -323,7 +416,7 @@ def "OPENIM_PUSH_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim- ###################### OpenIM openim-rpc-auth ###################### def "OPENIM_RPC_AUTH_HOST" "127.0.0.1" def "OPENIM_RPC_AUTH_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-auth" # OpenIM openim-rpc-auth 二进制文件路径 -def "OPENIM_RPC_AUTH_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-auth 配置文件路径 +def "OPENIM_RPC_AUTH_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-auth 配置文件路径 def "OPENIM_RPC_AUTH_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-auth" # OpenIM openim-rpc-auth 日志存储路径 def "OPENIM_RPC_AUTH_LOG_LEVEL" "info" # OpenIM openim-rpc-auth 日志级别 def "OPENIM_RPC_AUTH_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-auth 日志最大大小(MB) @@ -335,7 +428,7 @@ def "OPENIM_RPC_AUTH_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM ###################### OpenIM openim-rpc-conversation ###################### def "OPENIM_RPC_CONVERSATION_HOST" "127.0.0.1" def "OPENIM_RPC_CONVERSATION_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-conversation" # OpenIM openim-rpc-conversation 二进制文件路径 -def "OPENIM_RPC_CONVERSATION_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-conversation 配置文件路径 +def "OPENIM_RPC_CONVERSATION_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-conversation 配置文件路径 def "OPENIM_RPC_CONVERSATION_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-conversation" # OpenIM openim-rpc-conversation 日志存储路径 def "OPENIM_RPC_CONVERSATION_LOG_LEVEL" "info" # OpenIM openim-rpc-conversation 日志级别 def "OPENIM_RPC_CONVERSATION_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-conversation 日志最大大小(MB) @@ -347,7 +440,7 @@ def "OPENIM_RPC_CONVERSATION_LOG_WITH_STACK" "${LOG_WITH_STACK}" ###################### OpenIM openim-rpc-friend ###################### def "OPENIM_RPC_FRIEND_HOST" "127.0.0.1" def "OPENIM_RPC_FRIEND_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-friend" # OpenIM openim-rpc-friend 二进制文件路径 -def "OPENIM_RPC_FRIEND_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-friend 配置文件路径 +def "OPENIM_RPC_FRIEND_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-friend 配置文件路径 def "OPENIM_RPC_FRIEND_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-friend" # OpenIM openim-rpc-friend 日志存储路径 def "OPENIM_RPC_FRIEND_LOG_LEVEL" "info" # OpenIM openim-rpc-friend 日志级别 def "OPENIM_RPC_FRIEND_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-friend 日志最大大小(MB) @@ -359,7 +452,7 @@ def "OPENIM_RPC_FRIEND_LOG_WITH_STACK" "${LOG_WITH_STACK}" # Op ###################### OpenIM openim-rpc-group ###################### def "OPENIM_RPC_GROUP_HOST" "127.0.0.1" def "OPENIM_RPC_GROUP_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-group" # OpenIM openim-rpc-group 二进制文件路径 -def "OPENIM_RPC_GROUP_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-group 配置文件路径 +def "OPENIM_RPC_GROUP_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-group 配置文件路径 def "OPENIM_RPC_GROUP_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-group" # OpenIM openim-rpc-group 日志存储路径 def "OPENIM_RPC_GROUP_LOG_LEVEL" "info" # OpenIM openim-rpc-group 日志级别 def "OPENIM_RPC_GROUP_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-group 日志最大大小(MB) @@ -371,7 +464,7 @@ def "OPENIM_RPC_GROUP_LOG_WITH_STACK" "${LOG_WITH_STACK}" # Open ###################### OpenIM openim-rpc-msg ###################### def "OPENIM_RPC_MSG_HOST" "127.0.0.1" def "OPENIM_RPC_MSG_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-msg" # OpenIM openim-rpc-msg 二进制文件路径 -def "OPENIM_RPC_MSG_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-msg 配置文件路径 +def "OPENIM_RPC_MSG_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-msg 配置文件路径 def "OPENIM_RPC_MSG_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-msg" # OpenIM openim-rpc-msg 日志存储路径 def "OPENIM_RPC_MSG_LOG_LEVEL" "info" # OpenIM openim-rpc-msg 日志级别 def "OPENIM_RPC_MSG_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-msg 日志最大大小(MB) @@ -383,7 +476,7 @@ def "OPENIM_RPC_MSG_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM o ###################### OpenIM openim-rpc-third ###################### def "OPENIM_RPC_THIRD_HOST" "127.0.0.1" def "OPENIM_RPC_THIRD_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-third" # OpenIM openim-rpc-third 二进制文件路径 -def "OPENIM_RPC_THIRD_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-third 配置文件路径 +def "OPENIM_RPC_THIRD_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-third 配置文件路径 def "OPENIM_RPC_THIRD_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-third" # OpenIM openim-rpc-third 日志存储路径 def "OPENIM_RPC_THIRD_LOG_LEVEL" "info" # OpenIM openim-rpc-third 日志级别 def "OPENIM_RPC_THIRD_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-third 日志最大大小(MB) @@ -395,7 +488,7 @@ def "OPENIM_RPC_THIRD_LOG_WITH_STACK" "${LOG_WITH_STACK}" # Open ###################### OpenIM openim-rpc-user ###################### def "OPENIM_RPC_USER_HOST" "127.0.0.1" def "OPENIM_RPC_USER_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-user" # OpenIM openim-rpc-user 二进制文件路径 -def "OPENIM_RPC_USER_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-user 配置文件路径 +def "OPENIM_RPC_USER_CONFIG" ""${OPENIM_ROOT}"/config/" # OpenIM openim-rpc-user 配置文件路径 def "OPENIM_RPC_USER_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-user" # OpenIM openim-rpc-user 日志存储路径 def "OPENIM_RPC_USER_LOG_LEVEL" "info" # OpenIM openim-rpc-user 日志级别 def "OPENIM_RPC_USER_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-user 日志最大大小(MB) diff --git a/scripts/install/openim-api.sh b/scripts/install/openim-api.sh index b41d42d7a..5239b95e7 100755 --- a/scripts/install/openim-api.sh +++ b/scripts/install/openim-api.sh @@ -53,7 +53,7 @@ function openim::api::start() done # start all api services for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do - openim::util::stop_services_with_name ${OPENIM_API_SERVICE_LISTARIES[$i]} + openim::util::stop_services_on_ports ${OPENIM_API_PORT_LISTARIES[$i]} openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}" # Get the service and Prometheus ports. diff --git a/scripts/install/openim-msggateway.sh b/scripts/install/openim-msggateway.sh index de5656b0c..1010fbbec 100755 --- a/scripts/install/openim-msggateway.sh +++ b/scripts/install/openim-msggateway.sh @@ -33,32 +33,36 @@ function openim::msggateway::start() openim::util::stop_services_with_name ${SERVER_NAME} # OpenIM message gateway service port - OPENIM_RPC_PORTS=$(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} ) + OPENIM_MESSAGE_GATEWAY_PORTS=$(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} ) + read -a OPENIM_MSGGATEWAY_PORTS_ARRAY <<< ${OPENIM_MESSAGE_GATEWAY_PORTS} + # OpenIM WS port OPENIM_WS_PORTS=$(openim::util::list-to-string ${OPENIM_WS_PORT} ) + read -a OPENIM_WS_PORTS_ARRAY <<< ${OPENIM_WS_PORTS} + # Message Gateway Prometheus port of the service MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string ${MSG_GATEWAY_PROM_PORT} ) + read -a MSG_GATEWAY_PROM_PORTS_ARRAY <<< ${MSG_GATEWAY_PROM_PORTS} - openim::log::status "OpenIM RPC ports: ${OPENIM_RPC_PORTS[*]}" + openim::log::status "OpenIM Mssage Getway ports: ${OPENIM_MESSAGE_GATEWAY_PORTS[*]}" openim::log::status "OpenIM WS ports: ${OPENIM_WS_PORTS[*]}" openim::log::status "OpenIM Prometheus ports: ${MSG_GATEWAY_PROM_PORTS[*]}" openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGGATEWAY_CONFIG}" - if [ ${#OPENIM_RPC_PORTS[@]} -ne ${#OPENIM_WS_PORTS[@]} ]; then - openim::log::error "ws_ports does not match push_rpc_ports or prome_ports in quantity!!!" - exit 1 + if [ ${#OPENIM_MSGGATEWAY_PORTS_ARRAY[@]} -ne ${#OPENIM_WS_PORTS_ARRAY[@]} ]; then + openim::log::error_exit "ws_ports does not match push_rpc_ports or prome_ports in quantity!!!" fi - for ((i = 0; i < ${#OPENIM_WS_PORTS[@]}; i++)); do - openim::log::info "start push process, port: ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_MSGGATEWAY_PORTS_ARRAY[$i]}" - - PROMETHEUS_PORT_OPTION="" - if [[ -n "${MSG_GATEWAY_PROM_PORTS[$i]}" ]]; then - PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS[$i]}" - fi + for ((i = 0; i < ${#OPENIM_WS_PORTS_ARRAY[@]}; i++)); do + openim::log::info "start push process, port: ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]}, prometheus port: ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}" + + PROMETHEUS_PORT_OPTION="" + if [[ -n "${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}" ]]; then + PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}" + fi - nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_RPC_PORTS[$i]} --ws_port ${OPENIM_WS_PORTS[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2>&1 & + nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2>&1 & done openim::util::check_process_names ${SERVER_NAME} diff --git a/scripts/install/openim-rpc.sh b/scripts/install/openim-rpc.sh index 35745bff3..a0a7868f1 100755 --- a/scripts/install/openim-rpc.sh +++ b/scripts/install/openim-rpc.sh @@ -38,7 +38,6 @@ # Note: Before executing this script, ensure that the necessary permissions are granted and relevant environmental variables are set. # - set -o errexit set +o nounset set -o pipefail @@ -122,20 +121,25 @@ function openim::rpc::start() { # start all rpc services for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do - openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES[$i]} + # openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES + openim::util::stop_services_on_ports ${OPENIM_RPC_PORT_LISTARIES[$i]} openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}" # Get the service and Prometheus ports. OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PORT_LISTARIES[$i]}) ) + read -a OPENIM_RPC_SERVICE_PORTS_ARRAY <<< ${OPENIM_RPC_SERVICE_PORTS} + OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}) ) - - for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS[@]}; j++)); do + read -a OPENIM_RPC_PROM_PORTS_ARRAY <<< ${OPENIM_RPC_PROM_PORTS} + + for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS_ARRAY[@]}; j++)); do openim::log::info "Starting ${OPENIM_RPC_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_RPC_SERVICE_PORTS[j]}, prometheus port: ${OPENIM_RPC_PROM_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_RPC_SERVICE_LISTARIES[$i]}" openim::rpc::start_service "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}" - sleep 0.5 done done + sleep 0.5 + openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]} # openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]} diff --git a/scripts/install/openim-tools.sh b/scripts/install/openim-tools.sh index 81291c38d..1dacf68a8 100755 --- a/scripts/install/openim-tools.sh +++ b/scripts/install/openim-tools.sh @@ -71,6 +71,7 @@ readonly OPENIM_TOOLS_PRE_START_NAME_LISTARIES=("${OPENIM_TOOLS_PRE_START_NAME_T openim::tools::post_start_name() { local targets=( infra + versionchecker ) echo "${targets[@]}" } diff --git a/scripts/lib/logging.sh b/scripts/lib/logging.sh index 7dc0c0c2a..021a366e1 100755 --- a/scripts/lib/logging.sh +++ b/scripts/lib/logging.sh @@ -212,11 +212,11 @@ openim::log::success() function openim::log::test_log() { echo_log "test log" - openim::log::error "openim::log::error" openim::log::info "openim::log::info" openim::log::progress "openim::log::progress" openim::log::status "openim::log::status" openim::log::success "openim::log::success" + openim::log::error "openim::log::error" openim::log::error_exit "openim::log::error_exit" } diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 56f2a16c6..6825797e1 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -267,25 +267,34 @@ openim::util::check_ports() { openim::log::info "Checking ports: $*" # Iterate over each given port. for port in "$@"; do - # Use the `lsof` command to find process information related to the given port. - local info=$(lsof -i :$port -n -P | grep LISTEN || true) + # Use the `ss` command to find process information related to the given port. + local info=$(ss -ltnp | grep ":$port" || true) # If there's no process information, it means the process associated with the port is not running. if [[ -z $info ]]; then not_started+=($port) else - # If there's process information, extract relevant details: - # Process ID, Command Name, and Start Time. - local pid=$(echo $info | awk '{print $2}') - local command=$(echo $info | awk '{print $1}') - local start_time=$(ps -o lstart= -p $pid) - started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time") + # Extract relevant details: Process Name, PID, and FD. + local details=$(echo $info | sed -n 's/.*users:(("\([^"]*\)",pid=\([^,]*\),fd=\([^)]*\))).*/\1 \2 \3/p') + local command=$(echo $details | awk '{print $1}') + local pid=$(echo $details | awk '{print $2}') + local fd=$(echo $details | awk '{print $3}') + + # Get the start time of the process using the PID + if [[ -z $pid ]]; then + local start_time="N/A" + else + # Get the start time of the process using the PID + local start_time=$(ps -p $pid -o lstart=) + fi + + started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time") fi done - echo + # Print information about ports whose processes are not running. if [[ ${#not_started[@]} -ne 0 ]]; then - openim::log::info "### Not started ports:" + openim::log::info "\n### Not started ports:" for port in "${not_started[@]}"; do openim::log::error "Port $port is not started." done @@ -293,8 +302,7 @@ openim::util::check_ports() { # Print information about ports whose processes are running. if [[ ${#started[@]} -ne 0 ]]; then - echo - openim::log::info "### Started ports:" + openim::log::info "\n### Started ports:" for info in "${started[@]}"; do openim::log::info "$info" done @@ -305,11 +313,14 @@ openim::util::check_ports() { echo "++++ OpenIM Log >> cat ${LOG_FILE}" return 1 else - openim::log::success "started[@] processes are running." + openim::log::success "All specified processes are running." return 0 fi } -# openim::util::check_ports 10002 1004 +# set +o errexit +# Sample call for testing: +# openim::util::check_ports 10002 1004 12345 13306 +# set -o errexit # The `openim::util::check_process_names` function analyzes the state of processes based on given names. # It accepts multiple process names as arguments and prints: @@ -895,13 +906,13 @@ function openim::util::list-to-string() { # 2. Replace commas with spaces # 3. Remove opening and closing brackets ports_array=$(echo "$ports_list" | sed 's/ //g; s/,/ /g; s/^\[\(.*\)\]$/\1/') - # For external use, we might want to echo the result so that it can be captured by callers echo "$ports_array" } # MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string "10023, 2323, 34 34") +# read -a MSG_GATEWAY_PROM_PORTS <<< $(openim::util::list-to-string "10023, 2323, 34 34") # echo ${MSG_GATEWAY_PROM_PORTS} - +# echo "${#MSG_GATEWAY_PROM_PORTS[@]}" # Downloads cfssl/cfssljson/cfssl-certinfo into $1 directory if they do not already exist in PATH # # Assumed vars: diff --git a/scripts/make-rules/common.mk b/scripts/make-rules/common.mk index 1473963df..f72d22f73 100644 --- a/scripts/make-rules/common.mk +++ b/scripts/make-rules/common.mk @@ -140,10 +140,6 @@ ifndef V MAKEFLAGS += --no-print-directory endif -# Copy githook scripts when execute makefile -# TODO! GIT_FILE_SIZE_LIMIT=42000000 git commit -m "This commit is allowed file sizes up to 42MB" -COPY_GITHOOK:=$(shell cp -f scripts/githooks/* .git/hooks/; chmod +x .git/hooks/*) - # COMMA: Concatenate multiple strings to form a list of strings COMMA := , # SPACE: Used to separate strings diff --git a/scripts/make-rules/gen.mk b/scripts/make-rules/gen.mk index 60bfdd47a..1671fafff 100644 --- a/scripts/make-rules/gen.mk +++ b/scripts/make-rules/gen.mk @@ -28,6 +28,12 @@ gen.init: @echo "===========> Initializing openim server project" @${ROOT_DIR}/scripts/init-config.sh +## gen.init-githooks: Initialize git hooks ✨ +.PHONY: gen.init-githooks +gen.init-githooks: + @echo "===========> Initializing git hooks" + @${ROOT_DIR}/scripts/init-githooks.sh + ## gen.run: Generate necessary files and docs ✨ .PHONY: gen.run #gen.run: gen.errcode gen.docgo diff --git a/scripts/start-all.sh b/scripts/start-all.sh index 2961d44f7..64b931f50 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -22,6 +22,8 @@ set -o pipefail OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/install/common.sh" +openim::log::info "\n# Begin to start all openim service scripts" + set +o errexit openim::golang::check_openim_binaries if [[ $? -ne 0 ]]; then @@ -61,16 +63,21 @@ function execute_scripts() { else openim::log::errexit "Script ${script_path##*/} is missing or not executable." fi - sleep 0.5 done + sleep 0.5 } + # TODO Prelaunch tools, simple for now, can abstract functions later TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh + +openim::log::info "\n## Pre Starting OpenIM services" ${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start +openim::log::info "\n## Starting OpenIM services" execute_scripts +openim::log::info "\n## Post Starting OpenIM services" ${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start openim::log::success "✨ All OpenIM services have been successfully started!" \ No newline at end of file diff --git a/scripts/stop-all.sh b/scripts/stop-all.sh index 611caffe1..090c48b0d 100755 --- a/scripts/stop-all.sh +++ b/scripts/stop-all.sh @@ -26,6 +26,8 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/install/common.sh" +openim::log::info "\n# Begin to stop all openim service" + echo "++ Ready to stop port: ${OPENIM_SERVER_PORT_LISTARIES[@]}" openim::util::stop_services_on_ports ${OPENIM_SERVER_PORT_LISTARIES[@]} diff --git a/scripts/template/footer.md.tmpl b/scripts/template/footer.md.tmpl index 75a42d23c..4f9ab29ab 100644 --- a/scripts/template/footer.md.tmpl +++ b/scripts/template/footer.md.tmpl @@ -8,7 +8,7 @@ If you encounter any problems during its usage, please create an issue in the [G **Here are some ways to get involved with the OpenIM community:** -📢 **Slack Channel**: Join our Slack channels for discussions, communication, and support. Click [here](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) to join the Open-IM-Server Slack team channel. +📢 **Slack Channel**: Join our Slack channels for discussions, communication, and support. Click [here](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) to join the Open-IM-Server Slack team channel. 📧 **Gmail Contact**: If you have any questions, suggestions, or feedback for our open-source projects, please feel free to [contact us via email](https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=winxu81@gmail.com). diff --git a/test/data-conversion/kafka-conversation.go b/test/data-conversion/kafka-conversation.go index e3a26e009..a3fd0dc87 100644 --- a/test/data-conversion/kafka-conversation.go +++ b/test/data-conversion/kafka-conversation.go @@ -25,11 +25,12 @@ var ( addr = "127.0.0.1:9092" ) -var consumer sarama.Consumer -var producer sarama.SyncProducer +var ( + consumer sarama.Consumer + producer sarama.SyncProducer +) func init() { - //Producer config := sarama.NewConfig() // Instantiate a sarama Config config.Producer.Return.Successes = true // Whether to enable the successes channel to be notified after the message is sent successfully @@ -43,7 +44,7 @@ func init() { } producer = client - //Consumer + // Consumer consumerT, err := sarama.NewConsumer([]string{addr}, sarama.NewConfig()) if err != nil { fmt.Printf("fail to start consumer, err:%v\n", err) diff --git a/test/data-conversion/mysql-conversion.go b/test/data-conversion/mysql-conversion.go index 08d7ab789..58318cd3d 100644 --- a/test/data-conversion/mysql-conversion.go +++ b/test/data-conversion/mysql-conversion.go @@ -158,7 +158,7 @@ func GroupConversion() { temp := time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC) if val.NotificationUpdateTime.Equal(temp) { results[i].NotificationUpdateTime = time.Now() - //fmt.Println(val.NotificationUpdateTime) + // fmt.Println(val.NotificationUpdateTime) } } // Process query results @@ -220,7 +220,7 @@ func ChatLogsConversion() { MysqlDb_v2.Limit(batchSize).Offset(offset).Find(&results) // Process query results fmt.Println("============================batch data===================", offset, batchSize) - //fmt.Println(results) + // fmt.Println(results) MysqlDb_v3.Create(results) fmt.Println("======================================================") offset += batchSize diff --git a/test/README.md b/test/readme similarity index 100% rename from test/README.md rename to test/readme diff --git a/test/typecheck/go.mod b/test/typecheck/go.mod index 5bc1000ed..253c4641e 100644 --- a/test/typecheck/go.mod +++ b/test/typecheck/go.mod @@ -1,6 +1,6 @@ module github.com/OpenIMSDK/Open-IM-Server/test/typecheck -go 1.20 +go 1.18 require golang.org/x/tools v0.12.0 diff --git a/tools/changelog/go.mod b/tools/changelog/go.mod index 319cdecec..bc3f2192d 100644 --- a/tools/changelog/go.mod +++ b/tools/changelog/go.mod @@ -1,3 +1,3 @@ module github.com/OpenIMSDK/Open-IM-Server/tools/changelog -go 1.20 +go 1.18 diff --git a/tools/imctl/cmd/imctl/imctl.go b/tools/component/component_test.go similarity index 50% rename from tools/imctl/cmd/imctl/imctl.go rename to tools/component/component_test.go index fea2023a9..eaf139418 100644 --- a/tools/imctl/cmd/imctl/imctl.go +++ b/tools/component/component_test.go @@ -12,18 +12,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -// iamctl is the command line tool for iam platform. package main import ( - "os" + "testing" - "github.com/OpenIMSDK/Open-IM-Server/tools/imctl/internal/imctl/cmd" + "github.com/stretchr/testify/assert" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) -func main() { - command := cmd.NewDefaultIMCtlCommand() - if err := command.Execute(); err != nil { - os.Exit(1) +func TestCheckMysql(t *testing.T) { + err := mockInitCfg() + assert.NoError(t, err, "Initialization should not produce errors") + + err = checkMysql() + if err != nil { + // You might expect an error if MySQL isn't running locally with the mock credentials. + t.Logf("Expected error due to mock configuration: %v", err) } } + +// Mock for initCfg for testing purpose +func mockInitCfg() error { + config.Config.Mysql.Username = "root" + config.Config.Mysql.Password = "openIM123" + config.Config.Mysql.Address = []string{"127.0.0.1:13306"} + return nil +} diff --git a/tools/component/go.mod b/tools/component/go.mod index bc7abc133..c38541ed7 100644 --- a/tools/component/go.mod +++ b/tools/component/go.mod @@ -1,3 +1,3 @@ module github.com/OpenIMSDK/Open-IM-Server/tools/component -go 1.19 +go 1.18 diff --git a/tools/imctl/README.md b/tools/imctl/README.md deleted file mode 100644 index d5f674b55..000000000 --- a/tools/imctl/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# OpenIM CTL 模块 - - -## 为什么设计这个模块 - -OpenIM 后期功能扩展,不能总依赖一些单独的模块,而是整合到 Imctl 中。 - -测试同学做自动化测试或者是 e2e 测试,接口测试等等,每一次调用 API 很麻烦,用 imctl 的方式为 api 的调用提供了方便 - -和 scripts 深度交互,同样减少了 IM 本身的耦合度,提高了 IM 的可扩展性。 - - -## 功能设计 - -+ 用户管理:例如,添加、删除或禁用用户账户。 - -+ 系统监控:查看在线用户数量、消息传送速率等关键性能指标。 - -+ 调试:如查看日志、调整日志级别、查看系统状态等。 - -+ 配置管理:更新系统设置、管理插件或模块等。 - -+ 数据管理:备份和恢复数据、导入和导出数据等。 - -+ 系统维护:例如,执行更新、重启服务、进行维护模式等。 - - -## 设计思路 - -参考 kubectl, 方便 开发、运维、测试同学使用系统功能,并且实现自动化功能。 - -**自动化设计思路:** -1. 为后面的扩展子模块或者子命令提供自动化的功能,提供子命令 `imctl new` 自动创建新的子命令 -2. 以通过 imctl 对用户、密钥和策略进行CURD操作 -3. 设置 imctl 自动补全脚本 -4. 版本管理,问题:https://github.com/OpenIMSDK/Open-IM-Server/issues/574,做 IM 自动化的版本管理,查看 IM 系统版本 - -一些简单的 IM 解决方案可能不需要这样的工具,而复杂、高度定制的系统可能会从中受益。 - -所以暂时将这个模块放在 tools/imctl 中,后面迁移到 cmd/imctl 中 - - -## 目录结构设计 - -为了方便迁移,将 imctl 工程化设计,命令工具放入到 tools/imctl/cmd 中,其他的模块放入到 tools/imctl/pkg 中 - -``` \ No newline at end of file diff --git a/tools/imctl/cmd/genman/README.md b/tools/imctl/cmd/genman/README.md deleted file mode 100644 index 7b46cbefb..000000000 --- a/tools/imctl/cmd/genman/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# OpenIM `man` Module README - -Welcome to the `man` module of OpenIM, the comprehensive guide for using OpenIM's range of powerful commands. Here, you'll find in-depth details for each command, its options, and examples to help you harness the full power of the OpenIM suite. - -## Overview - -OpenIM is a robust instant messaging solution. To ensure users can effectively harness its capabilities, OpenIM provides a suite of commands that serve different functionalities, from the API level to RPC calls and utilities. - -The `man` module ensures that users, both new and experienced, have a reliable source of information and documentation to use these commands effectively. - -## Available Commands - -The OpenIM commands are divided into core services and tools. Below is a brief overview of each: - -### Core Services - -- **openim-api**: Interface to the main functionalities of OpenIM. -- **openim-cmdutils**: Utilities for executing common tasks. -- **openim-crontask**: Schedule and manage routine tasks within OpenIM. -- **openim-msggateway**: Gateway for managing messages within the OpenIM system. -- **openim-msgtransfer**: Handle message transfers across different parts of OpenIM. -- **openim-push**: Service for pushing notifications and updates. -- **openim-rpc-auth**: RPC interface for authentication tasks. -- **openim-rpc-conversation**: RPC service for handling conversations. -- **openim-rpc-friend**: Manage friend lists and related functionalities through RPC. -- **openim-rpc-group**: Group management via RPC. -- **openim-rpc-msg**: Message handling at the RPC level. -- **openim-rpc-third**: Third-party integrations and related tasks through RPC. -- **openim-rpc-user**: User management and tasks via RPC. - -### Tools - -- **changelog**: Track and manage changes in OpenIM. -- **component**: Utilities related to different components within OpenIM. -- **infra**: Infrastructure and backend management tools. -- **ncpu**: Monitor and manage CPU usage and related tasks. -- **yamlfmt**: A tool for formatting and linting YAML files within the OpenIM configuration. - -## How to Use - -To view the manual page for any of the OpenIM commands, use the `man` command followed by the command name. For example: - -``` -man openim-api -``` - -## Contributions - -We welcome contributions to enhance the `man` pages. If you discover inconsistencies, errors, or areas where further details are required, feel free to raise an issue or submit a pull request. \ No newline at end of file diff --git a/tools/imctl/cmd/genman/genman.go b/tools/imctl/cmd/genman/genman.go deleted file mode 100644 index 1de5c68cd..000000000 --- a/tools/imctl/cmd/genman/genman.go +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -package main - -import ( - "fmt" - "os" - - "k8s.io/kubernetes/cmd/genutils" -) - -func main() { - // TODO use os.Args instead of "flags" because "flags" will mess up the man pages! - path := "docs/man/man1" - module := "" - if len(os.Args) == 3 { - path = os.Args[1] - module = os.Args[2] - } else { - fmt.Fprintf(os.Stderr, "usage: %s [output directory] [module] \n", os.Args[0]) - os.Exit(1) - } - - outDir, err := genutils.OutDir(path) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err) - os.Exit(1) - } - - // Set environment variables used by command so the output is consistent, - // regardless of where we run. - os.Setenv("HOME", "/home/username") - - // openim-api - // openim-cmdutils - // openim-crontask - // openim-msggateway - // openim-msgtransfer - // openim-push - // openim-rpc-auth - // openim-rpc-conversation - // openim-rpc-friend - // openim-rpc-group - // openim-rpc-msg - // openim-rpc-third - // openim-rpc-user - switch module { - case "openim-api": - } -} diff --git a/tools/imctl/go.mod b/tools/imctl/go.mod deleted file mode 100644 index ed3685f56..000000000 --- a/tools/imctl/go.mod +++ /dev/null @@ -1,19 +0,0 @@ -module github.com/OpenIMSDK/Open-IM-Server/tools/imctl - -go 1.20 - -require ( - github.com/MakeNowJust/heredoc/v2 v2.0.1 - github.com/marmotedu/iam v1.7.0 - github.com/mitchellh/go-wordwrap v1.0.1 - github.com/moby/term v0.5.0 - github.com/russross/blackfriday v1.6.0 - github.com/spf13/cobra v1.7.0 - github.com/spf13/pflag v1.0.5 -) - -require ( - github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect - golang.org/x/sys v0.1.0 // indirect -) diff --git a/tools/imctl/go.sum b/tools/imctl/go.sum deleted file mode 100644 index 05f38d414..000000000 --- a/tools/imctl/go.sum +++ /dev/null @@ -1,26 +0,0 @@ -github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= -github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= -github.com/MakeNowJust/heredoc/v2 v2.0.1 h1:rlCHh70XXXv7toz95ajQWOWQnN4WNLt0TdpZYIR/J6A= -github.com/MakeNowJust/heredoc/v2 v2.0.1/go.mod h1:6/2Abh5s+hc3g9nbWLe9ObDIOhaRrqsyY9MWy+4JdRM= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= -github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= -github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/marmotedu/iam v1.7.0 h1:9aWg5Enx+npHU9kxQ0eYsdXvbiGeUsuuzxaV49BQa0I= -github.com/marmotedu/iam v1.7.0/go.mod h1:kjQ1Tzr+M6/B49DSC3Zky+2Ai9vAr6PbhuHV8mWUS48= -github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= -github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= -github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= -github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= -github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= -github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tools/imctl/internal/imctl/cmd/cmd.go b/tools/imctl/internal/imctl/cmd/cmd.go deleted file mode 100644 index 77a0ecb09..000000000 --- a/tools/imctl/internal/imctl/cmd/cmd.go +++ /dev/null @@ -1,133 +0,0 @@ -// 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. - -package cmd - -import ( - "flag" - "io" - "os" - - "github.com/marmotedu/iam/pkg/cli/genericclioptions" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "k8s.io/kubectl/pkg/cmd/completion" - "k8s.io/kubectl/pkg/cmd/options" - "k8s.io/kubectl/pkg/cmd/set" - "k8s.io/kubectl/pkg/cmd/version" - - "github.com/OpenIMSDK/Open-IM-Server/tools/imctl/internal/util/templates" -) - -// NewDefaultIAMCtlCommand creates the `imctl` command with default arguments. -func NewDefaultIMCtlCommand() *cobra.Command { - return NewIMCtlCommand(os.Stdin, os.Stdout, os.Stderr) -} - -// NewIAMCtlCommand returns new initialized instance of 'imctl' root command. -func NewIAMCtlCommand(in io.Reader, out, err io.Writer) *cobra.Command { - // Parent command to which all subcommands are added. - cmds := &cobra.Command{ - Use: "imctl", - Short: "imctl controls the IM platform", - Long: templates.LongDesc(` - imctl controls the IM platform, is the client side tool for IM platform. - - Find more information at: - // TODO: add link to docs, from auto scripts and gendocs - https://github.com/OpenIMSDK/Open-IM-Server/tree/main/docs`), - Run: runHelp, - // Hook before and after Run initialize and write profiles to disk, - // respectively. - PersistentPreRunE: func(*cobra.Command, []string) error { - return initProfiling() - }, - PersistentPostRunE: func(*cobra.Command, []string) error { - return flushProfiling() - }, - } - - flags := cmds.PersistentFlags() - flags.SetNormalizeFunc(cliflag.WarnWordSepNormalizeFunc) // Warn for "_" flags - - // Normalize all flags that are coming from other packages or pre-configurations - // a.k.a. change all "_" to "-". e.g. glog package - flags.SetNormalizeFunc(cliflag.WordSepNormalizeFunc) - - addProfilingFlags(flags) - - iamConfigFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag().WithDeprecatedSecretFlag() - iamConfigFlags.AddFlags(flags) - matchVersionIAMConfigFlags := cmdutil.NewMatchVersionFlags(iamConfigFlags) - matchVersionIAMConfigFlags.AddFlags(cmds.PersistentFlags()) - - _ = viper.BindPFlags(cmds.PersistentFlags()) - cobra.OnInitialize(func() { - genericapiserver.LoadConfig(viper.GetString(genericclioptions.FlagIAMConfig), "iamctl") - }) - cmds.PersistentFlags().AddGoFlagSet(flag.CommandLine) - - f := cmdutil.NewFactory(matchVersionIAMConfigFlags) - - // From this point and forward we get warnings on flags that contain "_" separators - cmds.SetGlobalNormalizationFunc(cliflag.WarnWordSepNormalizeFunc) - - ioStreams := genericclioptions.IOStreams{In: in, Out: out, ErrOut: err} - - groups := templates.CommandGroups{ - { - Message: "Basic Commands:", - Commands: []*cobra.Command{ - info.NewCmdInfo(f, ioStreams), - color.NewCmdColor(f, ioStreams), - new.NewCmdNew(f, ioStreams), - jwt.NewCmdJWT(f, ioStreams), - }, - }, - { - Message: "Identity and Access Management Commands:", - Commands: []*cobra.Command{ - user.NewCmdUser(f, ioStreams), - secret.NewCmdSecret(f, ioStreams), - policy.NewCmdPolicy(f, ioStreams), - }, - }, - { - Message: "Troubleshooting and Debugging Commands:", - Commands: []*cobra.Command{ - validate.NewCmdValidate(f, ioStreams), - }, - }, - { - Message: "Settings Commands:", - Commands: []*cobra.Command{ - set.NewCmdSet(f, ioStreams), - completion.NewCmdCompletion(ioStreams.Out, ""), - }, - }, - } - groups.Add(cmds) - - filters := []string{"options"} - templates.ActsAsRootCommand(cmds, filters, groups...) - - cmds.AddCommand(version.NewCmdVersion(f, ioStreams)) - cmds.AddCommand(options.NewCmdOptions(ioStreams.Out)) - - return cmds -} - -func runHelp(cmd *cobra.Command, args []string) { - _ = cmd.Help() -} diff --git a/tools/imctl/internal/imctl/cmd/profiling.go b/tools/imctl/internal/imctl/cmd/profiling.go deleted file mode 100644 index f0be6e38c..000000000 --- a/tools/imctl/internal/imctl/cmd/profiling.go +++ /dev/null @@ -1,95 +0,0 @@ -// 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. - -package cmd - -import ( - "errors" - "fmt" - "os" - "runtime" - "runtime/pprof" - - "github.com/spf13/pflag" -) - -// profiling configuration variables -var ( - profileName string = "none" // Name of the profile to capture. - profileOutput string = "profile.pprof" // File to write the profile data. -) - -// addProfilingFlags registers profiling related flags to the given FlagSet. -func addProfilingFlags(flags *pflag.FlagSet) { - flags.StringVar( - &profileName, - "profile", - "none", - "Type of profile to capture. Options: none, cpu, heap, goroutine, threadcreate, block, mutex", - ) - flags.StringVar(&profileOutput, "profile-output", "profile.pprof", "File to write the profile data") -} - -// initProfiling sets up profiling based on the user's choice. -// If 'cpu' is selected, it starts the CPU profile. For block and mutex profiles, -// sampling rates are set up. -func initProfiling() error { - switch profileName { - case "none": - return nil - case "cpu": - f, err := os.Create(profileOutput) - if err != nil { - return err - } - return pprof.StartCPUProfile(f) - case "block": - runtime.SetBlockProfileRate(1) // Sampling every block event - return nil - case "mutex": - runtime.SetMutexProfileFraction(1) // Sampling every mutex event - return nil - default: - if profile := pprof.Lookup(profileName); profile == nil { - return fmt.Errorf("unknown profile type: '%s'", profileName) - } - return nil - } -} - -// flushProfiling writes the profiling data to the specified file. -// For heap profiles, it runs the GC before capturing the data. -// It stops the CPU profile if it was started. -func flushProfiling() error { - switch profileName { - case "none": - return nil - case "cpu": - pprof.StopCPUProfile() - return nil - case "heap": - runtime.GC() // Run garbage collection before writing heap profile - fallthrough - default: - profile := pprof.Lookup(profileName) - if profile == nil { - return errors.New("invalid profile type") - } - f, err := os.Create(profileOutput) - if err != nil { - return err - } - return profile.WriteTo(f, 0) - } -} diff --git a/tools/imctl/internal/imctl/util/interrupt/interrupt.go b/tools/imctl/internal/imctl/util/interrupt/interrupt.go deleted file mode 100644 index e1d8386de..000000000 --- a/tools/imctl/internal/imctl/util/interrupt/interrupt.go +++ /dev/null @@ -1,103 +0,0 @@ -// 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. - -// Package interrupt deal with signals. -package interrupt - -import ( - "os" - "os/signal" - "sync" - "syscall" -) - -// terminationSignals are signals that cause the program to exit in the -// supported platforms (linux, darwin, windows). -var terminationSignals = []os.Signal{syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT} - -// Handler guarantees execution of notifications after a critical section (the function passed -// to a Run method), even in the presence of process termination. It guarantees exactly once -// invocation of the provided notify functions. -type Handler struct { - notify []func() - final func(os.Signal) - once sync.Once -} - -// Chain creates a new handler that invokes all notify functions when the critical section exits -// and then invokes the optional handler's notifications. This allows critical sections to be -// nested without losing exactly once invocations. Notify functions can invoke any cleanup needed -// but should not exit (which is the responsibility of the parent handler). -func Chain(handler *Handler, notify ...func()) *Handler { - if handler == nil { - return New(nil, notify...) - } - return New(handler.Signal, append(notify, handler.Close)...) -} - -// New creates a new handler that guarantees all notify functions are run after the critical -// section exits (or is interrupted by the OS), then invokes the final handler. If no final -// handler is specified, the default final is `os.Exit(1)`. A handler can only be used for -// one critical section. -func New(final func(os.Signal), notify ...func()) *Handler { - return &Handler{ - final: final, - notify: notify, - } -} - -// Close executes all the notification handlers if they have not yet been executed. -func (h *Handler) Close() { - h.once.Do(func() { - for _, fn := range h.notify { - fn() - } - }) -} - -// Signal is called when an os.Signal is received, and guarantees that all notifications -// are executed, then the final handler is executed. This function should only be called once -// per Handler instance. -func (h *Handler) Signal(s os.Signal) { - h.once.Do(func() { - for _, fn := range h.notify { - fn() - } - if h.final == nil { - os.Exit(1) - } - h.final(s) - }) -} - -// Run ensures that any notifications are invoked after the provided fn exits (even if the -// process is interrupted by an OS termination signal). Notifications are only invoked once -// per Handler instance, so calling Run more than once will not behave as the user expects. -func (h *Handler) Run(fn func() error) error { - ch := make(chan os.Signal, 1) - signal.Notify(ch, terminationSignals...) - defer func() { - signal.Stop(ch) - close(ch) - }() - go func() { - sig, ok := <-ch - if !ok { - return - } - h.Signal(sig) - }() - defer h.Close() - return fn() -} diff --git a/tools/imctl/internal/imctl/util/templates/command_groups.go b/tools/imctl/internal/imctl/util/templates/command_groups.go deleted file mode 100644 index 538b43ac4..000000000 --- a/tools/imctl/internal/imctl/util/templates/command_groups.go +++ /dev/null @@ -1,57 +0,0 @@ -// 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. - -package templates - -import ( - "github.com/spf13/cobra" -) - -type CommandGroup struct { - Message string - Commands []*cobra.Command -} - -type CommandGroups []CommandGroup - -func (g CommandGroups) Add(c *cobra.Command) { - for _, group := range g { - c.AddCommand(group.Commands...) - } -} - -func (g CommandGroups) Has(c *cobra.Command) bool { - for _, group := range g { - for _, command := range group.Commands { - if command == c { - return true - } - } - } - return false -} - -func AddAdditionalCommands(g CommandGroups, message string, cmds []*cobra.Command) CommandGroups { - group := CommandGroup{Message: message} - for _, c := range cmds { - // Don't show commands that have no short description - if !g.Has(c) && len(c.Short) != 0 { - group.Commands = append(group.Commands, c) - } - } - if len(group.Commands) == 0 { - return g - } - return append(g, group) -} diff --git a/tools/imctl/internal/imctl/util/templates/markdown.go b/tools/imctl/internal/imctl/util/templates/markdown.go deleted file mode 100644 index 5621163f8..000000000 --- a/tools/imctl/internal/imctl/util/templates/markdown.go +++ /dev/null @@ -1,149 +0,0 @@ -// 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. - -package templates - -import ( - "bytes" - "fmt" - "io" - "strings" - - "github.com/russross/blackfriday" -) - -const linebreak = "\n" - -// ASCIIRenderer implements blackfriday.Renderer. -var _ blackfriday.Renderer = &ASCIIRenderer{} - -// ASCIIRenderer is a blackfriday.Renderer intended for rendering markdown -// documents as plain text, well suited for human reading on terminals. -type ASCIIRenderer struct { - Indentation string - - listItemCount uint - listLevel uint -} - -// NormalText gets a text chunk *after* the markdown syntax was already -// processed and does a final cleanup on things we don't expect here, like -// removing linebreaks on things that are not a paragraph break (auto unwrap). -func (r *ASCIIRenderer) NormalText(out *bytes.Buffer, text []byte) { - raw := string(text) - lines := strings.Split(raw, linebreak) - for _, line := range lines { - trimmed := strings.Trim(line, " \n\t") - if len(trimmed) > 0 && trimmed[0] != '_' { - out.WriteString(" ") - } - out.WriteString(trimmed) - } -} - -// List renders the start and end of a list. -func (r *ASCIIRenderer) List(out *bytes.Buffer, text func() bool, flags int) { - r.listLevel++ - out.WriteString(linebreak) - text() - r.listLevel-- -} - -// ListItem renders list items and supports both ordered and unordered lists. -func (r *ASCIIRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) { - if flags&blackfriday.LIST_ITEM_BEGINNING_OF_LIST != 0 { - r.listItemCount = 1 - } else { - r.listItemCount++ - } - indent := strings.Repeat(r.Indentation, int(r.listLevel)) - var bullet string - if flags&blackfriday.LIST_TYPE_ORDERED != 0 { - bullet += fmt.Sprintf("%d.", r.listItemCount) - } else { - bullet += "*" - } - out.WriteString(indent + bullet + " ") - r.fw(out, text) - out.WriteString(linebreak) -} - -// Paragraph renders the start and end of a paragraph. -func (r *ASCIIRenderer) Paragraph(out *bytes.Buffer, text func() bool) { - out.WriteString(linebreak) - text() - out.WriteString(linebreak) -} - -// BlockCode renders a chunk of text that represents source code. -func (r *ASCIIRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) { - out.WriteString(linebreak) - lines := []string{} - for _, line := range strings.Split(string(text), linebreak) { - indented := r.Indentation + line - lines = append(lines, indented) - } - out.WriteString(strings.Join(lines, linebreak)) -} - -func (r *ASCIIRenderer) GetFlags() int { return 0 } -func (r *ASCIIRenderer) HRule(out *bytes.Buffer) { - out.WriteString(linebreak + "----------" + linebreak) -} -func (r *ASCIIRenderer) LineBreak(out *bytes.Buffer) { out.WriteString(linebreak) } -func (r *ASCIIRenderer) TitleBlock(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) Header(out *bytes.Buffer, text func() bool, level int, id string) { text() } -func (r *ASCIIRenderer) BlockHtml(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) BlockQuote(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) TableRow(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { r.fw(out, text) } -func (r *ASCIIRenderer) TableCell(out *bytes.Buffer, text []byte, align int) { r.fw(out, text) } -func (r *ASCIIRenderer) Footnotes(out *bytes.Buffer, text func() bool) { text() } -func (r *ASCIIRenderer) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) { - r.fw(out, text) -} -func (r *ASCIIRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) { r.fw(out, link) } -func (r *ASCIIRenderer) CodeSpan(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) Emphasis(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) RawHtmlTag(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) TripleEmphasis(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) StrikeThrough(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) FootnoteRef(out *bytes.Buffer, ref []byte, id int) { r.fw(out, ref) } -func (r *ASCIIRenderer) Entity(out *bytes.Buffer, entity []byte) { r.fw(out, entity) } -func (r *ASCIIRenderer) Smartypants(out *bytes.Buffer, text []byte) { r.fw(out, text) } -func (r *ASCIIRenderer) DocumentHeader(out *bytes.Buffer) {} -func (r *ASCIIRenderer) DocumentFooter(out *bytes.Buffer) {} -func (r *ASCIIRenderer) TocHeaderWithAnchor(text []byte, level int, anchor string) {} -func (r *ASCIIRenderer) TocHeader(text []byte, level int) {} -func (r *ASCIIRenderer) TocFinalize() {} - -func (r *ASCIIRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) { - r.fw(out, header, body) -} - -func (r *ASCIIRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { - out.WriteString(" ") - r.fw(out, link) -} - -func (r *ASCIIRenderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) { - r.fw(out, link) -} - -func (r *ASCIIRenderer) fw(out io.Writer, text ...[]byte) { - for _, t := range text { - out.Write(t) - } -} diff --git a/tools/imctl/internal/imctl/util/templates/normalizers.go b/tools/imctl/internal/imctl/util/templates/normalizers.go deleted file mode 100644 index f5873a0be..000000000 --- a/tools/imctl/internal/imctl/util/templates/normalizers.go +++ /dev/null @@ -1,99 +0,0 @@ -// 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. - -package templates - -import ( - "strings" - - "github.com/MakeNowJust/heredoc/v2" - "github.com/russross/blackfriday" - "github.com/spf13/cobra" -) - -const Indentation = ` ` - -// LongDesc normalizes a command's long description to follow the conventions. -func LongDesc(s string) string { - if len(s) == 0 { - return s - } - return normalizer{s}.heredoc().markdown().trim().string -} - -// Examples normalizes a command's examples to follow the conventions. -func Examples(s string) string { - if len(s) == 0 { - return s - } - return normalizer{s}.trim().indent().string -} - -// Normalize perform all required normalizations on a given command. -func Normalize(cmd *cobra.Command) *cobra.Command { - if len(cmd.Long) > 0 { - cmd.Long = LongDesc(cmd.Long) - } - if len(cmd.Example) > 0 { - cmd.Example = Examples(cmd.Example) - } - return cmd -} - -// NormalizeAll perform all required normalizations in the entire command tree. -func NormalizeAll(cmd *cobra.Command) *cobra.Command { - if cmd.HasSubCommands() { - for _, subCmd := range cmd.Commands() { - NormalizeAll(subCmd) - } - } - Normalize(cmd) - return cmd -} - -type normalizer struct { - string -} - -func (s normalizer) markdown() normalizer { - bytes := []byte(s.string) - formatted := blackfriday.Markdown( - bytes, - &ASCIIRenderer{Indentation: Indentation}, - blackfriday.EXTENSION_NO_INTRA_EMPHASIS, - ) - s.string = string(formatted) - return s -} - -func (s normalizer) heredoc() normalizer { - s.string = heredoc.Doc(s.string) - return s -} - -func (s normalizer) trim() normalizer { - s.string = strings.TrimSpace(s.string) - return s -} - -func (s normalizer) indent() normalizer { - indentedLines := []string{} - for _, line := range strings.Split(s.string, "\n") { - trimmed := strings.TrimSpace(line) - indented := Indentation + trimmed - indentedLines = append(indentedLines, indented) - } - s.string = strings.Join(indentedLines, "\n") - return s -} diff --git a/tools/imctl/internal/imctl/util/templates/templater.go b/tools/imctl/internal/imctl/util/templates/templater.go deleted file mode 100644 index 7b75cef13..000000000 --- a/tools/imctl/internal/imctl/util/templates/templater.go +++ /dev/null @@ -1,296 +0,0 @@ -// 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. - -package templates - -import ( - "bytes" - "fmt" - "strings" - "text/template" - "unicode" - - "github.com/spf13/cobra" - flag "github.com/spf13/pflag" - - "github.com/OpenIMSDK/Open-IM-Server/tools/imctl/internal/util/term" -) - -type FlagExposer interface { - ExposeFlags(cmd *cobra.Command, flags ...string) FlagExposer -} - -func ActsAsRootCommand(cmd *cobra.Command, filters []string, groups ...CommandGroup) FlagExposer { - if cmd == nil { - panic("nil root command") - } - templater := &templater{ - RootCmd: cmd, - UsageTemplate: MainUsageTemplate(), - HelpTemplate: MainHelpTemplate(), - CommandGroups: groups, - Filtered: filters, - } - cmd.SetFlagErrorFunc(templater.FlagErrorFunc()) - cmd.SilenceUsage = true - cmd.SetUsageFunc(templater.UsageFunc()) - cmd.SetHelpFunc(templater.HelpFunc()) - return templater -} - -func UseOptionsTemplates(cmd *cobra.Command) { - templater := &templater{ - UsageTemplate: OptionsUsageTemplate(), - HelpTemplate: OptionsHelpTemplate(), - } - cmd.SetUsageFunc(templater.UsageFunc()) - cmd.SetHelpFunc(templater.HelpFunc()) -} - -type templater struct { - UsageTemplate string - HelpTemplate string - RootCmd *cobra.Command - CommandGroups - Filtered []string -} - -func (t *templater) FlagErrorFunc(exposedFlags ...string) func(*cobra.Command, error) error { - return func(c *cobra.Command, err error) error { - c.SilenceUsage = true - switch c.CalledAs() { - case "options": - return fmt.Errorf("%s\nrun '%s' without flags", err, c.CommandPath()) - default: - return fmt.Errorf("%s\nsee '%s --help' for usage", err, c.CommandPath()) - } - } -} - -func (t *templater) ExposeFlags(cmd *cobra.Command, flags ...string) FlagExposer { - cmd.SetUsageFunc(t.UsageFunc(flags...)) - return t -} - -func (t *templater) HelpFunc() func(*cobra.Command, []string) { - return func(c *cobra.Command, s []string) { - tt := template.New("help") - tt.Funcs(t.templateFuncs()) - template.Must(tt.Parse(t.HelpTemplate)) - out := term.NewResponsiveWriter(c.OutOrStdout()) - err := tt.Execute(out, c) - if err != nil { - c.Println(err) - } - } -} - -func (t *templater) UsageFunc(exposedFlags ...string) func(*cobra.Command) error { - return func(c *cobra.Command) error { - tt := template.New("usage") - tt.Funcs(t.templateFuncs(exposedFlags...)) - template.Must(tt.Parse(t.UsageTemplate)) - out := term.NewResponsiveWriter(c.OutOrStderr()) - return tt.Execute(out, c) - } -} - -func (t *templater) templateFuncs(exposedFlags ...string) template.FuncMap { - return template.FuncMap{ - "trim": strings.TrimSpace, - "trimRight": func(s string) string { return strings.TrimRightFunc(s, unicode.IsSpace) }, - "trimLeft": func(s string) string { return strings.TrimLeftFunc(s, unicode.IsSpace) }, - "gt": cobra.Gt, - "eq": cobra.Eq, - "rpad": rpad, - "appendIfNotPresent": appendIfNotPresent, - "flagsNotIntersected": flagsNotIntersected, - "visibleFlags": visibleFlags, - "flagsUsages": flagsUsages, - "cmdGroups": t.cmdGroups, - "cmdGroupsString": t.cmdGroupsString, - "rootCmd": t.rootCmdName, - "isRootCmd": t.isRootCmd, - "optionsCmdFor": t.optionsCmdFor, - "usageLine": t.usageLine, - "exposed": func(c *cobra.Command) *flag.FlagSet { - exposed := flag.NewFlagSet("exposed", flag.ContinueOnError) - if len(exposedFlags) > 0 { - for _, name := range exposedFlags { - if flag := c.Flags().Lookup(name); flag != nil { - exposed.AddFlag(flag) - } - } - } - return exposed - }, - } -} - -func (t *templater) cmdGroups(c *cobra.Command, all []*cobra.Command) []CommandGroup { - if len(t.CommandGroups) > 0 && c == t.RootCmd { - all = filter(all, t.Filtered...) - return AddAdditionalCommands(t.CommandGroups, "Other Commands:", all) - } - all = filter(all, "options") - return []CommandGroup{ - { - Message: "Available Commands:", - Commands: all, - }, - } -} - -func (t *templater) cmdGroupsString(c *cobra.Command) string { - groups := []string{} - for _, cmdGroup := range t.cmdGroups(c, c.Commands()) { - cmds := []string{cmdGroup.Message} - for _, cmd := range cmdGroup.Commands { - if cmd.IsAvailableCommand() { - cmds = append(cmds, " "+rpad(cmd.Name(), cmd.NamePadding())+" "+cmd.Short) - } - } - groups = append(groups, strings.Join(cmds, "\n")) - } - return strings.Join(groups, "\n\n") -} - -func (t *templater) rootCmdName(c *cobra.Command) string { - return t.rootCmd(c).CommandPath() -} - -func (t *templater) isRootCmd(c *cobra.Command) bool { - return t.rootCmd(c) == c -} - -func (t *templater) parents(c *cobra.Command) []*cobra.Command { - parents := []*cobra.Command{c} - for current := c; !t.isRootCmd(current) && current.HasParent(); { - current = current.Parent() - parents = append(parents, current) - } - return parents -} - -func (t *templater) rootCmd(c *cobra.Command) *cobra.Command { - if c != nil && !c.HasParent() { - return c - } - if t.RootCmd == nil { - panic("nil root cmd") - } - return t.RootCmd -} - -func (t *templater) optionsCmdFor(c *cobra.Command) string { - if !c.Runnable() { - return "" - } - rootCmdStructure := t.parents(c) - for i := len(rootCmdStructure) - 1; i >= 0; i-- { - cmd := rootCmdStructure[i] - if _, _, err := cmd.Find([]string{"options"}); err == nil { - return cmd.CommandPath() + " options" - } - } - return "" -} - -func (t *templater) usageLine(c *cobra.Command) string { - usage := c.UseLine() - suffix := "[options]" - if c.HasFlags() && !strings.Contains(usage, suffix) { - usage += " " + suffix - } - return usage -} - -func flagsUsages(f *flag.FlagSet) string { - x := new(bytes.Buffer) - - f.VisitAll(func(flag *flag.Flag) { - if flag.Hidden { - return - } - format := "--%s=%s: %s\n" - - if flag.Value.Type() == "string" { - format = "--%s='%s': %s\n" - } - - if len(flag.Shorthand) > 0 { - format = " -%s, " + format - } else { - format = " %s " + format - } - - fmt.Fprintf(x, format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage) - }) - - return x.String() -} - -func rpad(s string, padding int) string { - template := fmt.Sprintf("%%-%ds", padding) - return fmt.Sprintf(template, s) -} - -func appendIfNotPresent(s, stringToAppend string) string { - if strings.Contains(s, stringToAppend) { - return s - } - return s + " " + stringToAppend -} - -func flagsNotIntersected(l *flag.FlagSet, r *flag.FlagSet) *flag.FlagSet { - f := flag.NewFlagSet("notIntersected", flag.ContinueOnError) - l.VisitAll(func(flag *flag.Flag) { - if r.Lookup(flag.Name) == nil { - f.AddFlag(flag) - } - }) - return f -} - -func visibleFlags(l *flag.FlagSet) *flag.FlagSet { - hidden := "help" - f := flag.NewFlagSet("visible", flag.ContinueOnError) - l.VisitAll(func(flag *flag.Flag) { - if flag.Name != hidden { - f.AddFlag(flag) - } - }) - return f -} - -func filter(cmds []*cobra.Command, names ...string) []*cobra.Command { - out := []*cobra.Command{} - for _, c := range cmds { - if c.Hidden { - continue - } - skip := false - for _, name := range names { - if name == c.Name() { - skip = true - break - } - } - if skip { - continue - } - out = append(out, c) - } - return out -} diff --git a/tools/imctl/internal/imctl/util/templates/templates.go b/tools/imctl/internal/imctl/util/templates/templates.go deleted file mode 100644 index ec71434ce..000000000 --- a/tools/imctl/internal/imctl/util/templates/templates.go +++ /dev/null @@ -1,103 +0,0 @@ -// 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. - -// Package templates provides template functions for working with templates. -package templates - -import ( - "strings" - "unicode" -) - -const ( - // SectionVars is the help template section that declares variables to be used in the template. - SectionVars = `{{$isRootCmd := isRootCmd .}}` + - `{{$rootCmd := rootCmd .}}` + - `{{$visibleFlags := visibleFlags (flagsNotIntersected .LocalFlags .PersistentFlags)}}` + - `{{$explicitlyExposedFlags := exposed .}}` + - `{{$optionsCmdFor := optionsCmdFor .}}` + - `{{$usageLine := usageLine .}}` - - // SectionAliases is the help template section that displays command aliases. - SectionAliases = `{{if gt .Aliases 0}}Aliases: -{{.NameAndAliases}} - -{{end}}` - - // SectionExamples is the help template section that displays command examples. - SectionExamples = `{{if .HasExample}}Examples: -{{trimRight .Example}} - -{{end}}` - - // SectionSubcommands is the help template section that displays the command's subcommands. - SectionSubcommands = `{{if .HasAvailableSubCommands}}{{cmdGroupsString .}} - -{{end}}` - - // SectionFlags is the help template section that displays the command's flags. - SectionFlags = `{{ if or $visibleFlags.HasFlags $explicitlyExposedFlags.HasFlags}}Options: -{{ if $visibleFlags.HasFlags}}{{trimRight (flagsUsages $visibleFlags)}}{{end}}{{ if $explicitlyExposedFlags.HasFlags}}{{ if $visibleFlags.HasFlags}} -{{end}}{{trimRight (flagsUsages $explicitlyExposedFlags)}}{{end}} - -{{end}}` - - // SectionUsage is the help template section that displays the command's usage. - SectionUsage = `{{if and .Runnable (ne .UseLine "") (ne .UseLine $rootCmd)}}Usage: - {{$usageLine}} - -{{end}}` - - // SectionTipsHelp is the help template section that displays the '--help' hint. - SectionTipsHelp = `{{if .HasSubCommands}}Use "{{$rootCmd}} --help" for more information about a given command. -{{end}}` - - // SectionTipsGlobalOptions is the help template section that displays the 'options' hint for displaying global - // flags. - SectionTipsGlobalOptions = `{{if $optionsCmdFor}}Use "{{$optionsCmdFor}}" for a list of global command-line options (applies to all commands). -{{end}}` -) - -// MainHelpTemplate if the template for 'help' used by most commands. -func MainHelpTemplate() string { - return `{{with or .Long .Short }}{{. | trim}}{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}` -} - -// MainUsageTemplate if the template for 'usage' used by most commands. -func MainUsageTemplate() string { - sections := []string{ - "\n\n", - SectionVars, - SectionAliases, - SectionExamples, - SectionSubcommands, - SectionFlags, - SectionUsage, - SectionTipsHelp, - SectionTipsGlobalOptions, - } - return strings.TrimRightFunc(strings.Join(sections, ""), unicode.IsSpace) -} - -// OptionsHelpTemplate if the template for 'help' used by the 'options' command. -func OptionsHelpTemplate() string { - return "" -} - -// OptionsUsageTemplate if the template for 'usage' used by the 'options' command. -func OptionsUsageTemplate() string { - return `{{ if .HasInheritedFlags}}The following options can be passed to any command: - -{{flagsUsages .InheritedFlags}}{{end}}` -} diff --git a/tools/imctl/internal/imctl/util/term/resize.go b/tools/imctl/internal/imctl/util/term/resize.go deleted file mode 100644 index 0063d0723..000000000 --- a/tools/imctl/internal/imctl/util/term/resize.go +++ /dev/null @@ -1,53 +0,0 @@ -// 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. - -package term - -import ( - "github.com/moby/term" -) - -// TerminalSize represents the width and height of a terminal. -type TerminalSize struct { - Width uint16 - Height uint16 -} - -// TerminalSizeQueue is capable of returning terminal resize events as they occur. -type TerminalSizeQueue interface { - // Next returns the new terminal size after the terminal has been resized. It returns nil when - // monitoring has been stopped. - Next() *TerminalSize -} - -// GetSize returns the current size of the user's terminal. If it isn't a terminal, -// nil is returned. -func (t TTY) GetSize() *TerminalSize { - outFd, isTerminal := term.GetFdInfo(t.Out) - if !isTerminal { - return nil - } - return GetSize(outFd) -} - -// GetSize returns the current size of the terminal associated with fd. -func GetSize(fd uintptr) *TerminalSize { - winsize, err := term.GetWinsize(fd) - if err != nil { - // runtime.HandleError(fmt.Errorf("unable to get terminal size: %v", err)) - return nil - } - - return &TerminalSize{Width: winsize.Width, Height: winsize.Height} -} diff --git a/tools/imctl/internal/imctl/util/term/term.go b/tools/imctl/internal/imctl/util/term/term.go deleted file mode 100644 index 45c820384..000000000 --- a/tools/imctl/internal/imctl/util/term/term.go +++ /dev/null @@ -1,37 +0,0 @@ -// 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. - -// Package term provides structures and helper functions to work with -// terminal (state, sizes). -package term - -import ( - "io" -) - -// TTY helps invoke a function and preserve the state of the terminal, even if the process is -// terminated during execution. It also provides support for terminal resizing for remote command -// execution/attachment. -type TTY struct { - // In is a reader representing stdin. It is a required field. - In io.Reader - // Out is a writer representing stdout. It must be set to support terminal resizing. It is an - // optional field. - Out io.Writer - // Raw is true if the terminal should be set raw. - Raw bool - // TryDev indicates the TTY should try to open /dev/tty if the provided input - // is not a file descriptor. - TryDev bool -} diff --git a/tools/imctl/internal/imctl/util/term/term_writer.go b/tools/imctl/internal/imctl/util/term/term_writer.go deleted file mode 100644 index 700a223af..000000000 --- a/tools/imctl/internal/imctl/util/term/term_writer.go +++ /dev/null @@ -1,124 +0,0 @@ -// 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. - -package term - -import ( - "io" - "os" - - wordwrap "github.com/mitchellh/go-wordwrap" - "github.com/moby/term" -) - -type wordWrapWriter struct { - limit uint - writer io.Writer -} - -// NewResponsiveWriter creates a Writer that detects the column width of the -// terminal we are in, and adjusts every line width to fit and use recommended -// terminal sizes for better readability. Does proper word wrapping automatically. -// -// if terminal width >= 120 columns use 120 columns -// if terminal width >= 100 columns use 100 columns -// if terminal width >= 80 columns use 80 columns -// -// In case we're not in a terminal or if it's smaller than 80 columns width, -// doesn't do any wrapping. -func NewResponsiveWriter(w io.Writer) io.Writer { - file, ok := w.(*os.File) - if !ok { - return w - } - fd := file.Fd() - if !term.IsTerminal(fd) { - return w - } - - terminalSize := GetSize(fd) - if terminalSize == nil { - return w - } - - var limit uint - switch { - case terminalSize.Width >= 120: - limit = 120 - case terminalSize.Width >= 100: - limit = 100 - case terminalSize.Width >= 80: - limit = 80 - } - - return NewWordWrapWriter(w, limit) -} - -// NewWordWrapWriter is a Writer that supports a limit of characters on every line -// and does auto word wrapping that respects that limit. -func NewWordWrapWriter(w io.Writer, limit uint) io.Writer { - return &wordWrapWriter{ - limit: limit, - writer: w, - } -} - -func (w wordWrapWriter) Write(p []byte) (nn int, err error) { - if w.limit == 0 { - return w.writer.Write(p) - } - original := string(p) - wrapped := wordwrap.WrapString(original, w.limit) - return w.writer.Write([]byte(wrapped)) -} - -// NewPunchCardWriter is a NewWordWrapWriter that limits the line width to 80 columns. -func NewPunchCardWriter(w io.Writer) io.Writer { - return NewWordWrapWriter(w, 80) -} - -type maxWidthWriter struct { - maxWidth uint - currentWidth uint - written uint - writer io.Writer -} - -// NewMaxWidthWriter is a Writer that supports a limit of characters on every -// line, but doesn't do any word wrapping automatically. -func NewMaxWidthWriter(w io.Writer, maxWidth uint) io.Writer { - return &maxWidthWriter{ - maxWidth: maxWidth, - writer: w, - } -} - -func (m maxWidthWriter) Write(p []byte) (nn int, err error) { - for _, b := range p { - if m.currentWidth == m.maxWidth { - m.writer.Write([]byte{'\n'}) - m.currentWidth = 0 - } - if b == '\n' { - m.currentWidth = 0 - } - _, err := m.writer.Write([]byte{b}) - if err != nil { - return int(m.written), err - } - m.written++ - m.currentWidth++ - } - return len(p), nil -} diff --git a/tools/imctl/internal/imctl/util/term/term_writer_test.go b/tools/imctl/internal/imctl/util/term/term_writer_test.go deleted file mode 100644 index 588ba3418..000000000 --- a/tools/imctl/internal/imctl/util/term/term_writer_test.go +++ /dev/null @@ -1,114 +0,0 @@ -// 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. - -package term - -import ( - "bytes" - "strings" - "testing" -) - -const test = "Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam Iam" - -func TestWordWrapWriter(t *testing.T) { - testcases := map[string]struct { - input string - maxWidth uint - }{ - "max 10": {input: test, maxWidth: 10}, - "max 80": {input: test, maxWidth: 80}, - "max 120": {input: test, maxWidth: 120}, - "max 5000": {input: test, maxWidth: 5000}, - } - for k, tc := range testcases { - b := bytes.NewBufferString("") - w := NewWordWrapWriter(b, tc.maxWidth) - _, err := w.Write([]byte(tc.input)) - if err != nil { - t.Errorf("%s: Unexpected error: %v", k, err) - } - result := b.String() - if !strings.Contains(result, "Iam") { - t.Errorf("%s: Expected to contain \"Iam\"", k) - } - if len(result) < len(tc.input) { - t.Errorf( - "%s: Unexpectedly short string, got %d wanted at least %d chars: %q", - k, - len(result), - len(tc.input), - result, - ) - } - for _, line := range strings.Split(result, "\n") { - if len(line) > int(tc.maxWidth) { - t.Errorf("%s: Every line must be at most %d chars long, got %d: %q", k, tc.maxWidth, len(line), line) - } - } - for _, word := range strings.Split(result, " ") { - if !strings.Contains(word, "Iam") { - t.Errorf("%s: Unexpected broken word: %q", k, word) - } - } - } -} - -func TestMaxWidthWriter(t *testing.T) { - testcases := map[string]struct { - input string - maxWidth uint - }{ - "max 10": {input: test, maxWidth: 10}, - "max 80": {input: test, maxWidth: 80}, - "max 120": {input: test, maxWidth: 120}, - "max 5000": {input: test, maxWidth: 5000}, - } - for k, tc := range testcases { - b := bytes.NewBufferString("") - w := NewMaxWidthWriter(b, tc.maxWidth) - _, err := w.Write([]byte(tc.input)) - if err != nil { - t.Errorf("%s: Unexpected error: %v", k, err) - } - result := b.String() - if !strings.Contains(result, "Iam") { - t.Errorf("%s: Expected to contain \"Iam\"", k) - } - if len(result) < len(tc.input) { - t.Errorf( - "%s: Unexpectedly short string, got %d wanted at least %d chars: %q", - k, - len(result), - len(tc.input), - result, - ) - } - lines := strings.Split(result, "\n") - for i, line := range lines { - if len(line) > int(tc.maxWidth) { - t.Errorf("%s: Every line must be at most %d chars long, got %d: %q", k, tc.maxWidth, len(line), line) - } - if i < len(lines)-1 && len(line) != int(tc.maxWidth) { - t.Errorf( - "%s: Lines except the last one are expected to be exactly %d chars long, got %d: %q", - k, - tc.maxWidth, - len(line), - line, - ) - } - } - } -} diff --git a/tools/infra/go.mod b/tools/infra/go.mod index 66a5b837d..acac79508 100644 --- a/tools/infra/go.mod +++ b/tools/infra/go.mod @@ -1,3 +1,3 @@ module github.com/OpenIMSDK/Open-IM-Server/tools/infra -go 1.20 +go 1.18 diff --git a/tools/ncpu/README.md b/tools/ncpu/README.md index 7edda5328..f7c05d583 100644 --- a/tools/ncpu/README.md +++ b/tools/ncpu/README.md @@ -37,11 +37,3 @@ The above command will ensure the build process takes advantage of all the avail ## Installation (Include installation steps here, e.g., how to clone the repo, build the tool, or install via package manager.) - -## Contributing - -If you have any suggestions, bug reports, or wish to contribute to the development of `ncpu`, please refer to our contribution guidelines (link to guidelines). - -## License - -`ncpu` is released under the [LICENSE_NAME](LINK_TO_LICENSE). Please refer to the license file for more details. \ No newline at end of file diff --git a/tools/ncpu/go.mod b/tools/ncpu/go.mod index c42fd4cc2..4173d306e 100644 --- a/tools/ncpu/go.mod +++ b/tools/ncpu/go.mod @@ -1,5 +1,5 @@ module github.com/OpenIMSDK/Open-IM-Server/tools/ncpu -go 1.20 +go 1.18 require go.uber.org/automaxprocs v1.5.3 diff --git a/tools/openim-web/Dockerfile b/tools/openim-web/Dockerfile new file mode 100644 index 000000000..2e0cd9e8e --- /dev/null +++ b/tools/openim-web/Dockerfile @@ -0,0 +1,47 @@ +# 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. + +# 使用官方Go镜像作为基础镜像 +FROM golang:1.21 AS build-env +ENV CGO_ENABLED=0 +# 设置工作目录 +WORKDIR /app + +# 安装curl和unzip工具 +#RUN apt-get update && apt-get install -y curl unzip + +# 从GitHub下载并解压dist.zip +#RUN curl -LO https://github.com/OpenIMSDK/dist.zip \ + # && unzip dist.zip -d ./ \ + # && rm dist.zip + +# 复制Go代码到容器 +COPY . . + +# 编译Go代码 +RUN go build -o openim-web + +# 使用轻量级的基础镜像 +FROM debian:buster-slim + +# 将编译好的二进制文件和dist资源复制到新的容器 +WORKDIR /app +COPY --from=build-env /app/openim-web /app/openim-web +COPY --from=build-env /app/dist /app/dist + +# 开放容器的20001端口 +EXPOSE 20001 + +# 指定容器启动命令 +ENTRYPOINT ["/app/openim-web"] \ No newline at end of file diff --git a/tools/openim-web/README.md b/tools/openim-web/README.md new file mode 100644 index 000000000..afd5e9a96 --- /dev/null +++ b/tools/openim-web/README.md @@ -0,0 +1,79 @@ +# OpenIM Web Service + +- [OpenIM Web Service](#openim-web-service) + - [Overview](#overview) + - [User](#user) + - [Docker Deployment](#docker-deployment) + - [Build the Docker Image](#build-the-docker-image) + - [Run the Docker Container](#run-the-docker-container) + - [Configuration](#configuration) + - [Contributions](#contributions) + + +OpenIM Web Service is a lightweight containerized service built with Go. The service serves static files and allows customization via environment variables. + +## Overview + +- Built using Go. +- Deployed as a Docker container. +- Serves static files from a directory which can be set via an environment variable. +- The default port for the service is `20001`, but it can be customized using an environment variable. + +## User + +example: + +```bash +$ ./openim-web -h +Usage of ./openim-web: + -distPath string + Path to the distribution (default "/app/dist") + -port string + Port to run the server on (default "20001") +``` + +Variables can be set as above, Environment variables can also be set + +example: + +```bash +$ export OPENIM_WEB_DIST_PATH="/app/dist" +$ export OPENIM_WEB_PPRT="11001" +``` + +Initialize the env configuration file: + +```bash +$ make init +``` + +## Docker Deployment + +### Build the Docker Image + +Even though we've implemented automation, it's to make the developer experience easier: + +To build the Docker image for OpenIM Web Service: + +```bash +$ docker build -t openim-web . +``` + +### Run the Docker Container + +To run the service: + +```bash +$ docker run -e DIST_PATH=/app/dist -e PORT=20001 -p 20001:20001 openim-web +``` + +## Configuration + +You can configure the OpenIM Web Service using the following environment variables: + +- **DIST_PATH**: The path to the directory containing the static files. Default: `/app/dist`. +- **PORT**: The port on which the service listens. Default: `11001`. + +## Contributions + +We welcome contributions from the community. If you find any bugs or have feature suggestions, please create an issue or send a pull request. \ No newline at end of file diff --git a/tools/openim-web/go.mod b/tools/openim-web/go.mod new file mode 100644 index 000000000..27d658d3b --- /dev/null +++ b/tools/openim-web/go.mod @@ -0,0 +1,7 @@ +module github.com/OpenIMSDK/Open-IM-Server/tools/openim-web + +go 1.18 + +require gopkg.in/yaml.v2 v2.4.0 + +require github.com/NYTimes/gziphandler v1.1.1 // indirect diff --git a/tools/openim-web/go.sum b/tools/openim-web/go.sum new file mode 100644 index 000000000..54ca3deb1 --- /dev/null +++ b/tools/openim-web/go.sum @@ -0,0 +1,10 @@ +github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= +github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/tools/openim-web/openim-web.go b/tools/openim-web/openim-web.go new file mode 100644 index 000000000..c913e35e7 --- /dev/null +++ b/tools/openim-web/openim-web.go @@ -0,0 +1,63 @@ +// 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. + +package main + +import ( + "flag" + "log" + "net/http" + "os" + + "github.com/NYTimes/gziphandler" +) + +var ( + distPathFlag string + portFlag string +) + +func init() { + flag.StringVar(&distPathFlag, "distPath", "/app/dist", "Path to the distribution") + flag.StringVar(&portFlag, "port", "11001", "Port to run the server on") +} + +func main() { + flag.Parse() + + distPath := getConfigValue("DIST_PATH", distPathFlag, "/app/dist") + fs := http.FileServer(http.Dir(distPath)) + + withGzip := gziphandler.GzipHandler(fs) + + http.Handle("/", withGzip) + + port := getConfigValue("PORT", portFlag, "11001") + log.Printf("Server listening on port %s in %s...", port, distPath) + err := http.ListenAndServe(":"+port, nil) + if err != nil { + log.Fatal(err) + } +} + +func getConfigValue(envKey, flagValue, fallback string) string { + envVal := os.Getenv(envKey) + if envVal != "" { + return envVal + } + if flagValue != "" { + return flagValue + } + return fallback +} diff --git a/tools/openim-web/openim-web_test.go b/tools/openim-web/openim-web_test.go new file mode 100644 index 000000000..dd1c93316 --- /dev/null +++ b/tools/openim-web/openim-web_test.go @@ -0,0 +1,71 @@ +// 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. + +package main + +import ( + "os" + "testing" +) + +func TestGetConfigValue(t *testing.T) { + tests := []struct { + name string + envKey string + envValue string + flagValue string + fallback string + wantResult string + }{ + { + name: "environment variable set", + envKey: "TEST_KEY", + envValue: "envValue", + flagValue: "", + fallback: "default", + wantResult: "envValue", + }, + { + name: "flag set and environment variable not set", + envKey: "TEST_KEY", + envValue: "", + flagValue: "flagValue", + fallback: "default", + wantResult: "flagValue", + }, + { + name: "nothing set, use fallback", + envKey: "TEST_KEY", + envValue: "", + flagValue: "", + fallback: "default", + wantResult: "default", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.envValue != "" { + os.Setenv(tt.envKey, tt.envValue) + defer os.Unsetenv(tt.envKey) + } + + got := getConfigValue(tt.envKey, tt.flagValue, tt.fallback) + + if got != tt.wantResult { + t.Errorf("getConfigValue(%s, %s, %s) = %s; want %s", tt.envKey, tt.flagValue, tt.fallback, got, tt.wantResult) + } + }) + } +} diff --git a/tools/versionchecker/go.mod b/tools/versionchecker/go.mod new file mode 100644 index 000000000..1c189e604 --- /dev/null +++ b/tools/versionchecker/go.mod @@ -0,0 +1,3 @@ +module github.com/OpenIMSDK/Open-IM-Server/tools/versionchecker + +go 1.18 diff --git a/tools/versionchecker/versionchecker.go b/tools/versionchecker/versionchecker.go new file mode 100644 index 000000000..e7bc3e379 --- /dev/null +++ b/tools/versionchecker/versionchecker.go @@ -0,0 +1,115 @@ +// 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. + +package main + +import ( + "bytes" + "fmt" + "os/exec" + "runtime" + "time" +) + +func executeCommand(cmdName string, args ...string) (string, error) { + cmd := exec.Command(cmdName, args...) + var out bytes.Buffer + var stderr bytes.Buffer + cmd.Stdout = &out + cmd.Stderr = &stderr + + err := cmd.Run() + if err != nil { + return "", fmt.Errorf("Error executing %s: %v", cmdName, err) + } + return out.String(), nil +} + +func printTime() string { + currentTime := time.Now() + + // 使用 Format 函数以优雅的方式格式化日期和时间 + // 2006-01-02 15:04:05 是 Go 中的标准时间格式 + formattedTime := currentTime.Format("2006-01-02 15:04:05") + + return fmt.Sprintf("Current Date & Time:", formattedTime) +} + +func getGoVersion() string { + version := runtime.Version() + goos := runtime.GOOS + goarch := runtime.GOARCH + return fmt.Sprintf("Go Version: %s\nOS: %s\nArchitecture: %s", version, goos, goarch) +} + +func getDockerVersion() string { + version, err := executeCommand("docker", "--version") + if err != nil { + return "Docker is not installed. Please install it to get the version." + } + return version +} + +func getDockerComposeVersion() string { + version, err := executeCommand("docker-compose", "--version") + if err != nil { + return "Docker Compose is not installed. Please install it to get the version." + } + return version +} + +func getKubernetesVersion() string { + version, err := executeCommand("kubectl", "version", "--client", "--short") + if err != nil { + return "Kubernetes is not installed. Please install it to get the version." + } + return version +} + +func getGitVersion() string { + version, err := executeCommand("git", "branch", "--show-current") + if err != nil { + return "Git is not installed. Please install it to get the version." + } + return version +} + +// NOTE: You'll need to provide appropriate commands for OpenIM versions. +func getOpenIMServerVersion() string { + // Placeholder + return "OpenIM Server: v3.2" +} + +func getOpenIMClientVersion() string { + // Placeholder + return "OpenIM Client: v3.2" +} + +func main() { + fmt.Println(printTime()) + fmt.Println("# Diagnostic Tool Result\n") + fmt.Println("## Go Version") + fmt.Println(getGoVersion()) + fmt.Println("## Branch Type") + fmt.Println(getGitVersion()) + fmt.Println("## Docker Version") + fmt.Println(getDockerVersion()) + fmt.Println("## Docker Compose Version") + fmt.Println(getDockerComposeVersion()) + fmt.Println("## Kubernetes Version") + fmt.Println(getKubernetesVersion()) + fmt.Println("## OpenIM Versions") + fmt.Println(getOpenIMServerVersion()) + fmt.Println(getOpenIMClientVersion()) +} diff --git a/tools/yamlfmt/go.mod b/tools/yamlfmt/go.mod index a6acf38a1..223264de8 100644 --- a/tools/yamlfmt/go.mod +++ b/tools/yamlfmt/go.mod @@ -1,6 +1,6 @@ module github.com/OpenIMSDK/Open-IM-Server/tools/yamlfmt -go 1.20 +go 1.18 require ( github.com/likexian/gokit v0.25.13