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

Add support of output image timestamp modification in image processing #1509

Merged
merged 5 commits into from
Mar 12, 2024

Conversation

HeavyWombat
Copy link
Contributor

Changes

Implementation for SHIP 0037: build output timestamp

Main changes:

  • image processing CLI now supports two more command-line flags to set the image timestamp of an image or index.
  • API for Build Output was extended to include a string that defines what kind of timestamp modification is suppose to be done
  • TaskRun setup was extended to properly setup the build settings to invoke the image processing with the respective settings

Fixes #1447

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.

Release Notes

Output image section now supports an optional timestamp field, which can be used to change the image creation timestamp, i.e. use string "SourceTimestamp" to let the output image creation timestamp to be modified to the timestamp of the source timestamp.

@openshift-ci openshift-ci bot added the release-note Label for when a PR has specified a release note label Feb 28, 2024
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 28, 2024
@HeavyWombat HeavyWombat changed the title Issue/1447 Add support of output image timestamp modification in image processing Feb 28, 2024
Comment on lines -48 to -67
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
}

Copy link
Contributor Author

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.

Comment on lines +65 to +66
pflag.StringArrayVar(&flagValues.annotation, "annotation", nil, "New annotations to add")
pflag.StringArrayVar(&flagValues.label, "label", nil, "New labels to add")
Copy link
Contributor Author

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)
Copy link
Contributor Author

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",
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 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",
Copy link
Contributor Author

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"))
Copy link
Contributor Author

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.

Comment on lines -55 to -69

// 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,
},
})
Copy link
Contributor Author

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.

Comment on lines +93 to +94
Expect(annotationsOf(image)).To(HaveKeyWithValue("org.opencontainers.image.url", "https://my-company.com/images"))
Expect(labelsOf(image)).To(HaveKeyWithValue("maintainer", "[email protected]"))
Copy link
Contributor Author

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.

@HeavyWombat HeavyWombat force-pushed the issue/1447 branch 2 times, most recently from 67f24e8 to 167305e Compare March 1, 2024 08:34
Copy link
Contributor

@qu1queee qu1queee left a 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.

docs/build.md Outdated Show resolved Hide resolved
pkg/apis/build/v1beta1/build_types.go Outdated Show resolved Hide resolved
pkg/reconciler/build/build_test.go Outdated Show resolved Hide resolved
pkg/validate/output.go Outdated Show resolved Hide resolved
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.
Copy link
Contributor

@qu1queee qu1queee left a 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

pkg/reconciler/buildrun/resources/taskrun.go Outdated Show resolved Hide resolved
@@ -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.
Copy link
Contributor

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.

Copy link
Contributor Author

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]>
@qu1queee qu1queee self-requested a review March 12, 2024 09:38
Copy link
Contributor

@qu1queee qu1queee left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 12, 2024
Copy link
Contributor

openshift-ci bot commented Mar 12, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 12, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit e1329cc into main Mar 12, 2024
14 checks passed
@openshift-merge-bot openshift-merge-bot bot deleted the issue/1447 branch March 12, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note Label for when a PR has specified a release note size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Mutate image time in image-processing based on configured preferences
2 participants