Accessing OpenBalena registry

I’m hoping someone can help me as I’m in a bit of a pickle.

I’m returning to my OpenBalena project after some time away and I’ve lost all my local docker build images and materials.

Is there a way for me to retrieve images from the OpenBalena registry to my local client? I’ve tried using Postman and curl to get tokens from the api service but this still results in an “unauthorized” when I try to get https://registry.mydomin.com/v2/_catalog.

I think I need to use the hashes stored in the registry container but I have no way to link these to a human readable app name, is that where redis comes in?

The API will never grant access to _catalog, and you don’t need it really. You can find what images are available and their names by querying the image resource on the API.

Why do you need the built artifacts back? Don’t you have the Dockerfiles around? You can retrieve those as well if you don’t, they’re too stored along with the image name on the image resource.

Ah, I see. Yes, I need the Docker files too so it will be great if I can recover them as well.

I’ll give it a crack later on today, thanks for the advice.

Is there an API document anywhere I can reference?

I’m looking through the source and I can get some resources to give me a response but not others, e.g.

https://api.mydomain.com/device-types/v1” gives me a list of all the supported device types, however,

“https:/api.mydomain.com/image” gives me a “Cannot GET /image” error.

I understand this is because /image as a resource doesn’t exist, I just don’t know how to find out how to build the correct URL.

Any help greatly appreciated.

Hi @bighair,

Yes, we have an API resource reference here: https://www.balena.io/docs/reference/api/resources/release/

This allows you to see the various resources that can be accessed by the API. Another source that might help you are the balena Node SDK and the balena Python SDK.

Hope this helps!

Hi, I’m trying to get a list of images in the balena register. I can see a list of images accesing https://api.mydomain.com/v5/image, but the information provided in the response is not enough to identify each image. I would like to access the information on the registry, such as image tags and Dockerfile (many of them are images pulled from Docker Hub). It would be great to know how to query the registry directly!

Also, I see different images with different is_stored_at__image_location property but exactly the same content_hash, is this normal?

Thanks in advance for the help!

There’s no way to inspect the registry – the API is what authorizes access to images on the registry and it does so by inspecting is_stored_at__image_location on the image resource. In other words, you can only access the images the API knows about.

You get an access token from the API for a particular set of images and the registry will happily allow you to query their manifests and/or pull them locally in order to inspect.

Also, I see different images with different is_stored_at__image_location property but exactly the same content_hash , is this normal?

Yes, this is normal. What is your concern?

Thanks for your reply. Could you elaborate on how to get an access token from the API? I don’t see it in the documentation.

My concern regarding the different image locations for the same content hash is that it might indicate I’m storing the same images multiple times. Depending on the size of the images, this could be a problem in the future. Is there any way to delete old images which are not in use?

Thanks again!

Could you elaborate on how to get an access token from the API?

This document describes how to get a token. You’ll need to replace a few domains with appropriate values. If in doubt, issue a random HTTP request to the registry and the response headers will contain the appropriate values. I believe this has been discussed before, so searching this forum is a good idea as it might yield more general answers and perhaps code snippets you can reuse.

My concern regarding the different image locations for the same content hash is that it might indicate I’m storing the same images multiple times. Depending on the size of the images, this could be a problem in the future.

The idea behind content hash is to avoid exactly this – ie. storing the same blobs multiple times. See this blog post for context (sorry, couldn’t find any authoritative documents in Docker’s doc pages).

Is there any way to delete old images which are not in use?

Not currently.

Perfect! Thanks for your help!

Just in case anybody else gets here, this is working for me:

Get Registry Token:

TOKEN=`curl -H "Authorization: Bearer $BALENA_TOKEN" "https://api.domain.com/auth/v1/token?service=registry.domain.com&scope=repository:v2/33784462c2bb21b7833a13310855ea07:pull\" | jq .token | tr -d \"`

Get Image Tags:

curl -H "Authorization: Bearer $TOKEN" https://registry.domain.com/v2/v2/33784462c2bb21b7833a13310855ea07/tags/list

Result:

{"name":"v2/33784462c2bb21b7833a13310855ea07","tags":["latest"]}