Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access the built image sha #49

Open
dhensby opened this issue Mar 1, 2024 · 14 comments
Open

How to access the built image sha #49

dhensby opened this issue Mar 1, 2024 · 14 comments
Labels
feature request question Further information is requested

Comments

@dhensby
Copy link

dhensby commented Mar 1, 2024

I'm looking at implementing docker image signing as part of our release process. To do this, ideally we'd have access to the sha of the built image. Is there any way to expose this value so that it can be used in an exec step or similar?

@esatterwhite
Copy link
Owner

esatterwhite commented Mar 13, 2024

@dhensby
Currently, I don't think so. I don't think its possible to pass information between stages, or at least it isn't a documented/supported feature of semantic-release.

How would you want to use this? an example would be helpful.

@esatterwhite esatterwhite added the question Further information is requested label Mar 13, 2024
@dhensby
Copy link
Author

dhensby commented Mar 13, 2024

So using something like notion you (ideally) want to get your hands on the raw image sha for signing. It's not much more than: notation sign --signature-format cose $IMAGE (where $IMAGE is image@sha:xxxx see: https://notaryproject.dev/docs/quickstart-guides/quickstart-sign-image-artifact/)

The issue is that builds don't seem to have a predictable tag nor a way to get your hand on it so you can resolve the hash locally.

Though, looking at the code - perhaps if I can set build_id, instead of it being random, the local tag will be predictable and I'll be able to find the image 🤔

@dhensby
Copy link
Author

dhensby commented Mar 13, 2024

If there was a way to set this build_id deterministically at run time, then I'd be able to run: docker images --no-trunc --quiet "image-name:${build_id}" to get the hash

@esatterwhite
Copy link
Owner

If there was a way to set this build_id deterministically at run time, then I'd be able to run: docker images --no-trunc --quiet "image-name:${build_id}" to get the hash

Not currently, but it wouldn't be difficult to add.

Also, and I'll have to confirm, but I might just be able to mutate the nextRelease object with the docker build info. Then you could reference it other states / plugins provided they support templating of some kind

@esatterwhite
Copy link
Owner

Additionally as I'm working through it now, I'm not sure that would work if you were using buildx as the build + push happen in the same docker command and the images are not stored locally.

it may not effect you, but something to think about.

@dhensby
Copy link
Author

dhensby commented Mar 13, 2024

The images are available locally if the clean flag is set to false, right? 🤔

@esatterwhite
Copy link
Owner

esatterwhite commented Mar 13, 2024

This images are available locally if the clean flag is set to false, right? 🤔

Yes.
I'm talking in a future state, if you were to start building multi-arch images w/ buildx ( a thing I'm working on now ), that would not be the case.

So nothing to worry about here, I'm just thinking out loud.

@Th3S4mur41
Copy link

Looking for something similar in order to take advantage of actions/attest-build-provenance in GitHub CI.

Right now, this seems only to be possible by publishing the docker image using docker/build-push-action after semantic-release.

@esatterwhite
Copy link
Owner

How would you expect to get access to it?

@esatterwhite
Copy link
Owner

The final image sha, or the tag of an image?

@dhensby
Copy link
Author

dhensby commented Sep 2, 2024

The signing programs can complain if you don't give the actual image sha, so that would be idea.

@Th3S4mur41
Copy link

How would you expect to get access to it?

I'm not sure either...
In order to get the version, I extract it from the package.json and add it as an output parameter for the CI job.

echo "version=$(npm run env | grep npm_package_version | cut -d '=' -f 2)" >> $GITHUB_OUTPUT

I can then reuse the new version in any of the following jobs.
If there is any way I could access the sha of the published image, I could do something similar

@dhensby
Copy link
Author

dhensby commented Sep 3, 2024

At the moment I use the exec provider for semantic release to add the release version as an output:

  - ['@semantic-release/exec', {
      "publishCmd": 'echo "version=${nextRelease.version}" >> "$GITHUB_OUTPUT"'
    }]

Then I use that version to do the signing with notation: ./notation sign --signature-format cose --id "$CERT_ID" --plugin azure-kv --plugin-config self_signed=true "$IMAGE"

Where $IMAGE is and env var constructed as so: dockerhost.com/image-name:${{ steps.release.outputs.version }}


Edit (for clarity): This causes notation to complain because it wants a sha instead - and that's what I'd like to be able to get my hands on somehow even if it means another exec call that just adds the image sha to the output.

@esatterwhite
Copy link
Owner

Ah, I see. Thanks, that helps. I think mutating the release object could work. Provided semantic release isn't re-creating it for each plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants