Pulling from a git repo when container starts

Hi there,

I’m hoping this is a relatively common use-case, so maybe someone has a solution. The majority of projects I’ve been working on using balena are pretty straight-forward, docker image running node10 and then running a node server. I’m growing frustrated with the deployment times any time I make a change to my node server, it’s 20+ minutes of deployment and build time, only to find out a package is missing from the package.json (as an example) and I have to go through the process again. It seems inefficient to me to have to rebuild the entire base image / container etc when trying to deploy a simple javascript update. Is there a way to deploy the container once, and have it simply pull from a git repo and run ‘yarn’ every time the container boots? This way, if I simply update my repo, I can restart the container and the changes will reflect immediately.

Anyone done anything similar?


Hi Craig, I think what might be useful for you is our ‘Live Push’ feature, that makes use of Local Mode and functions by looking for changes in the source, and then only pushing those changes to the target device. You can read about it more here: https://www.balena.io/blog/living-on-the-edge-with-livepush-and-other-cli-improvements/

Hope that helps!

Perfect, thanks @dtischler

Agree with dtischler that you would be hard pressed to beat balenaCloud’s binary image diff system. The traditional caching used in Docker is merely layer-based, and any change to package.json / package-lock.json will invalidate the cache on the corresponding yarn install (still happy to suggest basic build optimizations based on the Dockerfile).

Yes, your idea is also possible, because you can run any code at runtime (including a shell script containing git pull & yarn install && node index.js;) and skip installing the packages in the image (or even the source code). Would not recommend because this undercuts Balena’s single-source simplicty - I used to manually git pull and npm ci everything and would see sporadic unrecoverable filesystem corruption in the git and npm file caches. Introducing those systems here will mean more writes to disk and dependence on being able to reach more servers just to get started.