# Balena Push via GitHub Actions?

**URL:** <https://forums.balena.io/t/balena-push-via-github-actions/68084>\
**Category:** Product support\
**Created:** [February 29, 2020, 6:03am UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084 "2020-02-29T06:03:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wlisac](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/wlisac/32/1412_2.png) [@wlisac](https://forums.balena.io/u/wlisac)\
**Post date:** [February 29, 2020, 6:03am UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084/1 "2020-02-29T06:03:18Z")

</div>

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](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](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.

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

```

---

<div class="post-metadata">

**Author:** ![richbayliss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/richbayliss/32/1054_2.png) [@richbayliss](https://forums.balena.io/u/richbayliss)\
**Post date:** [March 2, 2020, 1:46pm UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084/4 "2020-03-02T13:46:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rapha](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/rapha/32/1239_2.png) [@rapha](https://forums.balena.io/u/rapha)\
**Post date:** [February 11, 2021, 11:53pm UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084/6 "2021-02-11T23:53:29Z")

</div>

@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](https://github.com/bekriebel/balena-cli-action) but they seem rather outdated.

---

<div class="post-metadata">

**Author:** ![circleoncircles](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/circleoncircles/32/5917_2.png) [@circleoncircles](https://forums.balena.io/u/circleoncircles)\
**Post date:** [June 3, 2021, 2:43am UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084/7 "2021-06-03T02:43:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![barryjump](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@barryjump](https://forums.balena.io/u/barryjump)\
**Post date:** [June 16, 2021, 9:09am UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084/8 "2021-06-16T09:09:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [June 21, 2021, 11:23am UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084/11 "2021-06-21T11:23:54Z")

</div>

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

> **[balena-io-playground/github-actions](https://github.com/balena-io-playground/github-actions)**
>
> Collection of github actions you can use to easily integrate projects with balena. - balena-io-playground/github-actions

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.

---

<div class="post-metadata">

**Author:** ![rapha](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/rapha/32/1239_2.png) [@rapha](https://forums.balena.io/u/rapha)\
**Post date:** [July 15, 2021, 12:20pm UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084/16 "2021-07-15T12:20:39Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [July 27, 2021, 4:48pm UTC](https://forums.balena.io/t/balena-push-via-github-actions/68084/19 "2021-07-27T16:48:53Z")

</div>

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