Skip to content

Commit

Permalink
Upgrade docker compose from v1 to v2 in scripts and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChenX committed Nov 12, 2022
1 parent b0d873f commit f6dc34c
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
sudo ENV=dev,demo INITIAL_ROOT_PASSWORD='${{ secrets.PLAYGROUND_ROOT_PASSWORD }}' docker compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate -d
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ 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:
```sh
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.

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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服务端也已经成功启动。
Expand Down Expand Up @@ -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攻击
Expand Down
13 changes: 4 additions & 9 deletions docker-compose.standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions terraform/common/cluster/tpl/user-data-turms-admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions terraform/common/cluster/tpl/user-data-turms-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions terraform/common/cluster/tpl/user-data-turms-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 11 additions & 21 deletions terraform/common/playground/tpl/user-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
sudo docker compose -f /srv/git/turms/docker-compose.standalone.yml --profile monitoring up --force-recreate -d
4 changes: 2 additions & 2 deletions turms-docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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服务端也已经成功启动。
Expand Down
18 changes: 9 additions & 9 deletions turms-docs/src/for-developers/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

适用场景:搭建流程方便快捷,但无法满足容灾、弹性扩展、零宕机升级与负载均衡等需求,主要用于搭建Demo用于展示,与服务对SLA无要求的用户。

#### 基于docker-compose
#### 基于Docker Compose

通过以下命令,可以全自动地搭建一套完整的Turms最小集群(包含turms-gateway、turms-service与turms-admin)及其依赖服务端(MongoDB分片集群与Redis)

```bash
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集群搭建成功。
Expand Down Expand Up @@ -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_CONTAINER_ID>`是无法查看到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单机集群。

具体操作命令如下:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# The file is used by tests of servers

version: "3.9"

services:
# MongoDB
mongodb-router:
Expand Down

0 comments on commit f6dc34c

Please sign in to comment.