From 30e2b8318d51d8999aff28d285c828dbceced6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Verstraeten?= Date: Mon, 9 Mar 2026 11:40:24 +0000 Subject: [PATCH] Refactor build workflow to support multi-architecture builds and enhance MQTT connection handling --- .github/workflows/pr-build.yml | 51 +++++++--------------------- machinery/src/routers/mqtt/main.go | 11 +++++- ui/src/pages/Dashboard/Dashboard.jsx | 14 ++++---- 3 files changed, 29 insertions(+), 47 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 3725aab..8ef3c9c 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -7,61 +7,34 @@ env: REPO: kerberos/agent jobs: - build-amd64: - runs-on: ubuntu-24.04 + build: + runs-on: ${{ matrix.runner }} permissions: contents: write strategy: matrix: - architecture: [amd64] + include: + - architecture: amd64 + runner: ubuntu-24.04 + dockerfile: Dockerfile + - architecture: arm64 + runner: ubuntu-24.04-arm + dockerfile: Dockerfile.arm64 steps: + - name: Checkout + uses: actions/checkout@v3 - name: Login to DockerHub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Checkout - uses: actions/checkout@v3 - uses: benjlevesque/short-sha@v2.1 id: short-sha with: length: 7 - name: Run Build run: | - docker build -t ${{matrix.architecture}} . - CID=$(docker create ${{matrix.architecture}}) - docker cp ${CID}:/home/agent ./output-${{matrix.architecture}} - docker rm ${CID} - - name: Strip binary - run: tar -cf agent-${{matrix.architecture}}.tar -C output-${{matrix.architecture}} . && rm -rf output-${{matrix.architecture}} - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: agent-${{matrix.architecture}}.tar - path: agent-${{matrix.architecture}}.tar - - build-arm64: - runs-on: ubuntu-24.04-arm - permissions: - contents: write - strategy: - matrix: - architecture: [arm64] - steps: - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Checkout - uses: actions/checkout@v3 - - uses: benjlevesque/short-sha@v2.1 - id: short-sha - with: - length: 7 - - name: Run Build - run: | - docker build -t ${{matrix.architecture}} -f Dockerfile.arm64 . + docker build -t ${{ matrix.architecture }} -f ${{ matrix.dockerfile }} . CID=$(docker create ${{matrix.architecture}}) docker cp ${CID}:/home/agent ./output-${{matrix.architecture}} docker rm ${CID} diff --git a/machinery/src/routers/mqtt/main.go b/machinery/src/routers/mqtt/main.go index 75a71b8..926a3c3 100644 --- a/machinery/src/routers/mqtt/main.go +++ b/machinery/src/routers/mqtt/main.go @@ -90,12 +90,16 @@ func ConfigureMQTT(configDirectory string, configuration *models.Configuration, // Some extra options to make sure the connection behaves // properly. More information here: github.com/eclipse/paho.mqtt.golang. - opts.SetCleanSession(true) + opts.SetCleanSession(false) + opts.SetResumeSubs(true) + opts.SetStore(mqtt.NewMemoryStore()) opts.SetConnectRetry(true) opts.SetAutoReconnect(true) opts.SetConnectRetryInterval(5 * time.Second) + opts.SetMaxReconnectInterval(1 * time.Minute) opts.SetKeepAlive(30 * time.Second) opts.SetPingTimeout(10 * time.Second) + opts.SetWriteTimeout(10 * time.Second) opts.SetOrderMatters(false) opts.SetConnectTimeout(30 * time.Second) opts.SetConnectionLostHandler(func(client mqtt.Client, err error) { @@ -108,6 +112,9 @@ func ConfigureMQTT(configDirectory string, configuration *models.Configuration, opts.SetReconnectingHandler(func(client mqtt.Client, options *mqtt.ClientOptions) { log.Log.Warning("routers.mqtt.main.ConfigureMQTT(): reconnecting to MQTT broker") }) + opts.SetOnConnectHandler(func(c mqtt.Client) { + log.Log.Info("routers.mqtt.main.ConfigureMQTT(): MQTT session is online") + }) hubKey := "" // This is the old way ;) @@ -150,6 +157,8 @@ func ConfigureMQTT(configDirectory string, configuration *models.Configuration, if token := mqc.Connect(); token.WaitTimeout(30 * time.Second) { if token.Error() != nil { log.Log.Error("routers.mqtt.main.ConfigureMQTT(): unable to establish mqtt broker connection, error was: " + token.Error().Error()) + } else { + log.Log.Info("routers.mqtt.main.ConfigureMQTT(): initial MQTT connection established") } } else { log.Log.Error("routers.mqtt.main.ConfigureMQTT(): timed out while establishing mqtt broker connection") diff --git a/ui/src/pages/Dashboard/Dashboard.jsx b/ui/src/pages/Dashboard/Dashboard.jsx index b6cbbad..385b875 100644 --- a/ui/src/pages/Dashboard/Dashboard.jsx +++ b/ui/src/pages/Dashboard/Dashboard.jsx @@ -41,16 +41,10 @@ class Dashboard extends React.Component { this.handleLiveviewLoad = this.handleLiveviewLoad.bind(this); } - handleLiveviewLoad() { - this.setState({ - liveviewLoaded: true, - }); - } - componentDidMount() { const liveview = document.getElementsByClassName('videocard-video'); if (liveview && liveview.length > 0) { - this.liveviewElement = liveview[0]; + [this.liveviewElement] = liveview; this.liveviewElement.addEventListener('load', this.handleLiveviewLoad); } this.initialiseLiveview(); @@ -77,6 +71,12 @@ class Dashboard extends React.Component { dispatchSend(message); } + handleLiveviewLoad() { + this.setState({ + liveviewLoaded: true, + }); + } + handleClose() { this.setState({ open: false,