-
Notifications
You must be signed in to change notification settings - Fork 113
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
Add support of output image timestamp modification in image processing #1509
Conversation
func getAnnotation() []string { | ||
var annotation []string | ||
|
||
if flagValues.annotation != nil { | ||
return append(annotation, *flagValues.annotation...) | ||
} | ||
|
||
return annotation | ||
} | ||
|
||
func getLabel() []string { | ||
var label []string | ||
|
||
if flagValues.label != nil { | ||
return append(label, *flagValues.label...) | ||
} | ||
|
||
return label | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplifying the flag usage meant that these became obsolete.
pflag.StringArrayVar(&flagValues.annotation, "annotation", nil, "New annotations to add") | ||
pflag.StringArrayVar(&flagValues.label, "label", nil, "New labels to add") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to unify the style with the other flags
@@ -179,6 +201,8 @@ func runImageProcessing(ctx context.Context) error { | |||
return err | |||
} | |||
|
|||
log.Printf("Image %s@%s pushed\n", imageName.String(), digest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only to allow for better time tracking in the user logs.
}) | ||
|
||
It("should fail in case --image does not exist", func() { | ||
Expect(run( | ||
"--image", "docker.io/feqlQoDIHc/bcfHFHHXYF", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name in the use case was actually invalid.
}) | ||
|
||
It("should fail in case annotation is invalid", func() { | ||
withTestImage(func(tag name.Tag) { | ||
Expect(run( | ||
"--insecure", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug in the test cases actually, the test case did not test what was intended to test.
"--image", tag.String(), | ||
"--annotation", "org.opencontainers.image.url*https://my-company.com/images", | ||
)).To(HaveOccurred()) | ||
)).To(FailWith("not enough parts")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to error text matching in order to avoid not checking for that actual problem in the tests.
|
||
// there is no mutate.ReplaceManifests, therefore, remove the old one first, and then add the new one | ||
imageIndex = mutate.RemoveManifests(imageIndex, func(desc containerreg.Descriptor) bool { | ||
return desc.Digest.String() == digest.String() | ||
}) | ||
|
||
imageIndex = mutate.AppendManifests(imageIndex, mutate.IndexAddendum{ | ||
Add: appendable, | ||
Descriptor: containerreg.Descriptor{ | ||
Annotations: descriptor.Annotations, | ||
MediaType: descriptor.MediaType, | ||
Platform: descriptor.Platform, | ||
URLs: descriptor.URLs, | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was moved into replaceManifestIn
.
3d74db0
to
201369b
Compare
Expect(annotationsOf(image)).To(HaveKeyWithValue("org.opencontainers.image.url", "https://my-company.com/images")) | ||
Expect(labelsOf(image)).To(HaveKeyWithValue("maintainer", "[email protected]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to timestamp work, but file needed to touched anyway and this should serve to have a common style and to be more readable.
67f24e8
to
167305e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding some initial feedback, pls take a look.
Simplify the `--annotation` and `--label` flag setup.
Ref: https://github.com/shipwright-io/community/blob/main/ships/0037-build-output-timestamp.md Add optional output image timestamp field to allow for setting a custom image creation timestamp.
Add command-line flag `--image-timestamp` to update the image creation timestamp of the image when using shipwright-managed push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs need to be improved, per the significance of this feature. Please take a look at my comments
@@ -89,6 +89,11 @@ The `Build` definition supports the following fields: | |||
- `spec.timeout` - Defines a custom timeout. The value needs to be parsable by [ParseDuration](https://golang.org/pkg/time/#ParseDuration), for example, `5m`. The default is ten minutes. You can overwrite the value in the `BuildRun`. | |||
- `spec.output.annotations` - Refers to a list of `key/value` that could be used to [annotate](https://github.com/opencontainers/image-spec/blob/main/annotations.md) the output image. | |||
- `spec.output.labels` - Refers to a list of `key/value` that could be used to label the output image. | |||
- `spec.output.timestamp` - Instruct the build to change the output image creation timestamp to the specified value. When omitted, the respective build strategy tool defines the output image timestamp. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should also extend https://github.com/shipwright-io/build/blob/main/docs/build.md#defining-the-output and provide some precise samples on this feature? e.g. with yaml
In addition, why not to document it as well in https://github.com/shipwright-io/build/blob/main/docs/buildrun.md , at the end is also part of a BuildRun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon double checking the docs, I realized we missed a couple of reasons in the table.
Introduce functions to mutate timestamp of an image or image index. Extend image-processing step to include required timestamp values based on the configured Build or BuildRun output settings. Add test E2E cases for timestamp values for: - Zero - SourceTimestamp - BuildTimestamp - custom timestamp
Add missing timestamp related reason fields and descriptions. Introduce consistent use of the **Note** keyword in the text. Format all tables to have the same style. Fix broken links in the table of content. Join lines to have a consistent line break style. Remove unncessary whitespaces in text. Add missing reasons in build validation table. Signed-off-by: Matthias Diester <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: qu1queee The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
Implementation for SHIP 0037: build output timestamp
Main changes:
Fixes #1447
Submitter Checklist
See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.
Release Notes