Skip to content

deploy fractal environment #75

deploy fractal environment

deploy fractal environment #75

name: deploy-mqttcli
on:
workflow_dispatch:
inputs:
runner_number:
description: 'Runner number (1-2)'
required: true
type: choice
options:
- 1
- 2
jobs:
set-runners:
runs-on: ubuntu-latest
outputs:
runner_combinations: ${{ steps.set-runner-combinations.outputs.runner_combinations }}
fractal_ips: ${{ steps.init-fractal-ips.outputs.fractal_ips }}
steps:
- name: Set Runner Combinations
id: set-runner-combinations
run: |
echo "Setting Runner Combinations"
# 生成 mqtt-client 和 fractal-edge 的标签数组
mqtt_client=$(seq 1 2 | sed 's/^/mqtt-client/')
fractal_edge=$(seq 1 2 | sed 's/^/fractal-edge-/')
# 将标签转换为 JSON 数组
mqtt_json=$(echo "$mqtt_client" | jq -R -s -c 'split("\n")[:-1]') # 去除末尾空元素
fractal_json=$(echo "$fractal_edge" | jq -R -s -c 'split("\n")[:-1]')
# 生成组合数组:一一对应的 [{"mqtt_client": "mqtt-client1", "fractal_edge": "fractal-edge-1"}, ...]
combinations=$(jq -n --argjson a "$mqtt_json" --argjson b "$fractal_json" '$a | to_entries | map({ mqtt_client: .value, fractal_edge: $b[.key] })'| jq -c .)
# 调试输出
echo "Generated combinations: $combinations"
# 设置输出
echo "::set-output name=runner_combinations::$combinations"
- name: Initialize fractal_ips
id: init-fractal-ips
run: |
fractal_ips='{}'
echo "::set-output name=fractal_ips::$fractal_ips"
deploy-fractal-edge:
needs: set-runners
strategy:
matrix:
combination: ${{ fromJSON(needs.set-runners.outputs.runner_combinations) }}
runs-on:
group: fractal
labels:
- self-hosted
- Linux
- X64
- edge_td
- fractal
- ${{ matrix.combination.fractal_edge }}
outputs:
fractal_ips: ${{ matrix.combination.fractal_edge }}_ip
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get IP Addresses
id: get-ip
run: |
local_ip=$(hostname -I | awk '{print $1}')
echo "Local IP Address: $local_ip"
echo "local_ip=$local_ip" >> $GITHUB_OUTPUT
- name: Collect IPs
id: collect-ips
run: |
echo "Collecting IPs"
# 获取当前 runner 的首个 IP 地址
local_ip=${{ steps.get-ip.outputs.local_ip }}
# 获取当前任务的 fractal_edge 标识
fractal_edge=${{ matrix.combination.fractal_edge }}
# 获取前面任务累积的 fractal_ips
fractal_ips=${{ needs.set-runners.outputs.fractal_ips }}
# 更新 fractal_ips 对象
fractal_ips=$(echo "$fractal_ips" | jq --arg key "$fractal_edge" --arg value "$local_ip" '.[$key] = $value' | jq -c .)
echo "::set ${{ matrix.combination.fractal_edge }}=$fractal_ips" >> $GITHUB_OUTPUT
echo "::set-output name=${{ matrix.combination.fractal_edge }}_ip::$fractal_ips"
deploy-mqtt-client:
needs: [set-runners,deploy-fractal-edge]
strategy:
matrix:
combination: ${{ fromJSON(needs.set-runners.outputs.runner_combinations) }}
runs-on:
group: fractal
labels:
- self-hosted
- Linux
- X64
- fractal
- ${{ matrix.combination.mqtt_client }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Use Fractal Edges IPs
run: |
fractal_ip=${{ needs.deploy-fractal-edge.outputs.fractal_ips }}
echo "Fractal IPs: $fractal_ip"
# run: |
# cd /root/tools/deploy && ./setup_system.sh replace_sources
# - name: Install MQTT CLI
# uses: taosdata/.github/.github/actions/install-mqtt-simulator
# with:
# res_app_id: ${{ vars.TAOSDATA_BOT_ID }}
# res_app_key: ${{ secrets.TAOSDATA_BOT_KEY }}
# - name: Find mqtt_pub binary
# run: |
# if command -v mqtt_pub &> /dev/null; then
# echo "mqtt_pub found at $(command -v mqtt_pub)"
# else
# echo "mqtt_pub not found"
# fi