From f625e9716da473901af5e98d67422e69895dcebf Mon Sep 17 00:00:00 2001 From: YangMa <104260107+YoungMa962@users.noreply.github.com> Date: Mon, 20 Jun 2022 14:31:12 +0800 Subject: [PATCH] chore: use docker-compose to start etcd and layotto #635 (#657) * chore: use docker-compose to start etcd and layotto #635 * add docker compose * modify the etcd quickstart doc * chore: use docker-compose to start etcd and layotto (#635) * add docker compose * modify the etcd quickstart doc * Update docs/zh/start/configuration/start.md Co-authored-by: seeflood * Update use docker-compose to start etcd and layotto (#635) * Update docs/en/start/configuration/start.md * Update docs/zh/start/sequencer/start.md * Update docs/en/start/sequencer/start.md * fix use docker-compose to start etcd and layotto (#635) * fix some words * add Stop containers and release resources step Co-authored-by: seeflood --- docker/layotto-etcd/docker-compose.yml | 49 +++++++++++ docker/layotto-etcd/etcd_config.json | 108 +++++++++++++++++++++++++ docs/en/start/configuration/start.md | 37 ++++++++- docs/en/start/sequencer/start.md | 37 ++++++++- docs/zh/start/configuration/start.md | 38 ++++++++- docs/zh/start/sequencer/start.md | 38 ++++++++- 6 files changed, 295 insertions(+), 12 deletions(-) create mode 100644 docker/layotto-etcd/docker-compose.yml create mode 100644 docker/layotto-etcd/etcd_config.json diff --git a/docker/layotto-etcd/docker-compose.yml b/docker/layotto-etcd/docker-compose.yml new file mode 100644 index 0000000000..4f3352a90a --- /dev/null +++ b/docker/layotto-etcd/docker-compose.yml @@ -0,0 +1,49 @@ +#Licensed to the Apache Software Foundation (ASF) under one or more +#contributor license agreements. See the NOTICE file distributed with +#this work for additional information regarding copyright ownership. +#The ASF licenses this file to You 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. + +version: '3.3' + +networks: + app-tier: + driver: bridge + +services: + layotto: + image: layotto/layotto:latest + container_name: layotto + command: + - 'start' + volumes: + - ./etcd_config.json:/runtime/configs/config.json + ports: + - 34903:34903 + - 34904:34904 + - 34999:34999 + networks: + - app-tier + depends_on: + - etcd + + etcd: + image: 'bitnami/etcd:latest' + container_name: etcd + environment: + - ALLOW_NONE_AUTHENTICATION=yes + - ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379 + ports: + - 2379:2379 + - 2380:2380 + networks: + - app-tier \ No newline at end of file diff --git a/docker/layotto-etcd/etcd_config.json b/docker/layotto-etcd/etcd_config.json new file mode 100644 index 0000000000..864913680d --- /dev/null +++ b/docker/layotto-etcd/etcd_config.json @@ -0,0 +1,108 @@ +{ + "servers": [ + { + "default_log_path": "stdout", + "default_log_level": "INFO", + "listeners": [ + { + "name": "grpc", + "address": "0.0.0.0:34904", + "bind_port": true, + "filter_chains": [ + { + "filters": [ + { + "type": "grpc", + "config": { + "server_name": "runtime", + "grpc_config": { + "hellos": { + "quick_start_demo": { + "type": "helloworld", + "hello": "greeting" + } + }, + "config_store": { + "config_demo": { + "type": "etcd", + "address": [ + "http://etcd:2379" + ], + "timeout": "10" + } + }, + "sequencer": { + "sequencer_demo": { + "type": "etcd", + "metadata": { + "endpoints": "etcd:2379", + "segmentCacheEnable": "false", + "segmentStep": "1", + "username": "", + "password": "", + "dialTimeout": "5" + } + } + }, + "lock": { + "lock_demo": { + "type": "etcd", + "metadata": { + "endpoints": "etcd:2379", + "username": "", + "password": "", + "keyPrefixPath": "/lock", + "dialTimeout": "5" + } + } + } + } + } + } + ] + } + ], + "stream_filters": [ + { + "type": "flowControlFilter", + "config": { + "global_switch": true, + "limit_key_type": "PATH", + "rules": [ + { + "resource": "/spec.proto.runtime.v1.Runtime/SayHello", + "grade": 1, + "threshold": 5 + } + ] + } + }, + { + "type": "grpc_metric" + } + ] + } + ] + } + ], + "tracing": { + "enable": true, + "driver": "SOFATracer", + "config": { + "generator": "mosntracing", + "exporter": [ + "stdout" + ] + } + }, + "metrics": { + "sinks": [ + { + "type": "prometheus", + "config": { + "port": 34903 + } + } + ] + } +} diff --git a/docs/en/start/configuration/start.md b/docs/en/start/configuration/start.md index 1b187b7be8..8c34ffe3f3 100644 --- a/docs/en/start/configuration/start.md +++ b/docs/en/start/configuration/start.md @@ -7,8 +7,22 @@ The architecture of this demo is shown in the figure below. The processes starte ![](https://gw.alipayobjects.com/mdn/rms_5891a1/afts/img/A*dzGaSb78UCoAAAAAAAAAAAAAARQnAQ) [Then config file](https://github.com/mosn/layotto/blob/main/configs/runtime_config.json) claims `etcd` in the `config_store` section, but users can change it to other configuration center they want (currently only support etcd and apollo). +### step 1. Deploy etcd and Layotto + +#### **With Docker Compose** +You can start etcd and Layotto with docker-compose -## Start etcd +```bash +cd docker/layotto-etcd +# Start etcd and layotto with docker-compose +docker-compose up -d +``` +#### **Compile locally (not for Windows)** +You can run etcd with Docker, then compile and run Layotto locally. + +> [!TIP|label: Not for Windows users] +> Layotto fails to compile under Windows. Windows users are recommended to deploy using docker-compose +#### step 1.1 Start etcd If you want to run this demo, you need to start a etcd server first. You can download etcd from `https://github.com/etcd-io/etcd/releases` (You can also use docker.) @@ -20,7 +34,7 @@ start it: Then you can access etcd with the address `localhost:2379`. -## Start Layotto +#### step 1.2 Start Layotto Build Layotto: ```shell @@ -35,8 +49,9 @@ Run it: ```shell @background ./layotto start -c ../../configs/runtime_config.json ``` + -## Start client APP +### step 2. Start client APP ```shell cd ${project_path}/demo/configuration/common @@ -60,6 +75,22 @@ delete keys success write start receive subscribe resp store_name:"config_demo" app_id:"apollo" items: tags: > ``` +### step 3. Stop containers and release resources + +#### **Docker Compose** +If you started etcd and Layotto with docker-compose, you can shut them down as follows: + +```bash +cd ${project_path}/docker/layotto-etcd +docker-compose stop +``` + +#### **Destroy the etcd container** +If you started etcd with Docker, you can destroy the etcd container as follows: +```shell +docker rm -f etcd +``` + ## Next step ### What did this demo do? diff --git a/docs/en/start/sequencer/start.md b/docs/en/start/sequencer/start.md index a6d2e6642b..b5286b01b0 100644 --- a/docs/en/start/sequencer/start.md +++ b/docs/en/start/sequencer/start.md @@ -11,8 +11,22 @@ This example shows how to call Etcd through Layotto to generate a distributed un The architecture of this example is shown in the figure below, and the processes started are: Etcd, Layotto, and client programs ![img.png](../../../img/sequencer/etcd/img.png) +### step 1. Deploy etcd and Layotto + +#### **With Docker Compose** +You can start etcd and Layotto with docker-compose -### Step 1: Deploy the storage system (Etcd) +```bash +cd docker/layotto-etcd +# Start etcd and layotto with docker-compose +docker-compose up -d +``` +#### **Compile locally (not for Windows)** +You can run etcd with Docker, then compile and run Layotto locally. + +> [!TIP|label: Not for Windows users] +> Layotto fails to compile under Windows. Windows users are recommended to deploy using docker-compose +#### step 1.1 Deploy the storage system (Etcd) For the deployment of etcd, please refer to etcd's [Official Document](https://etcd.io/docs/v3.5/quickstart/) @@ -27,7 +41,7 @@ Once the download is finished,execute the command to start: ``` The default listening address is `localhost:2379` -### Step 2: Run Layotto +#### step 1.2 Run Layotto After downloading the project code to the local, switch the code directory and compile: @@ -44,8 +58,9 @@ Once finished, the layotto file will be generated in the directory, run it: ```shell @background ./layotto start -c ../../configs/runtime_config.json ``` + -### Step 3: Run the client program and call Layotto to generate a unique id +### step 2. Run the client program and call Layotto to generate a unique id ```shell cd ${project_path}/demo/sequencer/common/ @@ -69,6 +84,22 @@ Next id:next_id:9 Next id:next_id:10 Demo success! ``` +### step 3. Stop containers and release resources + +#### **Docker Compose** +If you started etcd and Layotto with docker-compose, you can shut them down as follows: + +```bash +cd ${project_path}/docker/layotto-etcd +docker-compose stop +``` + +#### **Destroy the etcd container** +If you started etcd with Docker, you can destroy the etcd container as follows: +```shell +docker rm -f etcd +``` + ### Next step #### What does this client program do? diff --git a/docs/zh/start/configuration/start.md b/docs/zh/start/configuration/start.md index 847806e1e1..569a075df8 100644 --- a/docs/zh/start/configuration/start.md +++ b/docs/zh/start/configuration/start.md @@ -4,8 +4,23 @@ 本示例架构如下图,启动的进程有:客户端程程序、Layotto、etcd 。 ![](https://gw.alipayobjects.com/mdn/rms_5891a1/afts/img/A*dzGaSb78UCoAAAAAAAAAAAAAARQnAQ) +### step 1. 启动 etcd 和 Layotto + +#### **使用 Docker Compose** +您可以使用 docker-compose 启动 etcd 和 Layotto -## 启动 etcd +```bash +cd docker/layotto-etcd +# Start etcd and layotto with docker-compose +docker-compose up -d +``` + +#### **本地编译(不适合 Windows)** +您可以使用 Docker 运行 etcd,然后本地编译、运行 Layotto。 + +> [!TIP|label: 不适合 Windows 用户] +> Layotto 在 Windows 下会编译失败。建议 Windows 用户使用 docker-compose 部署 +#### step 1.1 启动 etcd etcd的启动方式可以参考etcd的[官方文档](https://etcd.io/docs/v3.5/quickstart/) @@ -25,7 +40,7 @@ etcd的启动方式可以参考etcd的[官方文档](https://etcd.io/docs/v3.5/q 默认监听地址为 `localhost:2379` -## 启动 layotto +#### step 1.2 启动 layotto ```shell cd ${project_path}/cmd/layotto @@ -43,8 +58,9 @@ go build -o layotto ``` > 解释:[runtime_config.json](https://github.com/mosn/layotto/blob/main/configs/runtime_config.json) 是 Layotto 的配置文件,它在 `config_store` 中声明了使用 etcd 作为配置中心。用户可以更改配置文件,改成使用自己想要用的其他配置中心(目前支持 etcd 和 apollo)。 + -## 启动本地client +### step 2. 启动测试demo ```shell cd ${project_path}/demo/configuration/common @@ -68,6 +84,22 @@ delete keys success write start receive subscribe resp store_name:"config_demo" app_id:"apollo" items: tags: > ``` +### step 3.销毁容器,释放资源 + +#### **关闭 Docker Compose** +如果您是用 docker-compose 启动的 etcd 和 Layotto,可以按以下方式关闭: + +```bash +cd ${project_path}/docker/layotto-etcd +docker-compose stop +``` +#### **销毁 etcd Docker 容器** +如果您是用 Docker 启动的 etcd,可以按以下方式销毁 etcd 容器: + +```shell +docker rm -f etcd +``` + ## 下一步 ### 这个客户端Demo做了什么? diff --git a/docs/zh/start/sequencer/start.md b/docs/zh/start/sequencer/start.md index 76c16f58ae..bffaf4ccbc 100644 --- a/docs/zh/start/sequencer/start.md +++ b/docs/zh/start/sequencer/start.md @@ -12,7 +12,22 @@ Sequencer API支持声明对自增的需求,包括趋势递增(WEAK)和严格 ![img.png](../../../img/sequencer/etcd/img.png) -### 第一步:部署存储系统(Etcd) +### step 1. 启动 etcd 和 Layotto + +#### **使用 Docker Compose** +您可以使用 docker-compose 启动 etcd 和 Layotto + +```bash +cd docker/layotto-etcd +# Start etcd and layotto with docker-compose +docker-compose up -d +``` + +#### **本地编译(不适合 Windows)** +您可以使用 Docker 运行 etcd,然后本地编译、运行 Layotto。 +> [!TIP|label: 不适合 Windows 用户] +> Layotto 在 Windows 下会编译失败。建议 Windows 用户使用 docker-compose 部署 +### step 1.1:部署存储系统(Etcd) etcd的启动方式可以参考etcd的[官方文档](https://etcd.io/docs/v3.5/quickstart/) @@ -28,7 +43,7 @@ etcd的启动方式可以参考etcd的[官方文档](https://etcd.io/docs/v3.5/q 默认监听地址为 `localhost:2379` -### 第二步:运行Layotto +### step 1.2:运行Layotto 将项目代码下载到本地后,切换代码目录: @@ -47,8 +62,9 @@ go build -o layotto ```shell @background ./layotto start -c ../../configs/runtime_config.json ``` + -### 第三步:运行客户端程序,调用Layotto生成唯一id +### step 2. 运行客户端程序,调用Layotto生成唯一id ```shell cd ${project_path}/demo/sequencer/common/ @@ -72,6 +88,22 @@ Next id:next_id:9 Next id:next_id:10 Demo success! ``` +### step 3.销毁容器,释放资源 + +#### **关闭 Docker Compose** +如果您是用 docker-compose 启动的 etcd 和 Layotto,可以按以下方式关闭: + +```bash +cd ${project_path}/docker/layotto-etcd +docker-compose stop +``` +#### **销毁 etcd Docker 容器** +如果您是用 Docker 启动的 etcd,可以按以下方式销毁 etcd 容器: + +```shell +docker rm -f etcd +``` + ### 下一步 #### 这个客户端程序做了什么?