Deploying an image to balena

Hello, I have written a code in python that will log into dockerhub and will push an image with the latest tag. It will extract the label from the payload and compare this label with the label of the last images deployed to our device. If they are different then we will push this latest image to our local device. Im sure the logic of my code is correct my I can not see the new image on our local device on balena board. I need to mention that I have used the label flag for building my docker image and passing the git-sha - key,value pair
def docker_image(repo_name, tag):
image_name = repo_name + ‘:’ + tag
client = docker.from_env()
client.login(docker_username, docker_password)
latest_image_pulled = client.images.pull(image_name)
cmd_copy = ‘docker inspect -f “{{json .Config.Labels }}” ’ + image_name + ’ |json_pp’
fl = os.popen(cmd_copy)
label_portion =
print (’ \nLabel portion extracted from payload is:’, label_portion)
label_dict_persentation = json.loads(label_portion)
label_last_image_pulled = label_dict_persentation[‘git-sha’]
print (’ \nValue of the git-sha- Label of the last image pulled from dockerhub is :’, label_last_image_pulled)
return image_name, label_last_image_pulled

def balena_push(image_name, app_name):
balena = Balena()
auth_token = balena.auth.authenticate(username = balena_username, password = balena_password)
balena_login =[‘balena’, ‘login’, ‘–token’, auth_token], capture_output=True, text=True, check=True)
print(’ \nbalena_login_returncode is :’, balena_login.returncode)
balena_deploy =[‘balena’, ‘deploy’, app_name, image_name], capture_output=True, text=True, check=True)
print(’ \nbalena_deploy_returncode is: ', balena_deploy.returncode)
return (balena_deploy.returncode)

def main():
image_name, label_last_image_pulled = docker_image(repo_name, tag)

print(' \nIn the def main() the label passed from docker_image def is: ', label_last_image_pulled)
with open ('timestamp.txt', 'r+') as f_last_pushed:
	f_last_pushed_content = f_last_pushed.readline()
	print(' \nLabel inside the file indicates the last image pushed to the local device is: ',f_last_pushed_content, end='')
	if f_last_pushed_content != label_last_image_pulled:
		deploy_result = balena_push(image_name, app_name)
		if int(deploy_result) == 0:
			print(' \nBalena Deployment was unsuccessful')
		print(' \nLocal device is up to date, no new images since last image:', label_last_image_pulled)


Firstly, it might be worth wrapping your code block in triple backticks so that it can be correctly formatted. This will help others read and understand your code.

I am not a Python programmer, so it’s difficult for me to make anything more than general comments on your code. However, if I’m reading your question correctly it is not deploying the code to the balenaCloud application? Have you tried looking at the application’s releases page to see if a new release is being created? Perhaps the application’s release strategy is not track?


Thank you!
However, if I’m reading your question correctly it is not deploying the code to the balenaCloud application?
Yes, if I deploy an image on balena board then I have to expect to get a release tag which am I not, so I am not able to verify if my image was deployed to the local device on balena. The application is under development mode.

the one under production mode. Have the release tag

but the one I am working is under development mode

Hi Layla. The reason your device is not pulling the code you pushed is because it is in development mode. The development mode tells the device to stop listening to the API and fleet wide releases and instead expects to get pushes from balena push <device_ip> on the local network. You can read more about local mode here: . If you want to make your device get the new release you pushed fleet wide, you just need to disable local mode on that device.

Thank you Shaun:
Yes, I realize that the reason Im not able to push the image is because as you mentioned we are in the development mode. Please allow me to explain what is the focus of my work. What am trying to do is I want to login to the dockerhub, pull a specific image with the latest tag, and deploy that image to my local device on balena board. You mentioned that I need to use balena push but I need to push this specific image, so I need to include that image_name. I better say that we want to deploy/push the pre-build image to our local device on balenaboard. Is this possible?

thank you


If I use balena push or balena push local.shortUUID, I also need to pass the image that I have been pulled from docker. Is there any way to do so.

thank you

I forgot to mention that I want to buy balena build server. I just want to push that specific image to my local device on my balena board


Building locally and pushing the image to local mode devices is, unfortunately, not yet supported. For reference, see: It is possible to build locally and push to the cloud however, with balena deploy and balena-build.

A possible workaround is to use balena push with the local mode device (note that in that case you use the IP or .local domain of the device). In this case, the container will be built in the device itself.