Skip to content

chore: use docker-compose to start etcd and layotto #635 #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 20, 2022
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
}
}
]
}
}
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 运行 MinIO,然后本地编译、运行 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