Build, distribute and run binaries using GitHub

In this example we show how to use GitHub to deploy a binary file to your fleet of Raspberry Pis. The specific binary is written in go. The process starts by pushing the changes of your source code to your GitHub repository. Then, using GitHub actions, your source code is cross compiled for your Raspberry Pi and finally the binary is placed into your qbee.io file manager. From there on you can distribute and run it on the group of devices you have specified.

If we want to build an executable (called hi-pi) for our Raspberry Pi we can use the following code

main.go

package main

import "fmt"

func main() {
    fmt.Println("Hello Norway")
}

we can easily do that locally using

   $ env GOARCH=arm GOOS=linux go build -o hi-pi main.go
thanks to go's powerful cross compilation capabilities.

However, we aim to setup an automatic workflow, where we

  • use git as for version control management
  • setup a GitHub runner (using GitHub actions) to build our code once a push is triggered
  • copy the created binary to the qbee.io file manager via API calls
  • use the qbee.io file distribution to distribute (and run) the executable on a list of devices

How to create a repository on GitHub

Check out the official documentation on how to create a repository on GitHub.

Once a repository is set up, before creating a runner you need to set up GitHub secrets as shown in the following screenshot.

GitHub secrets

There we specify our qbee.io username with USERNAME_KEY and our password with PASSWORD_KEY, as we do not want them to be exposed.

After the passwords are defined we start GitHub actions which executes the YAML file on the runners on GitHub (or you can use a custom runner). GitHub actions are created under "set up a workflow yourself".

GitHub action

This is the script:

go-package-distribution.yml
name: Go package distribution

on:
push:
    branches: [ master ]
pull_request:
    branches: [ master ]

jobs:


build:
    runs-on: ubuntu-latest
    env:
        APPNAME: hi-pi

    steps:
    - uses: actions/checkout@v2

    - name: create go executable
      env:
        GOARCH: arm
        GOOS: linux
      run: go build -o $APPNAME main.go

    - name: qbee.io authentication
      uses: qbee-io/authenticate-action@v1
      id: qbee-auth
      with:
        login: ${{ secrets.USERNAME_KEY }}
        password: ${{ secrets.PASSWORD_KEY }}

    - name: qbee.io file upload
      uses: qbee-io/file-upload-action@v1
      with:
        token: ${{ steps.qbee-auth.outputs.token }}
        filename: ${{ env.APPNAME }}
        qbee_directory: '/'
        local_directory: '.'

Comments on the yaml file

  • this action is triggered on pushes to the master branch
  • the runner is a virtual machine with an Ubuntu OS as we specified ubuntu-latest
  • The actions/checkout@v2 option will check out your code on the virtual machine. This needs to be done every time as the virtual machine is not persistent
  • we set up a step, where we build the go application using cross compilation (due to the specified environment variables GOARCH and GOOS
  • a custom GitHub action places the output file into the qbee.io file manager (within the action the qbee.io REST API is used, c.f. file distribution via API)

Note that your credentials aren't revealed as we use GitHub secrets to encrypt them as you can see in the action output

!github-secrets

Finally, we distribute our files to the remote devices as usual with the standard file distribution.

Automatic deployment

Using this workflow, every time you push your code changes to the repository the output binary (or binaries) will always be replaced within the file manager. If the binary file differs from the one previously placed in the file manager, then the file distribution is triggered along with the run command that you provided.

Hence, all your edge devices are updated by a simple git push :)