diff --git a/deploy/crds/shipwright.io_buildruns.yaml b/deploy/crds/shipwright.io_buildruns.yaml index 1725b332e8..7306e6b203 100644 --- a/deploy/crds/shipwright.io_buildruns.yaml +++ b/deploy/crds/shipwright.io_buildruns.yaml @@ -114,6 +114,15 @@ spec: description: Labels references the additional labels to be applied on the image type: object + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC + on 1 January 1970 - "SourceTimestamp", to set the source + timestamp dereived from the input source - "BuildTimestamp", + to set the timestamp of the current build itself - Parsable + integer number defined as the epoch seconds - or nil/empty + to not set any specific timestamp' + type: string required: - image type: object @@ -272,6 +281,15 @@ spec: description: Labels references the additional labels to be applied on the image type: object + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC + on 1 January 1970 - "SourceTimestamp", to set the source + timestamp dereived from the input source - "BuildTimestamp", + to set the timestamp of the current build itself - Parsable + integer number defined as the epoch seconds - or nil/empty + to not set any specific timestamp' + type: string required: - image type: object @@ -2352,6 +2370,15 @@ spec: description: Labels references the additional labels to be applied on the image type: object + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC on + 1 January 1970 - "SourceTimestamp", to set the source timestamp + dereived from the input source - "BuildTimestamp", to set the + timestamp of the current build itself - Parsable integer number + defined as the epoch seconds - or nil/empty to not set any specific + timestamp' + type: string required: - image type: object @@ -4125,6 +4152,15 @@ spec: description: Labels references the additional labels to be applied on the image type: object + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC + on 1 January 1970 - "SourceTimestamp", to set the source + timestamp dereived from the input source - "BuildTimestamp", + to set the timestamp of the current build itself - Parsable + integer number defined as the epoch seconds - or nil/empty + to not set any specific timestamp' + type: string required: - image type: object @@ -4283,6 +4319,15 @@ spec: description: Labels references the additional labels to be applied on the image type: object + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC + on 1 January 1970 - "SourceTimestamp", to set the source + timestamp dereived from the input source - "BuildTimestamp", + to set the timestamp of the current build itself - Parsable + integer number defined as the epoch seconds - or nil/empty + to not set any specific timestamp' + type: string required: - image type: object @@ -6552,6 +6597,16 @@ spec: description: Describes the secret name for pushing a container image. type: string + timestamp: + description: 'Timestamp references the optional image + timestamp to be set, valid values are: - "Zero", to + set 00:00:00 UTC on 1 January 1970 - "SourceTimestamp", + to set the source timestamp dereived from the input + source - "BuildTimestamp", to set the timestamp of the + current build itself - Parsable integer number defined + as the epoch seconds - or nil/empty to not set any specific + timestamp' + type: string required: - image type: object @@ -8691,6 +8746,15 @@ spec: description: Describes the secret name for pushing a container image. type: string + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC on + 1 January 1970 - "SourceTimestamp", to set the source timestamp + dereived from the input source - "BuildTimestamp", to set the + timestamp of the current build itself - Parsable integer number + defined as the epoch seconds - or nil/empty to not set any specific + timestamp' + type: string required: - image type: object @@ -10556,6 +10620,15 @@ spec: description: Describes the secret name for pushing a container image. type: string + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC + on 1 January 1970 - "SourceTimestamp", to set the source + timestamp dereived from the input source - "BuildTimestamp", + to set the timestamp of the current build itself - Parsable + integer number defined as the epoch seconds - or nil/empty + to not set any specific timestamp' + type: string required: - image type: object diff --git a/deploy/crds/shipwright.io_builds.yaml b/deploy/crds/shipwright.io_builds.yaml index c3ca0df34c..9f3dc63e82 100644 --- a/deploy/crds/shipwright.io_builds.yaml +++ b/deploy/crds/shipwright.io_builds.yaml @@ -100,6 +100,15 @@ spec: description: Labels references the additional labels to be applied on the image type: object + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC on + 1 January 1970 - "SourceTimestamp", to set the source timestamp + dereived from the input source - "BuildTimestamp", to set the + timestamp of the current build itself - Parsable integer number + defined as the epoch seconds - or nil/empty to not set any specific + timestamp' + type: string required: - image type: object @@ -252,6 +261,15 @@ spec: description: Labels references the additional labels to be applied on the image type: object + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC on + 1 January 1970 - "SourceTimestamp", to set the source timestamp + dereived from the input source - "BuildTimestamp", to set the + timestamp of the current build itself - Parsable integer number + defined as the epoch seconds - or nil/empty to not set any specific + timestamp' + type: string required: - image type: object @@ -2324,6 +2342,15 @@ spec: description: Describes the secret name for pushing a container image. type: string + timestamp: + description: 'Timestamp references the optional image timestamp + to be set, valid values are: - "Zero", to set 00:00:00 UTC on + 1 January 1970 - "SourceTimestamp", to set the source timestamp + dereived from the input source - "BuildTimestamp", to set the + timestamp of the current build itself - Parsable integer number + defined as the epoch seconds - or nil/empty to not set any specific + timestamp' + type: string required: - image type: object diff --git a/docs/build.md b/docs/build.md index f2b87c1a5c..20cacbd4f0 100644 --- a/docs/build.md +++ b/docs/build.md @@ -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. + - Use string `Zero` to set the image timestamp to UNIX epoch timestamp zero. + - Use string `SourceTimestamp` to set the image timestamp to the source timestamp, i.e. the timestamp of the Git commit that was used. + - Use string `BuildTimestamp` to set the image timestamp to the timestamp of the build run. + - Use any valid UNIX epoch seconds number as a string to set this as the image timestamp. - `spec.env` - Specifies additional environment variables that should be passed to the build container. The available variables depend on the tool that is being used by the chosen build strategy. - `spec.retention.atBuildDeletion` - Defines if all related BuildRuns needs to be deleted when deleting the Build. The default is false. - `spec.retention.ttlAfterFailed` - Specifies the duration for which a failed buildrun can exist. diff --git a/pkg/apis/build/v1alpha1/build_types.go b/pkg/apis/build/v1alpha1/build_types.go index 8023c71f32..4b10b12223 100644 --- a/pkg/apis/build/v1alpha1/build_types.go +++ b/pkg/apis/build/v1alpha1/build_types.go @@ -233,6 +233,16 @@ type Image struct { // // +optional Labels map[string]string `json:"labels,omitempty"` + + // Timestamp references the optional image timestamp to be set, valid values are: + // - "Zero", to set 00:00:00 UTC on 1 January 1970 + // - "SourceTimestamp", to set the source timestamp dereived from the input source + // - "BuildTimestamp", to set the timestamp of the current build itself + // - Parsable integer number defined as the epoch seconds + // - or nil/empty to not set any specific timestamp + // + // +optional + Timestamp *string `json:"timestamp,omitempty"` } // BuildStatus defines the observed state of Build diff --git a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go index c36175df27..58ce75daff 100644 --- a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go @@ -904,6 +904,11 @@ func (in *Image) DeepCopyInto(out *Image) { (*out)[key] = val } } + if in.Timestamp != nil { + in, out := &in.Timestamp, &out.Timestamp + *out = new(string) + **out = **in + } return } diff --git a/pkg/apis/build/v1beta1/build_conversion.go b/pkg/apis/build/v1beta1/build_conversion.go index be06a55a06..55a0b98fb2 100644 --- a/pkg/apis/build/v1beta1/build_conversion.go +++ b/pkg/apis/build/v1beta1/build_conversion.go @@ -196,6 +196,7 @@ func (dest *BuildSpec) ConvertFrom(orig *v1alpha1.BuildSpec) error { dest.Output.Annotations = orig.Output.Annotations dest.Output.Labels = orig.Output.Labels + dest.Output.Timestamp = orig.Output.Timestamp // Handle BuildSpec Timeout dest.Timeout = orig.Timeout @@ -288,6 +289,7 @@ func (dest *BuildSpec) ConvertTo(bs *v1alpha1.BuildSpec) error { } bs.Output.Annotations = dest.Output.Annotations bs.Output.Labels = dest.Output.Labels + bs.Output.Timestamp = dest.Output.Timestamp // Handle BuildSpec Timeout bs.Timeout = dest.Timeout diff --git a/pkg/apis/build/v1beta1/build_types.go b/pkg/apis/build/v1beta1/build_types.go index 0d233f0c50..5231835608 100644 --- a/pkg/apis/build/v1beta1/build_types.go +++ b/pkg/apis/build/v1beta1/build_types.go @@ -200,6 +200,16 @@ type Image struct { // // +optional Labels map[string]string `json:"labels,omitempty"` + + // Timestamp references the optional image timestamp to be set, valid values are: + // - "Zero", to set 00:00:00 UTC on 1 January 1970 + // - "SourceTimestamp", to set the source timestamp dereived from the input source + // - "BuildTimestamp", to set the timestamp of the current build itself + // - Parsable integer number defined as the epoch seconds + // - or nil/empty to not set any specific timestamp + // + // +optional + Timestamp *string `json:"timestamp,omitempty"` } // BuildStatus defines the observed state of Build diff --git a/pkg/apis/build/v1beta1/zz_generated.deepcopy.go b/pkg/apis/build/v1beta1/zz_generated.deepcopy.go index 689cbcfe67..9c1ce78f6b 100644 --- a/pkg/apis/build/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/build/v1beta1/zz_generated.deepcopy.go @@ -808,6 +808,11 @@ func (in *Image) DeepCopyInto(out *Image) { (*out)[key] = val } } + if in.Timestamp != nil { + in, out := &in.Timestamp, &out.Timestamp + *out = new(string) + **out = **in + } return }