Skip to content

Commit

Permalink
chore(cluster_deploy): remove swarm mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ActivePeter committed Dec 7, 2023
1 parent 7e35948 commit 8d1bf94
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 125 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
docker.zip
*.zip

3 changes: 2 additions & 1 deletion scripts/deploy_cluster/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
gen_ansible.ini
gen_docker_stack.yml
gen_docker_stack.yml
compose_*
69 changes: 0 additions & 69 deletions scripts/deploy_cluster/_ans_build_cluster_docker_stack.yml

This file was deleted.

63 changes: 63 additions & 0 deletions scripts/deploy_cluster/_gen_each_node_compose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import yaml
import os

# Get the directory of the current script
DEPLOY_CLUSTER_DIR = os.path.dirname(os.path.abspath(__file__))
NODE_CONFIG = os.path.join(DEPLOY_CLUSTER_DIR, 'node_config.yaml')


def read_yaml(file_path):
with open(file_path, 'r') as file:
data = yaml.safe_load(file)
return data


def generate_docker_compose(ip, nodes):
services = {}
for key, node in nodes.items():
service_name = f"node{key}"

external_port1 = int(node['addr'].split(':')[-1])
external_port2 = external_port1 + 1
external_ip = node['addr'].split(':')[0]

services[service_name] = {
'image': 'wasm_serverless:v1',
'ports': [f"{external_ip}:{external_port1}:{external_port1}/udp", f"{external_port2}:{external_port2}"],
'deploy':{
'resources':{
'limits':{
'memory': '6G'
}
}
},

'volumes': ['/root/wasm_serverless_deploy:/etc/wasm_serverless/config'],
'environment': {
'WASM_SERVERLESS_NODEID': key
}
}

compose_data = {'version': '3', 'services': services}
compose_file_name = os.path.join(DEPLOY_CLUSTER_DIR, f"compose_{ip}.yml")

with open(compose_file_name, 'w') as file:
yaml.dump(compose_data, file, default_flow_style=False)


def main():
data = read_yaml(NODE_CONFIG)

grouped_nodes = {}
for key, node in data['nodes'].items():
ip = node['addr'].split(':')[0]
if ip not in grouped_nodes:
grouped_nodes[ip] = {}
grouped_nodes[ip][key] = node

for ip, nodes in grouped_nodes.items():
generate_docker_compose(ip, nodes)


if __name__ == "__main__":
main()
73 changes: 56 additions & 17 deletions scripts/deploy_cluster/ans_redeploy_cluster.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
---
- hosts: localhost
tasks:
# install rysr, proto, docker, docker-compose
- name: Install All
include_tasks: ../install/_ans_install.yml

- name: Remove Docker Stack
docker_stack:
state: absent
name: wasm_serverless


- name: Build the application on the master node
shell: cargo build --release
Expand All @@ -19,11 +12,8 @@
args:
chdir: ../../apps/fn2

# - name: Debug
# shell: ls ../../target/release/

- name: Generate Docker stack file
include_tasks: _ans_build_cluster_docker_stack.yml
- name: Generate Docker Compose File
shell: python3 _gen_each_node_compose.py

- name: Remove Zip
file:
Expand All @@ -34,6 +24,16 @@
command: "zip -r docker.zip docker"
args:
chdir: ../..

- name: Remove scripts Zip
file:
path: ../../scripts.zip
state: absent

- name: Zip scripts file
command: "zip -r scripts.zip scripts"
args:
chdir: ../..
- hosts: web
vars_prompt:
- name: build_env
Expand All @@ -48,6 +48,25 @@
src: ../../target/release/wasm_serverless
dest: /root/wasm_serverless_deploy/target/release/wasm_serverless
become: yes

- name: Check if the Docker compose configuration file exists
stat:
path: "/root/wasm_serverless_deploy/docker-compose.yml"
register: compose_file

- name: Docker compose down if the configuration file exists
command: docker-compose down
args:
chdir: "/root/wasm_serverless_deploy"
become: yes
when: compose_file.stat.exists
ignore_errors: yes

- name: Copy compose_{ip}.yml to all nodes
copy:
src: ../deploy_cluster/compose_{{ ansible_host }}.yml
dest: /root/wasm_serverless_deploy/docker-compose.yml
become: yes
- name: Copy node_config.yaml to all nodes
copy:
src: ../deploy_cluster/node_config.yaml
Expand Down Expand Up @@ -76,6 +95,21 @@
chdir: /root/wasm_serverless_deploy
become: yes

- name: Copy scripts to all nodes
copy:
src: ../../scripts.zip
dest: /root/wasm_serverless_deploy/scripts.zip
become: yes

