Use case for deprecated balena build -B

Hello,

Context: build image for a multi-container project.

I haven’t find an alternative to use balena build -B in my use case, so I would like to share it with you as mentionned in the warning message :slight_smile:

Basically I want to pass an NPM_TOKEN to my Dockerfile. I tried to use the “build secrets” feature but it only works on balena-engine. When I use balena build locally on my Mac to build the docker image I cannot build it using secrets.

I plan to use balena build in our CI to build and push images in our Docker registry for our components. If this feature works only in balena-engine, I cannot use it and I have to fallback to a build arg.

Unless there is a way to use balena build with remote Belena builders, but pushing to a custom registry after building ?

Hi,

Build args using the -B / --buildArg flag is deprecated and the recommended method for passing tokens during image build is to use build secrets, per this link: Deploy to your fleet - Balena Documentation

However, I understand that this only works for balena push. I’ve attached a pattern for adding this feature to balena build as well. In the meantime, as a workaround, could you invoke balena push, then pull the built image from the balena registry then push it to your docker registry? You can find the URL for the image location using the following Node SDK call (which can be translated into an API call):

await sdk.pine.get({
    resource:'image',
    options: {
        $select: ['id', 'is_stored_at__image_location'],
        $filter: {
            is_part_of__release: {
                release: YOUR_RELEASE_ID
            }
        }
    }
})

Let us know if you’d like further help with this workaround!

Regards,
Christina

Thanks for your answer !

Unfortunately it’s not possible for me to use balena push because when I build one image I’m not in the repository containing the docker-compose file. Also, pushing means creating a realease, which I don’t want at this step.

Here is my setup :

  • Multiple Git repositories: one per docker container running on my device
  • Every repository has its own CI in charge of building the image (using balena build)
  • When I want to release a new version, I run balena push which uses existing built images.

I don’t think I can do this without using -B until secrets are supported in balena build.