Build, distribute and run binaries using Github

In short

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 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


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 file manager via API calls
  • use the file distribution to the 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 up Github secrets as shown in the following screenshot. github-secrets There we specify our username and password, as we do not want them to be exposed.

Once that is done, we create a Github actions which runs our setup script on the runners provided by Github (or you can set up your own runners). Github actions can be created as follows (we use "set up a workflow yourself")


The script we used is the following:

name: Go package distribution

    branches: [ master ]
    branches: [ master ]


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

    - uses: actions/checkout@v2

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

    - name: copy to qbee file manager
    run: |
        curl --digest -u ${{ secrets.QM }}:${{ secrets.QP }} -i -X "DELETE" -d "path=/$APPNAME" -H "Content-type: application/x-www-form-urlencoded"
        curl --digest -u ${{ secrets.QM }}:${{ secrets.QP }} -i -X POST -H "Content-Type:multipart/form-data" -F "path=/" -F "file=@$APPNAME"

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
  • on that virtual machine (freshly created for you on every single run) the code from your repository is checked out using the actions/checkout@v2 option
  • we set up a step, where we build the go application using cross compilation (due to the specified environment variables GOARCH and GOOS
  • the output is placed into the root directory of your file manager (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


Finally, we distribute our files to the remote devices as usual with the 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 :)