Add another service to an existing Balena device

Hi!

I have successfully installed the Balena OS on my Raspberry Zero W with service balena-cam and now I want to add another service (wifi-connect): how to do this?

I got this error when I try to push the wifi-connect repo: git push balena master

! [rejected] master → master (fetch first)
error: failed to push some refs to [BALENA USERNAME:.git]
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.

Thx for any help.

Hi @leon22,

Welcome to the balena Forums! If you used Deploy with balena for your initial push, you don’t yet have the GitHub repo files on your workstation or any local reference to the remote repo. That means you’ll first need to do a git add repo <git remote add <repo URL.git> before doing a git push balena master.

That said, pushing a project (a containerized service) from a second repo will not add that to your application. It will replace it. In order to create what we call a multi-container application, you need to clone the different repos to your workstation and copy the Dockerfiles and associated content to one common directory, and update the docker-compose.yml. That is, the updated docker-compose.yml would have two (or more) service stanzas that includes everything from both original single docker-compose.yml files:

version: '2.0'
services:
  service1:
    build: ./balena-cam
    ...
  service2:
    build: ./wifi-connect
    ...

Standard Docker formatting and syntax applies.

Let us know how you make out.

John

I should add that you can either a) push your new combined project to a new GitHub repo you own or install balenaCLI and push the application from your workstation to your Raspberry Pi with balena push <app-name>.

John

Thank you. It’s easier to use the balena-cli commands:

balena push [application-name]

Hi,

Whenever you push an application, whether with Deploy with balena, balena push or git, the code will replace whatever else was on the device. The fact that you have a container named main suggests you still only have one container/service running. balena-cam and wifi-connect need to be both included in a docker-compose.yml file in your working directory (on your workstation). If you don’t push your changes to a new GitHub repo and instead point to one of the others, that will be deployed, not your code. balena push <app-name> pushes the code you edited on your workstation to the device.

Your combined docker-compose.yml should look something like this:

version: '2'
services:
        balena-cam:
                build: ./balena-cam
                privileged: true
                restart: always
                network_mode: "host"
                labels:
                        io.balena.features.kernel-modules: '1'
        wifi-connect:
                build: ./wifi-connect
                privileged: true
                restart: always
                network_mode: host

On your workstation, open a shell and grab the balena-cam repo:

git clone https://github.com/balenalabs/balena-cam cd balena-cam

Now clone wifi-connect into your balena-cam directory:

$ git clone https://github.com/balena-io/wifi-connect

Place the above docker-compose.yml in the root of your balena-cam directory:

./balena-cam/docker-compose.yml
./balena-cam/balena-cam/Dockerfile.template
./balena-cam/balena-cam/…
./balena-cam/wifi-connect/Dockerfile.template
./balena-cam/wifi-connect/…


It's a little odd because the balena-cam working directory has a subfolder with the same name.

Hope this helps,
John

Wow. Great help. Thank you very much!