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

Infer predefined annotations when pushing to registry #2618

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

itowlson
Copy link
Contributor

@itowlson itowlson commented Jul 9, 2024

Fixes #2612 (or at least part of it).

I'm not sure the best way to test this in CI, but trying it locally it seems promising:

# Manifest for testing
ivan@hestia:~/testing$ cat v2vanillareallyv2/spin.toml
spin_manifest_version = 2

[application]
name = "v2vanillareallyv2"
version = "0.1.0"
authors = ["itowlson <ivan.towlson@fermyon.com>"]
description = ""
# moar TOML

# If the user doesn't set any of the predefined annotations
ivan@hestia:~/testing$ spin registry push localhost:5000/vanilla:v0.1 -f v2vanillareallyv2/ --insecure
Pushing app to the Registry..
Pushed with digest sha256:9110a84446a12c3479978316e2343e60bda6d5375ff39fb0ef0f77759d7d1011

# ...then they are inferred (formatting added for legibility)
ivan@hestia:~/testing$ docker buildx imagetools inspect localhost:5000/vanilla:v0.1 --raw
{"annotations":{
  "org.opencontainers.image.authors":"itowlson <ivan.towlson@fermyon.com>",
  "org.opencontainers.image.created":"2024-07-09T01:33:37.290049791+00:00",
  "org.opencontainers.image.title":"v2vanillareallyv2",
  "org.opencontainers.image.version":"0.1.0"
},
# moar JSON
}

# But if the user specifies, say, the `authors` annotation...
ivan@hestia:~/testing$ spin registry push localhost:5000/vanilla:v0.2 -f v2vanillareallyv2/ --insecure --annotation org.opencontainers.image.authors="THE GREAT OZ"
Pushing app to the Registry..
Pushed with digest sha256:63420c721dbb51261c0c3af18cded3b6ef81d8fc65c820be535500f27cb4285e

# ...then we do not infer it but respect the one we are given (formatting added for legibility)
ivan@hestia:~/testing$ docker buildx imagetools inspect localhost:5000/vanilla:v0.2 --raw
{"annotations":{
  "org.opencontainers.image.authors":"THE GREAT OZ",
  "org.opencontainers.image.created":"2024-07-09T01:36:01.402920121+00:00",
  "org.opencontainers.image.title":"v2vanillareallyv2",
  "org.opencontainers.image.version":"0.1.0"
},
# moar JSON
}

The OCI authors annotation is a string, whereas Spin allows an array: the PR comma-space-concatenates them, e.g. "The Great Oz, Dorothy Gale". OCI describes the field as a freeform string but if there's a common community convention then I can adopt that.

This PR does not provide a way for a user to suppress inference but the infrastructure is there in case we want to add an option, or for programmatic use (e.g. reproducibility).

@itowlson itowlson requested a review from vdice July 9, 2024 01:52
@itowlson itowlson linked an issue Jul 9, 2024 that may be closed by this pull request
@itowlson
Copy link
Contributor Author

itowlson commented Jul 9, 2024

Also linked #2259

@@ -136,14 +148,15 @@ impl Client {
locked: LockedApp,
reference: impl AsRef<str>,
annotations: Option<BTreeMap<String, String>>,
predefined_annotations: PredefinedAnnotations,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that annotations is an option of a map and predefined_annotations is an enum is somewhat confusing here; how much of this behavior is an external consumer of this API supposed to understand?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radu-matei I am gazing at this and struggling to think of a better design. I don't want to put it on consumers to construct the predefined annotations, so it shouldn't be a map. So I am having difficulty getting away from the "I want the predefined annotations or I don't" flag. I would value suggestions. Or is it as simple as "we should rename the flag to infer_predefined_annotations or something, so it sounds like an action instead of a set" perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radu-matei I tried some renaming - if that doesn't improve matters then I'd value suggestions - thanks!

&app_file,
&self.reference,
annotations,
PredefinedAnnotations::Infer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the behavior here is: always infer, and if the user provided any annotation explicitly, it takes priority over the inferred value??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user provides one of the annotations that would be inferred explicitly, then the explicit value takes precedence - see the comment on the enum.

Copy link
Member

@vdice vdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks Ivan!

crates/oci/src/client.rs Outdated Show resolved Hide resolved
crates/oci/src/client.rs Outdated Show resolved Hide resolved
crates/oci/src/client.rs Outdated Show resolved Hide resolved
@vdice
Copy link
Member

vdice commented Jul 9, 2024

OCI describes the field as a freeform string but if there's a common community convention then I can adopt that.

Not able to find a convention after a brief search. I think the comma-separated string as you've initially added seems a sane way to go for now.

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
Copy link
Member

@vdice vdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎸👨‍🎤 🔈 LGTM+11!

@itowlson itowlson merged commit 27c7edf into fermyon:main Jul 10, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants