balena-io-modules / balena-preload

Script for preloading containers onto balena device images
https://www.balena.io/
Apache License 2.0
35 stars 8 forks source link

openBalena: RequestError: Error: getaddrinfo ENOTFOUND registry2.xxx #236

Closed pdcastro closed 3 years ago

pdcastro commented 3 years ago

balena preload is forming the registry URL with: https://github.com/balena-io-modules/balena-preload/blob/v10.4.1/lib/preload.js#L518

url: `https://${this.balenaSettings.registry2Url}${endpoint}`,

... which currently resolves to registry2.xxx where xxx is the user's openBalena domain name (like mydomain.com). However, such a registry2 hostname does not exist in openBalena.

Putting aside the discussion of whether or not registry2.xxx should exist in openBalena, it was pointed out, I think correctly, that balena-preload should prefer extracting the registry URL from the image's name, rather than building the URL as in the code snippet above. In particular, I see this function:

https://github.com/balena-io-modules/balena-preload/blob/v10.4.1/lib/preload.js#L562-L571

    _imageManifestUrl(imageLocation) {
        // imageLocation: registry2.balena-cloud.com/v2/ad7cd3616b4e72ed51a5ad349e03715e@sha256:4c042f195b59b7d4c492e210ab29ab61694f490a69c65720a5a0121c6277ecdd
        const slashIndex = imageLocation.search('/');
        const atIndex = imageLocation.search('@');
        // 2 times v2: /v2/v2/.... this is expected
        return `/v2${imageLocation.substring(
            slashIndex,
            atIndex,
        )}/manifests/${imageLocation.substring(atIndex + 1)}`;
    }

... that already parses the imageLocation name that is supposed to have the "correct" registry domain name, which is being ignored in favour of this.balenaSettings.registry2Url. I think that function could be slightly modified to return the domain name as well.

jellyfish-bot commented 3 years ago

[pdcastro] This issue has attached support thread https://jel.ly.fish/19ffc301-2f91-48f2-b432-3c36ff3030ce

zvin commented 3 years ago

I think that function could be slightly modified to return the domain name as well.

This or another function, something like getRegistryDomain(imageLocation)