forked from 340Lab/waverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cluster_deploy): remove swarm mode
- Loading branch information
1 parent
7e35948
commit 8d1bf94
Showing
15 changed files
with
252 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
target | ||
docker.zip | ||
*.zip | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
69
scripts/deploy_cluster/_ans_build_cluster_docker_stack.yml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Oops, something went wrong.