Configure docker compose from the device/fleet's Env

Hello!

I’m new to balena, and enjoying it very much, I’m using it to build my own cloud for some compute batch jobs.

The setup is straight forward: I have a container pulling work from a queue.

As I’m adding new devices to the fleet it starts to be a bit more heterogeneous, a mix of Pi4 4GB and Pi 5 8GB. The container works well with 4GB of RAM but can’t really use more than that, as i want to avoid wasting resources and do the work asap. I will run 2 containers on the Pi5.

My question is what’s the best way to do so? I could have a different application and push twice every time I deploy but that doesn’t sound optimal. Is there a way to change the number of replicas in the docker-compose based on an ENV parameter?

Hello @zukoo first of all, welcome to the balena community!

My first recommendation would be to suggest you to use different fleets for different applications that you would like to deploy on devices, instead of using the same.

Unless they are the same application but with tiny differences. If you can manage to start the deploys using device variables that might work as well. Find here an example that i’m not sure it applies with your use case, but just to give you some ideas.

Another thing that you can do is to deploy 2 applications on the same fleet and control the application deployed pinning devices to specific releases. Find here more information.

Let me know if that works and if you need more help!

Thanks, so i understood correctly that device variables cannot be used within the docker-compose file?

My idea was to change the value here based on a device variable: Compose Deploy Specification | Docker Docs

So I’ll go with the one fleet per device type approach.

I realized that the replica attribute of docker-compose isn’t available in blenaOS so instead i implemented the parallelism in the application itself, and that easy to manage with the device env. :tada:

1 Like