Skip to content

Commit

Permalink
chore: use docker-compose to start etcd and layotto #635 (#657)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>
  • Loading branch information
YoungMa962 and seeflood committed Jun 20, 2022
1 parent 2aa9090 commit f625e97
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 12 deletions.
49 changes: 49 additions & 0 deletions docker/layotto-etcd/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
108 changes: 108 additions & 0 deletions docker/layotto-etcd/etcd_config.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
}
37 changes: 34 additions & 3 deletions docs/en/start/configuration/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!-- tabs:start -->
#### **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.)
Expand All @@ -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
Expand All @@ -35,8 +49,9 @@ Run it:
```shell @background
./layotto start -c ../../configs/runtime_config.json
```
<!-- tabs:end -->

## Start client APP
### step 2. Start client APP

```shell
cd ${project_path}/demo/configuration/common
Expand All @@ -60,6 +75,22 @@ delete keys success
write start
receive subscribe resp store_name:"config_demo" app_id:"apollo" items:<key:"heihei" content:"heihei1" group:"application" label:"prod" tags:<key:"feature" value:"haha" > tags:<key:"release" value:"16" > >
```
### step 3. Stop containers and release resources
<!-- tabs:start -->
#### **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
```
<!-- tabs:end -->

## Next step
### What did this demo do?
Expand Down
37 changes: 34 additions & 3 deletions docs/en/start/sequencer/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!-- tabs:start -->
#### **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/)

Expand All @@ -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:

Expand All @@ -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
```
<!-- tabs:end -->

### 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/
Expand All @@ -69,6 +84,22 @@ Next id:next_id:9
Next id:next_id:10
Demo success!
```
### step 3. Stop containers and release resources
<!-- tabs:start -->
#### **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
```
<!-- tabs:end -->

### Next step
#### What does this client program do?
Expand Down
38 changes: 35 additions & 3 deletions docs/zh/start/configuration/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@
本示例架构如下图,启动的进程有:客户端程程序、Layotto、etcd 。

![](https://gw.alipayobjects.com/mdn/rms_5891a1/afts/img/A*dzGaSb78UCoAAAAAAAAAAAAAARQnAQ)
### step 1. 启动 etcd 和 Layotto
<!-- tabs:start -->
#### **使用 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/)

Expand All @@ -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
Expand All @@ -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)。
<!-- tabs:end -->
## 启动本地client
### step 2. 启动测试demo

```shell
cd ${project_path}/demo/configuration/common
Expand All @@ -68,6 +84,22 @@ delete keys success
write start
receive subscribe resp store_name:"config_demo" app_id:"apollo" items:<key:"heihei" content:"heihei1" group:"application" label:"prod" tags:<key:"feature" value:"haha" > tags:<key:"release" value:"16" > >
```
### step 3.销毁容器,释放资源
<!-- tabs:start -->
#### **关闭 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
```
<!-- tabs:end -->

## 下一步
### 这个客户端Demo做了什么?
Expand Down
Loading

0 comments on commit f625e97

Please sign in to comment.