From 9762b220d390971dd7e460c9f4408bb8fcd12731 Mon Sep 17 00:00:00 2001 From: ActivePeter <1020401660@qq.com> Date: Thu, 7 Dec 2023 18:29:43 +0800 Subject: [PATCH 1/2] chore(delpoy_cluster): available tc --- docker/WasmEdge/Dockerfile | 2 +- docker/WasmServerless/wasm_serverless_entrypoint.sh | 6 ++++++ scripts/deploy_cluster/_gen_each_node_compose.py | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docker/WasmEdge/Dockerfile b/docker/WasmEdge/Dockerfile index 1ba7654..18b1223 100644 --- a/docker/WasmEdge/Dockerfile +++ b/docker/WasmEdge/Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu:18.04 as wasm_serverless LABEL maintainers="ActivePeter" LABEL description="Wasm serverless platform" -RUN apt-get update && apt-get install -y python3 python3-pip git && mkdir -p /tmp/install +RUN apt-get update && apt-get install -y python3 python3-pip git iproute2 iputils-ping && mkdir -p /tmp/install # COPY --from=builder /root/.wasmedge /root/.wasmedge COPY wasm_edge.py /tmp/install/wasm_edge.py COPY WasmEdge-0.13.3-manylinux2014_x86_64.tar.gz /tmp/install/WasmEdge-0.13.3-manylinux2014_x86_64.tar.gz diff --git a/docker/WasmServerless/wasm_serverless_entrypoint.sh b/docker/WasmServerless/wasm_serverless_entrypoint.sh index 754818b..3e23d95 100644 --- a/docker/WasmServerless/wasm_serverless_entrypoint.sh +++ b/docker/WasmServerless/wasm_serverless_entrypoint.sh @@ -3,6 +3,12 @@ echo "Node id: ${WASM_SERVERLESS_NODEID}" echo "Who am i: $(whoami)" +# tc qdisc add dev eth0 root netem delay 100ms + +# tc qdisc add dev eth0 root tbf rate 1mbit burst 10kb latency 70ms + +timeout 10 ping baidu.com + cd /usr/local/bin/ ls /etc/wasm_serverless/ diff --git a/scripts/deploy_cluster/_gen_each_node_compose.py b/scripts/deploy_cluster/_gen_each_node_compose.py index b9a9a37..ddd29a3 100644 --- a/scripts/deploy_cluster/_gen_each_node_compose.py +++ b/scripts/deploy_cluster/_gen_each_node_compose.py @@ -14,6 +14,7 @@ def read_yaml(file_path): def generate_docker_compose(ip, nodes): services = {} + for key, node in nodes.items(): service_name = f"node{key}" @@ -35,7 +36,8 @@ def generate_docker_compose(ip, nodes): 'volumes': ['/root/wasm_serverless_deploy:/etc/wasm_serverless/config'], 'environment': { 'WASM_SERVERLESS_NODEID': key - } + }, + 'privileged': True # for tc control } compose_data = {'version': '3', 'services': services} From 700f7415627bfcb77a94d55d1863c0f52d5f0c6b Mon Sep 17 00:00:00 2001 From: ActivePeter <1020401660@qq.com> Date: Tue, 19 Dec 2023 19:56:15 +0800 Subject: [PATCH 2/2] chore: add undeploy --- scripts/deploy_cluster/3.undeploy.sh | 1 + .../deploy_cluster/ans_undeploy_cluster.yml | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 scripts/deploy_cluster/3.undeploy.sh create mode 100644 scripts/deploy_cluster/ans_undeploy_cluster.yml diff --git a/scripts/deploy_cluster/3.undeploy.sh b/scripts/deploy_cluster/3.undeploy.sh new file mode 100644 index 0000000..13daf99 --- /dev/null +++ b/scripts/deploy_cluster/3.undeploy.sh @@ -0,0 +1 @@ +ansible-playbook -vv scripts/deploy_cluster/ans_undeploy_cluster.yml -i scripts/deploy_cluster/gen_ansible.ini \ No newline at end of file diff --git a/scripts/deploy_cluster/ans_undeploy_cluster.yml b/scripts/deploy_cluster/ans_undeploy_cluster.yml new file mode 100644 index 0000000..f3fb1ce --- /dev/null +++ b/scripts/deploy_cluster/ans_undeploy_cluster.yml @@ -0,0 +1,25 @@ +--- +- hosts: web + vars: + container_whitelist: + - "portainer" + + tasks: + - name: 获取所有运行中的容器 + command: docker ps -q + register: running_containers + ignore_errors: true + + - name: 关闭非白名单中的容器 + docker_container: + name: "{{ item }}" + state: stopped + with_items: "{{ running_containers.stdout_lines }}" + when: item not in container_whitelist and running_containers.stdout_lines|length > 0 + + - name: 删除非白名单中的容器 + docker_container: + name: "{{ item }}" + state: absent + with_items: "{{ running_containers.stdout_lines }}" + when: item not in container_whitelist and running_containers.stdout_lines|length > 0