Balena Push via GitHub Actions?

Hi there,

I’m wondering if there are plans to support an official GitHub Action to push code to a BalenaCloud app using the Balena CLI?

@shaunmulligan – I’ve seen this on the product roadmap, but I’m not sure if it’s specific to a GitHub Action: https://trello.com/c/ElN82kKs/73-deploy-from-a-github-repository

This community action is helpful, but it’s slow since it builds from source (and it’s not versioned): https://github.com/theaccordance/balena-push

It’s relatively straightforward to DIY with something like this, but I think being able to use an official (and versioned) action would be a great addition.

    - name: Balena Push
      run: |
        curl -L -o /tmp/balena.zip https://github.com/balena-io/balena-cli/releases/download/v11.28.5/balena-cli-v11.28.5-linux-x64-standalone.zip
        unzip /tmp/balena.zip -d /opt
        rm /tmp/balena.zip
        export PATH=$PATH:/opt/balena-cli
        balena login --token ${{secrets.BALENA_TOKEN}}
        balena push My-App

Hey,

Thanks for sharing this; I personally wasn’t aware of the project you linked.

It has been made aware to our product team and I believe that they will be discussing the possibility of us providing an official action soon.

3 Likes

@richbayliss Great to hear. Any progress to report on this? There are a couple of actions I am aware of, such as: GitHub - bekriebel/balena-cli-action: Continuously deploy your application to BalenaCloud but they seem rather outdated.

ping the progress, I am too could not use any pre-build actions

+1 on this. I too tried all the community built Github Actions, but none worked and all seemed outdated.

An official Github Action from Balena would be glorious.

@barryjump @circleoncircles let me share with you something that it’s still work in progress but it would be cool to get your feedback and maybe contributions?

Remember, this repo is on balena-io-playground, so that means that it’s not ready for production and it’s still WIP. But glad to learn what do you think.

We manage to push via a Github Action, but had to manually update one of the existing balena github actions to use the newest balena cli.

We have a few specialities such as

  • pulling pre-built images prior to deployment from both Github and Gitlab - We have native arm64 runners that are significantly quicker than balena’s - we thus also deploy using the --emulate tag to hit the quicker balena x86 runners
  • having to handle submodules
  • Caching through the image itself (will blow up the image size - do something else)
  • Tag the balena release with the branch or git tag, as well as the git SHA

My workflow file looks like this:

name: Build Docker images and deploy to Balena

on:
  push:
    branches:
      - "master"
  workflow_dispatch:
jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: checkout submodules using deploy ssh key
        env:
          SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
        run: |
          mkdir $HOME/.ssh && echo "$SSH_KEY" > $HOME/.ssh/id_rsa && chmod 600 $HOME/.ssh/id_rsa
          ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
          ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts
          git submodule sync --recursive
          git submodule update --init --recursive --force
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Build Do image
        uses: docker/build-push-action@v2
        with:
          context: .
          file: nx.Dockerfile
          push: true
          tags: ghcr.io/SOME_ORG/SOME_IMAGE
          platforms: linux/arm64
          cache-from: type=registry,ref=ghcr.io/SOME_ORG/SOME_IMAGE
          cache-to: type=inline
      - 
        name: "Pull containers"
        run: docker-compose pull
      - 
        name: Balena Deploy
        uses: aivero/balena-cli-action@master
        if: success()
        timeout-minutes: 15
        with:
          balena_api_token: ${{ secrets.BALENA_TOKEN }}
          balena_command: balena deploy SOME_BALENA_APPLICATION --emulated
          balena_secrets: |
            {
              "ghcr.io": {
                "username": "${{ github.actor }}",
                "password": "${{ secrets.GITHUB_TOKEN }}"
              }
            }
      - 
        name: Balena tag release with git ref
        uses: aivero/balena-cli-action@master
        if: success()
        timeout-minutes: 5
        with:
          balena_api_token: ${{ secrets.BALENA_TOKEN }}
          balena_command: balena app SOME_BALENA_APPLICATION | grep COMMIT | awk '{print $2}' | xargs balena tag set version ${{ github.ref }}  --release
      - 
        name: Balena tag telease with git SHA
        uses: aivero/balena-cli-action@master
        if: success()
        timeout-minutes: 5
        with:
          balena_api_token: ${{ secrets.BALENA_TOKEN }}
          balena_command: balena app SOME_BALENA_APPLICATION | grep COMMIT | awk '{print $2}' | xargs balena tag set commit_sha ${{ github.sha }}  --release
1 Like

Hey thanks for the feedback, ill forward to the team that’s working on this so they are aware of the use case.