Balena Electron setup help

Hello all. Does anyone have any experience setting up the balenaBlocks Electron template? I’ve spent the better part of a few days reading through the ReadMe, the included Dockerfiles, and an old blog post trying to see what I’m missing. My expectation is that the sample should run right out of the box, but the container seems to either fail when including the files in specified docker folder or or errors are throw with the balenablocks/armv7hf-balena-electron-env manifest or when running Electron directly.

Is there a better setup guide to get the sample-app running besides the minimal instructions in the ReadMe, or could someone fill in the gaps in instructions?

Thanks in advance.

Note: I’ve used Docker rarely and have never really been able to understand it. I understand Balena is kind of build on or around the Docker ecosystem.

Hey

  • Can you share more details about the error logs, and also what device are you building this on?
  • When running balena push what folder are you running it from?

Thanks for getting back to me. Late last night I figured out what I was doing wrong. I read the instructions wrong, thinking I needed to push the block verses my Electron app. More research into the Belena ecosystem before submitting this should have been my first route.

I’m having trouble with this as well. So you do a git clone, I’ve added at “ADD usr/app/sample-app” to the dockerfile so that the sample app is in usr/app (no clue if that is the correct way to do it but doing a “ls” shows the files) and then I have to use npm start in the terminal to start the electron app and then it seems touch doesn’t work. And of course manually doing npm start doesn’t really make sense. So I think I’m way off here.

A better question, I guess is, what are the exact steps to use this project and run the sample-app correctly?

Let me start by saying you might be better helped by creating a new question vs resurrecting an old one. I’m not entirely sure what I was doing when I set it up. I still don’t. However, I can tell you how I got electron running. I’m running this from memory, so take this with a grain of salt.

Start with the example app in the Git repository. The two files you should focus on are the contained Dockerfile and the start.sh.

The Dockerfile tells Docker what to do, including pulling the necessary Linux distro, pulling the balena-electron-env package, running updates, and COPY the necessary files to make your node app run, and copying the “start.sh” file.

The start.sh file tells the balena-electron-env package what special things you want it to do (error logging, screensaver delay, etc.).

The Dockerfile and start.sh file should be included in the root of your app. You only need to push your app through BalenaCLI to your environment.

As for touch, I don’t know how to help with that. That was never a part of what I was trying to do. Best of luck.

Hey, thanks for the reply! So do you push the entire git repo to balena or only the sample-app? If everything is included out of the box with balena-electron-env and I only have to simply run that as a service that’d be great but it doesn’t seem to be the case. When I use FROM balena-electron-env I get an error saying balena-electron-env doesn’t exist. Even if I use balenablocks/armv7hf-balena-electron-env. Do I have to build that image first with the image-builder in the repo? I feel like it’s something really simple and I’m overly complicating this.

You just push the sample-app. The sample-app is your node app, right? Here’s a minorly oversimplified example: I have created an node/electron app called “MyAwesomeApp” in a folder of the same name. The only things I need to add to my app to get it to run on the Balena system is a Dockerfile and the start.sh. Everything else in “MyAwesomeApp” is what I decided to put there. Balena looks at the Dockerfile first and then everything runs accordingly. Note: as I understand, the Dockerfile is only seen when the container is being made or remade, not everytime you run the container.

Something I suggest you try is getting the sample app running on it’s own first to see if it works. Always interesting to see if/how a developer wants their code to run

There’s some quirks when getting electron on Balena running. What runs fine on your computer using npm start doesn’t necessarily translate the way you want (I ran into some issues with running node script on the front end. I think that might have something to do with Electron vs Balena though).

When you get it working you might be slapping yourself in the forehead. But I started knowing nothing about this stuff. I still don’t quite understand how it works, but I have a better understanding of what each step is supposed to do.

Here’s a copy of my Dockerfile that got me off the ground. I can’t tell you why it works like this–and maybe it currently doesn’t. I stopped development of my project because I kept running into issues and have too many other responsibilities at the moment–but it worked for me. I’ll try to explain what I remember below the copy.

FROM balenalib/armv7hf-debian-node:15.10-buster-build
FROM balenalib/armv7hf-debian-node:15.10-buster-run
FROM balenablocks/armv7hf-balena-electron-env:v1.2.6

RUN apt update
RUN apt upgrade
RUN npm install -g n stable

COPY package-lock.json package.json preload.js renderer.js server.js start.sh ./

RUN npm install

(I was running this on a Raspberry Pi 3b+)

FROM
Line 1) I needed to install a build of Linux that worked for my 32bit, armv7hf device. This pulls the necessary build.
Line 2) Instantiates the Linux build.
Line 3) Pulls the armv7hf version of the balena-electron-env. This is basically the Github repo.

Note: There’s a lot going on in the repo that you do not need to be responsible for. That’s what the developers have done. If you want an idea of what they are doing that you do not, take a look at the Dockerfile.template in the root of the repo.

RUN
Lines 4 & 5) updates the Linux system we’ve installed
Lines 6) installs npm for your app to use

COPY
Line 7) all of the files needed to run your node app including ./, aka every file included in the root directory.

RUN
Line 8) Don’t remember, lol. But I think it had to do with an issue I was running into where node/npm didn’t quite do everything it needed to do.

Last note, I think balena-electron-env is someone’s side project. It’s a framework that tinkers or people who know more of what they’re doing to use/break/learn on. It’s fun to be able to make something work from seemingly nothing. But part of that fun is the problem solving and weird quirks of unfinished/untested/in-progress code. I tried to use balena-electron-env as a display board for my company. And to varying degrees, it worked. But it became a pain for one person to fix, play with, and troubleshoot with all the other necessary responsibilities. It was a fun project when times were slow. I wish I could have used it to greater effect. But I had to let my project die. If you’re looking for something that is stable, that is maintained, you might need to look for a paid solution.

1 Like

Hey @MontreatDesigner , I have taken a stab at explaining some of the fundamentals on this other thread (example project linked in there) that I figured I would link, in order to bring the conversations together: How EXACTLY do you implement the Balena Electron Block?