- name: Unzip scripts to all nodes
shell: rm -rf scripts && unzip -q -o scripts.zip && rm -f scripts.zip && chmod -R 775 scripts
args:
chdir: /root/wasm_serverless_deploy
become: yes

- name: Install docker
include_tasks: ../install/_ans_install_docker.yml

- name: Build the environment Docker image (conditionally)
command: ./docker/WasmEdge/build_image.sh
args:
Expand All @@ -89,9 +123,14 @@
chdir: /root/wasm_serverless_deploy
become: yes

- name: docker-compose
command: docker-compose -v
args:
chdir: /root/wasm_serverless_deploy
become: yes


- hosts: localhost
tasks:
- name: Stack Up
shell: docker stack deploy -c ../deploy_cluster/gen_docker_stack.yml wasm_serverless
- name: Docker compose up
command: docker-compose --compatibility up -d
args:
chdir: /root/wasm_serverless_deploy
become: yes
8 changes: 4 additions & 4 deletions scripts/deploy_cluster/node_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ nodes:
spec: [meta,worker]
3:
id: t8f80nn3qxavell7leopbab40
addr: 192.168.31.87:2510
addr: 192.168.31.87:2500
spec: [meta,worker]
4:
id: t8f80nn3qxavell7leopbab40
addr: 192.168.31.87:2515
addr: 192.168.31.87:2505
spec: [meta,worker]
5:
id: d8huj03dv09keg3gp4vh1cj7k
addr: 192.168.31.96:2520
addr: 192.168.31.96:2500
spec: [meta,worker]
6:
id: d8huj03dv09keg3gp4vh1cj7k
addr: 192.168.31.96:2525
addr: 192.168.31.96:2505
spec: [meta,worker]
18 changes: 11 additions & 7 deletions scripts/install/_ans_install_build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
- name: Check if Rust is installed
become: true
command: rustc --version
ignore_errors: yes
register: rust_installed

- name: Install required packages
become: true
apt:
Expand All @@ -18,6 +12,16 @@
- protobuf-compiler
- pkg-config
- libssl-dev
- snap

- name: Install Docker
include_tasks: ../install/_ans_install_docker.yml

- name: Check if Rust is installed
become: true
command: rustc --version
ignore_errors: yes
register: rust_installed

- name: Install Rust if not present
become: true
Expand All @@ -42,4 +46,4 @@
when: "'rustc' not in rust_installed.stdout"

- name: Install WasmEdge
include_tasks: _ans_install_wasmedge.yml
include_tasks: _ans_install_wasmedge.yml
16 changes: 16 additions & 0 deletions scripts/install/_ans_install_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: Check Docker installation status
command: docker --version
register: docker_version_output
ignore_errors: true
become: yes

- name: Print Docker version if installed
debug:
msg: "{{ docker_version_output.stdout }}"
become: yes
when: docker_version_output.rc == 0

- name: Handle case when Docker is not installed
shell: snap install docker
become: yes
when: docker_version_output.rc != 0
8 changes: 4 additions & 4 deletions scripts/install/_ans_install_wasmedge.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
- name: Check if the file exists
ansible.builtin.stat:
path: inner/WasmEdge-0.13.3-manylinux2014_x86_64.tar.gz
path: ../install/inner/WasmEdge-0.13.3-manylinux2014_x86_64.tar.gz
register: file_stat

- name: Download WasmEdge release file
become: true
ansible.builtin.get_url:
url: "https://github.com/WasmEdge/WasmEdge/releases/download/0.13.3/WasmEdge-0.13.3-manylinux2014_x86_64.tar.gz"
dest: "inner/WasmEdge-0.13.3-manylinux2014_x86_64.tar.gz"
dest: "../install/inner/WasmEdge-0.13.3-manylinux2014_x86_64.tar.gz"
when: not file_stat.stat.exists

- name: Install WasmEdge
Expand All @@ -24,5 +24,5 @@
bash /tmp/install_wasmedge.sh
rm -f /tmp/install_wasmedge.sh
args:
chdir: '../..'
creates: "/usr/local/bin/wasmedge" # Skip if WasmEdge is already installed
chdir: "../.."
creates: "/usr/local/bin/wasmedge" # Skip if WasmEdge is already installed
Empty file.
26 changes: 26 additions & 0 deletions scripts/saaf/app_installed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import subprocess
import sys

def is_command_installed(command):
try:
# 使用subprocess.check_call来执行指令,如果指令存在则返回0,否则抛出异常
subprocess.check_call([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return True
except subprocess.CalledProcessError:
return False
except FileNotFoundError:
return False

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <command>")
sys.exit(1)

command_to_check = sys.argv[1]
result = is_command_installed(command_to_check)

# 通过echo输出结果
if result:
print("true")
else:
print("false")
Loading

0 comments on commit 8d1bf94

Please sign in to comment.