How do I get the "git hash" or release of an application from within a device service?

How do I get the “git hash” or release of an application from within a device service?

  • I see the release on the dashboard for the device.
  • application REST API has should_track_latest_release
  • device REST API has should_be_running__release
  • releases REST API has should_track_latest_release
  • I don’t see anything in the balena supervisor api

I don’t see an environment variable.

Hey the recommended way would be to call the following endpoint: https://www.balena.io/docs/reference/supervisor/supervisor-api/#get-v2applicationsstate

You would read the commit value from the returned state.

Thanks @CameronDiver – unfortunately the supervisor isn’t available immediately after boot. Assuming that we can’t make a network call, one option is to cache the git hash in persistent storage, but then it might be out of date.

Usually when building software binaries, the build system can fill in template values into a file that doesn’t belong to the repository. Perhaps the human readable version number is committed to the repository.

Are there any other offline, available at first boot, options for getting the commit hash.

Hey @jason10, you are correct about the supervisor not being available at first boot.

I really liked your build variable idea, and it ties in with some similar stuff that’s been on my radar for quite a while.

I’ve added this PR in a satellite module: https://github.com/balena-io-modules/resin-bundle-resolve/pull/43 which when merged will be integrated into the cloud builder and our CLI.

The eventual feature will provide the %%RELEASE_HASH%% template variable into Dockerfile.template parsing a resolution.

Will this solve things for you?

Hey @CameronDiver,

Totally! I could then do

ENV RELEASE_HASH=%%RELEASE_HASH%%

Or

RUN printf("#define RELEASE_HASH %s\n", %%RELEASE_HASH%%) >>version.h

Or other things. Looking forward to trying it out!

Hey @jason10

We just deployed a new version of the builder which supports 3 additional template variables:

%%BALENA_APP_NAME%%
%%BALENA_SERVICE_NAME%%
%%BALENA_RELEASE_HASH%%

Let me know how this works for you :slight_smile: I believe the documentation should be updated later today.
Thanks for the suggestion!

2 Likes