From f6dc34cbaa51cd755ac5e9a0436c76475bd1ebfe Mon Sep 17 00:00:00 2001 From: JamesChenX Date: Sat, 12 Nov 2022 11:30:48 +0800 Subject: [PATCH] Upgrade docker compose from v1 to v2 in scripts and docs --- .github/workflows/deploy-playground.yml | 4 +-- README.md | 6 ++-- README_zh.md | 6 ++-- docker-compose.standalone.yml | 13 +++----- .../cluster/tpl/user-data-turms-admin.sh | 8 ++--- .../cluster/tpl/user-data-turms-gateway.sh | 8 ++--- .../cluster/tpl/user-data-turms-service.sh | 8 ++--- terraform/common/playground/tpl/user-data.sh | 32 +++++++------------ turms-docs/src/README.md | 4 +-- .../src/for-developers/getting-started.md | 18 +++++------ .../main/resources/docker-compose.test.yml | 2 -- 11 files changed, 46 insertions(+), 63 deletions(-) diff --git a/.github/workflows/deploy-playground.yml b/.github/workflows/deploy-playground.yml index e660d23ce4..2804d00417 100644 --- a/.github/workflows/deploy-playground.yml +++ b/.github/workflows/deploy-playground.yml @@ -28,10 +28,10 @@ jobs: script_stop: true script: | cd /opt/turms - sudo docker-compose -f docker-compose.standalone.yml down + sudo docker compose -f docker-compose.standalone.yml down sudo docker system prune -a -f sudo docker system prune --volumes -f sudo rm -rf /var/log/journal sudo git pull sudo git reset --hard - sudo ENV=dev,demo INITIAL_ROOT_PASSWORD='${{ secrets.PLAYGROUND_ROOT_PASSWORD }}' docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d \ No newline at end of file + sudo ENV=dev,demo INITIAL_ROOT_PASSWORD='${{ secrets.PLAYGROUND_ROOT_PASSWORD }}' docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d \ No newline at end of file diff --git a/README.md b/README.md index 4a96825083..8eca658ec8 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Please refer to [Turms Documentation](https://turms-im.github.io/docs) (no Engli You can use any turms-client-(java/js/swift) implementation to send requests to turms-gateway and interact with other users. -In addition, Playground is set up automatically by just one command: `ENV=dev,demo docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d` +In addition, Playground is set up automatically by just one command: `ENV=dev,demo docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d` ## Quick Start Running the following commands to setup a minimum viable cluster (including turms-gateway, turms-service and turms-admin) and its dependent servers (MongoDB sharded cluster and Redis) automatically: @@ -32,7 +32,7 @@ Running the following commands to setup a minimum viable cluster (including turm git clone --depth 1 https://github.com/turms-im/turms.git cd turms docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions -docker-compose -f docker-compose.standalone.yml up --force-recreate +docker compose -f docker-compose.standalone.yml up --force-recreate ``` After the cluster is set up, you can visit turms-admin at http://localhost:6510, and enter the account and password (`turms` by default). If you log in successfully, it means that the cluster of Turms has been setup successfully. @@ -71,7 +71,7 @@ Note: The main disadvantage of the current Turms project is that it does not pro 1. (Agility) Support updating Turms servers without the users' awareness of shutdown to support rapid iteration 2. (Scalability) The Turms server is stateless to be scaled out; Support multi-active across data centers -3. (Deployability) Support container deployment to facilitate integration (CI/CD) with cloud services. Turms provides three solutions for container deployment out of the box: docker image, docker-compose script, and Terraform module +3. (Deployability) Support container deployment to facilitate integration (CI/CD) with cloud services. Turms provides three solutions for container deployment out of the box: Docker image, Docker compose file, and Terraform module 4. (Observability) Support relatively complete features of observability for business analysis and troubleshoot 5. (Scalability) Support medium to large scale instant messaging applications, and there is no need to refactor even if the application becomes large from medium-scale (There is still a lot of optimization work to be done for large applications, but Turms servers are easy to upgrade) 6. (Security) Support API throttling and global user/IP blocklist to resist most CC attacks diff --git a/README_zh.md b/README_zh.md index 301fe75c8e..6c427db1b5 100644 --- a/README_zh.md +++ b/README_zh.md @@ -26,7 +26,7 @@ Turms是一套全球范围内最为先进的、为同时在线用户数为100K~1 您可以使用任意turms-client-(java/js/swift)客户端,向turms-gateway服务端发送请求,并与其他用户进行交互。 -另外,Playground由一条指令全自动搭建:`ENV=dev,demo docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d` +另外,Playground由一条指令全自动搭建:`ENV=dev,demo docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d` ## Quick Start @@ -36,7 +36,7 @@ Turms是一套全球范围内最为先进的、为同时在线用户数为100K~1 git clone --depth 1 https://github.com/turms-im/turms.git cd turms docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions -docker-compose -f docker-compose.standalone.yml up --force-recreate +docker compose -f docker-compose.standalone.yml up --force-recreate ``` 等集群完成搭建后,可以通过 http://localhost:6510 访问turms-admin后台管理系统,并输入账号密码(默认均为`turms`)。如果登录成功,则说明Turms服务端也已经成功启动。 @@ -74,7 +74,7 @@ Turms基于读扩散消息模型进行架构设计,对业务数据变化感知 1. (敏捷性)支持在用户无感知的情况下,对Turms服务端进行停机更新,为快速迭代提供可能 2. (可伸缩性)无状态架构,Turms集群支持弹性扩展与异地多活的部署实现,用户可通过DNS就近接入 -3. (可部署性)支持容器化部署,方便与云服务对接,以实现全自动化部署与运维。Turms默认提供了docker镜像、docker-compose脚本、Terraform模块三套容器化部署方案 +3. (可部署性)支持容器化部署,方便与云服务对接,以实现全自动化部署与运维。Turms默认提供了Docker镜像、Docker compose脚本、Terraform模块三套容器化部署方案 4. (可观测性)具备相对完善的可观测性体系设计,为业务统计与错误排查提供可能 5. (可拓展性)能同时支持中大型即时通讯场景,即便用户体量由小变大也无需重构(当然,对于大型运用场景还有很多优化的工作需要做,但当前架构不影响后期的无痛升级) 6. (安全性)提供限流防刷机制与全局用户/IP黑名单机制,以抵御大部分CC攻击 diff --git a/docker-compose.standalone.yml b/docker-compose.standalone.yml index b441fb19d2..8021df36ad 100644 --- a/docker-compose.standalone.yml +++ b/docker-compose.standalone.yml @@ -3,21 +3,16 @@ # docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions # # Ways to Run: -# docker-compose -f docker-compose.standalone.yml up --force-recreate +# docker compose -f docker-compose.standalone.yml up --force-recreate # # Run in a specific environment (e.g. "dev"): -# Powershell: $env:ENV="dev";docker-compose -f docker-compose.standalone.yml up --force-recreate -# Unix: ENV=dev docker-compose -f docker-compose.standalone.yml up --force-recreate +# Powershell: $env:ENV="dev";docker compose -f docker-compose.standalone.yml up --force-recreate +# Unix: ENV=dev docker compose -f docker-compose.standalone.yml up --force-recreate # # Run with optional monitoring services (Prometheus+Grafana) -# Run with "--profile monitoring": docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate +# Run with "--profile monitoring": docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate # -# Note: -# 1. "mem_limit" is mentioned removed in v3 but still can work in fact if running with compose-v1.29.2 - -version: "3.9" - # Disable loki because it has a critical bug: # https://github.com/grafana/loki/issues/2361 diff --git a/terraform/common/cluster/tpl/user-data-turms-admin.sh b/terraform/common/cluster/tpl/user-data-turms-admin.sh index e39762cf84..c1736928a4 100644 --- a/terraform/common/cluster/tpl/user-data-turms-admin.sh +++ b/terraform/common/cluster/tpl/user-data-turms-admin.sh @@ -4,15 +4,15 @@ sudo apt-get update # Set up Docker repository sudo apt-get install -y \ - apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release -sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg +sudo mkdir -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo \ - "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ - $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null # Install Docker Engine sudo apt-get update diff --git a/terraform/common/cluster/tpl/user-data-turms-gateway.sh b/terraform/common/cluster/tpl/user-data-turms-gateway.sh index 0d457f7da4..3409669d73 100644 --- a/terraform/common/cluster/tpl/user-data-turms-gateway.sh +++ b/terraform/common/cluster/tpl/user-data-turms-gateway.sh @@ -4,15 +4,15 @@ sudo apt-get update # Set up Docker repository sudo apt-get install -y \ - apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release -sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg +sudo mkdir -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo \ - "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ - $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null # Install Docker Engine sudo apt-get update diff --git a/terraform/common/cluster/tpl/user-data-turms-service.sh b/terraform/common/cluster/tpl/user-data-turms-service.sh index 3f3a33401d..a94325161f 100644 --- a/terraform/common/cluster/tpl/user-data-turms-service.sh +++ b/terraform/common/cluster/tpl/user-data-turms-service.sh @@ -4,15 +4,15 @@ sudo apt-get update # Set up Docker repository sudo apt-get install -y \ - apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release -sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg +sudo mkdir -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo \ - "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ - $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null # Install Docker Engine sudo apt-get update diff --git a/terraform/common/playground/tpl/user-data.sh b/terraform/common/playground/tpl/user-data.sh index f4e3f28652..21d99965bb 100644 --- a/terraform/common/playground/tpl/user-data.sh +++ b/terraform/common/playground/tpl/user-data.sh @@ -4,32 +4,22 @@ sudo apt-get update # Set up Docker repository sudo apt-get install -y \ - apt-transport-https \ - ca-certificates \ - curl \ - gnupg \ - lsb-release -sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg + ca-certificates \ + curl \ + gnupg \ + lsb-release +sudo mkdir -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo \ - "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ - $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null -# Install Docker Engine -sudo apt-get update -sudo apt-get install -y docker-ce docker-ce-cli containerd.io +# Install Docker engine and the compose plugin +sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin sudo systemctl start docker sudo systemctl enable docker -# Install docker-compose -DOCKER_COMPOSE_URL="https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -if [ "${USE_CHINA_MIRROR}" == "true" ]; then - DOCKER_COMPOSE_URL="https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -fi -sudo curl -L "$DOCKER_COMPOSE_URL" -o /usr/local/bin/docker-compose -sudo chmod +x /usr/local/bin/docker-compose -sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose - # Install loki-docker-driver sudo docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions @@ -78,4 +68,4 @@ sudo sysctl -p sudo git clone --depth 1 https://github.com/turms-im/turms.git /srv/git # Run Turms Playground -sudo docker-compose -f /srv/git/turms/docker-compose.standalone.yml --profile monitoring up --force-recreate -d \ No newline at end of file +sudo docker compose -f /srv/git/turms/docker-compose.standalone.yml --profile monitoring up --force-recreate -d diff --git a/turms-docs/src/README.md b/turms-docs/src/README.md index c8d9e485a0..906813fb6f 100644 --- a/turms-docs/src/README.md +++ b/turms-docs/src/README.md @@ -26,7 +26,7 @@ Turms是一套全球范围内最为先进的、为同时在线用户数为100K~1 您可以使用任意turms-client-(java/js/swift)客户端,向turms-gateway服务端发送请求,并与其他用户进行交互。 -另外,Playground由一条指令全自动搭建:`ENV=dev,demo docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d` +另外,Playground由一条指令全自动搭建:`ENV=dev,demo docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d` ## Quick Start @@ -36,7 +36,7 @@ Turms是一套全球范围内最为先进的、为同时在线用户数为100K~1 git clone --depth 1 https://github.com/turms-im/turms.git cd turms docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions -docker-compose -f docker-compose.standalone.yml up --force-recreate +docker compose -f docker-compose.standalone.yml up --force-recreate ``` 等集群完成搭建后,可以通过 http://localhost:6510 访问turms-admin后台管理系统,并输入账号密码(默认均为`turms`)。如果登录成功,则说明Turms服务端也已经成功启动。 diff --git a/turms-docs/src/for-developers/getting-started.md b/turms-docs/src/for-developers/getting-started.md index e984f9f24b..a0674c8058 100644 --- a/turms-docs/src/for-developers/getting-started.md +++ b/turms-docs/src/for-developers/getting-started.md @@ -6,7 +6,7 @@ 适用场景:搭建流程方便快捷,但无法满足容灾、弹性扩展、零宕机升级与负载均衡等需求,主要用于搭建Demo用于展示,与服务对SLA无要求的用户。 -#### 基于docker-compose +#### 基于Docker Compose 通过以下命令,可以全自动地搭建一套完整的Turms最小集群(包含turms-gateway、turms-service与turms-admin)及其依赖服务端(MongoDB分片集群与Redis) @@ -14,8 +14,8 @@ git clone --depth 1 https://github.com/turms-im/turms.git cd turms docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions -# Or "ENV=dev,demo docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d" to run with sidecar services in dev profile -docker-compose -f docker-compose.standalone.yml up --force-recreate +# Or "ENV=dev,demo docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d" to run with sidecar services in dev profile +docker compose -f docker-compose.standalone.yml up --force-recreate ``` 等集群完成搭建后,可以通过 http://localhost:6510 访问turms-admin后台管理系统,并输入账号密码(默认均为`turms`)。如果登录成功,则说明Turms集群搭建成功。 @@ -43,16 +43,16 @@ sudo docker plugin enable loki 补充: -* 配合`--profile monitoring`(`docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate`),还可以额外自动搭建Prometheus与Grafana服务端。 +* 配合`--profile monitoring`(`docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate`),还可以额外自动搭建Prometheus与Grafana服务端。 * Turms服务端默认使用生产环境配置,不会向控制台打印日志,只会打印日志文件,因此您通过`docker logs `是无法查看到Turms服务端的运行日志的。为了方便排查问题,您可以在本地开发测试时,把环境变量设置为`ENV=dev`,然后再次启动`docker-compose.standalone.yml`。在dev环境下,Turms会向控制台打印日志,并自动生成测试用的Fake数据,与模拟真实客户端TCP连接与请求 -* 如果您通过上述指令,无法启动`docker-compose.standalone.yml`。则确保服务器的`docker-compose`版本为`1.29.x`,`docker`版本为`19.x.x`或`20.x.x` -* Turms的Playground环境与网站每次都是通过`ENV=dev,demo docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d`这一条命令自动搭建的 +* 如果您通过上述指令,无法启动`docker-compose.standalone.yml`。则确保服务器的`Docker`版本为`20.x.x`与`Docker Compose`插件版本为`2.x.x`, +* Turms的Playground环境与网站每次都是通过`ENV=dev,demo docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d`这一条命令自动搭建的 -#### 基于Terraform与docker-compose +#### 基于Terraform与Docker Compose -(由于Turms目前并没有提供封装好的镜像,因此仍需要使用docker-compose进行环境搭建) +(由于Turms目前并没有提供封装好的镜像,因此仍需要使用Docker Compose进行环境搭建) -该方案是在上述docker-compose方案的基础上,引入了Turms自定义的Terraform模块,以帮助用户自动开通并配置VPC、交换机、安全组与单机ECS抢占式实例。在这台ECS上,Terraform会通过user-data系统初始化脚本,来安装docker-compose与Turms等服务,并最终启动Turms单机集群。 +该方案是在上述Docker Compose方案的基础上,引入了Turms自定义的Terraform模块,以帮助用户自动开通并配置VPC、交换机、安全组与单机ECS抢占式实例。在这台ECS上,Terraform会通过user-data系统初始化脚本,来安装Docker、Docker Compose与Turms等服务,并最终启动Turms单机集群。 具体操作命令如下: diff --git a/turms-server-test-common/src/main/resources/docker-compose.test.yml b/turms-server-test-common/src/main/resources/docker-compose.test.yml index 3b9dc20d0f..b64352d83f 100644 --- a/turms-server-test-common/src/main/resources/docker-compose.test.yml +++ b/turms-server-test-common/src/main/resources/docker-compose.test.yml @@ -1,7 +1,5 @@ # The file is used by tests of servers -version: "3.9" - services: # MongoDB mongodb-router: