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

Make multi-type annotation settings match docs #2522

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

treuherz
Copy link
Contributor

The Docker docs in multiple places describe passing an annotation at the command line like "index,manifest:com.example.name=my-cool-image", and say that this will result in the annotation being applied to both the index and the manifest. It doesn't seem like this was actually implemented, and instead it just results in an annotation key with "index,manifest:" at the beginning being applied to the manifest.

This change splits the part of the key before the colon by comma, and creates an annotation for each type/platform given, so the implementation should now match the docs.

@treuherz
Copy link
Contributor Author

I get the same test failures locally with and without this change - I think these must be my setup rather than an actual problem. Hopefully the validation will be green but I'll mark as draft again if not.

@treuherz treuherz marked this pull request as ready for review June 13, 2024 09:55
@treuherz
Copy link
Contributor Author

A dep changed from // indirect to direct - fixed, re-run vendor etc. Sorry about that


for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, gotErr := ParseAnnotations(test.in)
Copy link
Member

Choose a reason for hiding this comment

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

s/gotErr/err/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if test.wantErr != "" {
require.ErrorContains(t, gotErr, test.wantErr)
} else {
assert.NoError(t, gotErr)
Copy link
Member

Choose a reason for hiding this comment

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

NoError should use require

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -81,7 +81,8 @@ func ParseExports(inp []string) ([]*controllerapi.ExportEntry, error) {

func ParseAnnotations(inp []string) (map[exptypes.AnnotationKey]string, error) {
// TODO: use buildkit's annotation parser once it supports setting custom prefix and ":" separator
annotationRegexp := regexp.MustCompile(`^(?:([a-z-]+)(?:\[([A-Za-z0-9_/-]+)\])?:)?(\S+)$`)
annotationRegexp := regexp.MustCompile(`^((?:[a-z-]+(?:\[[A-Za-z0-9_/-]+\])?)(?:,[a-z-]+(?:\[[A-Za-z0-9_/-]+\])?)*:)?(\S+)$`)
Copy link
Member

Choose a reason for hiding this comment

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

This needs comments about why there are multiple and what's the difference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The regexp is pretty inscrutable, I might try breaking it up into cuts and splits and just using a smaller regexp for pulling out the platform specifier, if it’s all the same to you

slices.SortFunc(wantKVs, sortFunc)
slices.SortFunc(gotKVs, sortFunc)

if diff := gocmp.Diff(wantKVs, gotKVs); diff != "" {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just use assert.Equal in here. No need for gocmp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

assert.NoError(t, gotErr)
}

// Can't compare maps with pointer in their keys, need to extract and sort the map entries
Copy link
Member

Choose a reason for hiding this comment

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

might make sense to make this covert code into a function and then convert both maps. Atm there is duplication where exactly the same commands need to run on both maps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@tonistiigi tonistiigi requested a review from jedevc June 15, 2024 02:32
The Docker docs in multiple places describe passing an annotation at the
command line like "index,manifest:com.example.name=my-cool-image", and
say that this will result in the annotation being applied to both the
index and the manifest. It doesn't seem like this was actually
implemented, and instead it just results in an annotation key with
"index,manifest:" at the beginning being applied to the manifest.

This change splits the part of the key before the colon by comma, and
creates an annotation for each type/platform given, so the
implementation should now match the docs.

Signed-off-by: Eli Treuherz <[email protected]>
Signed-off-by: Eli Treuherz <[email protected]>
@tonistiigi tonistiigi added this to the v0.16.0 milestone Jun 25, 2024
@tonistiigi tonistiigi merged commit 8180454 into docker:master Jun 26, 2024
102 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants