From e9b3b89d52d56350f34927098efa4e571a9f0b2c Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 20 Oct 2022 13:08:33 -0400 Subject: [PATCH] cmd-push-container-manifest: change image key schema The `oscontainer` and `base-oscontainer` keys should follow the same schema. Currently, the former has a `digest` field, while the other one does not. Tweak `cosa push-container-manifest` and `cosa push-container` so that they follows the new schema. (Though note the latter command will be deleted soon). To keep previous 4.12 `meta.json` files valid, this loosens the `image` schema definition so that `digest` is now optional. Once we branch for 4.12, we will undo this change so that it becomes required again. Fixes https://github.com/coreos/coreos-assembler/issues/3122 --- .../coreos-assembler/pkg/builds/cosa_v1.go | 16 +++--------- .../coreos-assembler/pkg/builds/schema_doc.go | 26 +++---------------- pkg/builds/cosa_v1.go | 16 +++--------- pkg/builds/schema_doc.go | 26 +++---------------- src/cmd-push-container | 5 +++- src/cmd-push-container-manifest | 5 +++- src/v1.json | 24 +++-------------- 7 files changed, 27 insertions(+), 91 deletions(-) diff --git a/mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/cosa_v1.go b/mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/cosa_v1.go index 752888a91f..30a7908aa5 100644 --- a/mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/cosa_v1.go +++ b/mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/cosa_v1.go @@ -1,7 +1,7 @@ package builds // generated by 'make schema' -// source hash: 3508b2f150e72b8e24151d870789809cf4070cec6b4716966a4e8bc585e0c5f1 +// source hash: 1e32ab25dfdd0724f8e8246008b9d91b88a40e9ea834cf779ab0da818bf1cf25 type AdvisoryDiff []AdvisoryDiffItems @@ -27,10 +27,6 @@ type Artifact struct { UncompressedSize int `json:"uncompressed-size,omitempty"` } -type BaseOsContainer struct { - Image string `json:"image"` -} - type Build struct { AdvisoryDiffAgainstParent AdvisoryDiff `json:"parent-advisories-diff,omitempty"` AdvisoryDiffBetweenBuilds AdvisoryDiff `json:"advisories-diff,omitempty"` @@ -38,7 +34,7 @@ type Build struct { Amis []Amis `json:"amis,omitempty"` Architecture string `json:"coreos-assembler.basearch,omitempty"` Azure *Cloudartifact `json:"azure,omitempty"` - BaseOsContainer *BaseOsContainer `json:"base-oscontainer,omitempty"` + BaseOsContainer *Image `json:"base-oscontainer,omitempty"` BuildArtifacts *BuildArtifacts `json:"images,omitempty"` BuildID string `json:"buildid"` BuildRef string `json:"ref,omitempty"` @@ -54,7 +50,7 @@ type Build struct { CosaImageChecksum string `json:"coreos-assembler.image-config-checksum,omitempty"` CosaImageVersion int `json:"coreos-assembler.image-genver,omitempty"` Extensions *Extensions `json:"extensions,omitempty"` - ExtensionsContainer *ExtensionsContainer `json:"extensions-container,omitempty"` + ExtensionsContainer *Image `json:"extensions-container,omitempty"` FedoraCoreOsParentCommit string `json:"fedora-coreos.parent-commit,omitempty"` FedoraCoreOsParentVersion string `json:"fedora-coreos.parent-version,omitempty"` Gcp *Gcp `json:"gcp,omitempty"` @@ -134,10 +130,6 @@ type Extensions struct { Sha256 string `json:"sha256"` } -type ExtensionsContainer struct { - Image string `json:"image"` -} - type Gcp struct { ImageFamily string `json:"family,omitempty"` ImageName string `json:"image"` @@ -154,7 +146,7 @@ type Git struct { type Image struct { Comment string `json:"comment,omitempty"` - Digest string `json:"digest"` + Digest string `json:"digest,omitempty"` Image string `json:"image"` } diff --git a/mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/schema_doc.go b/mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/schema_doc.go index 7c8f985691..936d80cc06 100644 --- a/mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/schema_doc.go +++ b/mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/schema_doc.go @@ -1,5 +1,5 @@ // Generated by ./generate-schema.sh -// Source hash: 3508b2f150e72b8e24151d870789809cf4070cec6b4716966a4e8bc585e0c5f1 +// Source hash: 1e32ab25dfdd0724f8e8246008b9d91b88a40e9ea834cf779ab0da818bf1cf25 // DO NOT EDIT package builds @@ -56,10 +56,10 @@ var generatedSchemaJSON = `{ "image": { "type": "object", "required": [ - "digest", "image" ], "optional": [ + "digest", "comment" ], "properties": { @@ -882,31 +882,13 @@ var generatedSchemaJSON = `{ "$id": "#/properties/base-oscontainer", "type": "object", "title": "Base OS container", - "required": [ - "image" - ], - "properties": { - "image": { - "$id": "#/properties/base-oscontainer/image", - "type": "string", - "title": "Image" - } - } + "$ref": "#/definitions/image" }, "extensions-container": { "$id": "#/properties/extensions-container", "type": "object", "title": "Extensions container", - "required": [ - "image" - ], - "properties": { - "image": { - "$id": "#/properties/extensions-container/image", - "type": "string", - "title": "Image" - } - } + "$ref": "#/definitions/image" }, "gcp": { "$id": "#/properties/gcp", diff --git a/pkg/builds/cosa_v1.go b/pkg/builds/cosa_v1.go index 752888a91f..30a7908aa5 100644 --- a/pkg/builds/cosa_v1.go +++ b/pkg/builds/cosa_v1.go @@ -1,7 +1,7 @@ package builds // generated by 'make schema' -// source hash: 3508b2f150e72b8e24151d870789809cf4070cec6b4716966a4e8bc585e0c5f1 +// source hash: 1e32ab25dfdd0724f8e8246008b9d91b88a40e9ea834cf779ab0da818bf1cf25 type AdvisoryDiff []AdvisoryDiffItems @@ -27,10 +27,6 @@ type Artifact struct { UncompressedSize int `json:"uncompressed-size,omitempty"` } -type BaseOsContainer struct { - Image string `json:"image"` -} - type Build struct { AdvisoryDiffAgainstParent AdvisoryDiff `json:"parent-advisories-diff,omitempty"` AdvisoryDiffBetweenBuilds AdvisoryDiff `json:"advisories-diff,omitempty"` @@ -38,7 +34,7 @@ type Build struct { Amis []Amis `json:"amis,omitempty"` Architecture string `json:"coreos-assembler.basearch,omitempty"` Azure *Cloudartifact `json:"azure,omitempty"` - BaseOsContainer *BaseOsContainer `json:"base-oscontainer,omitempty"` + BaseOsContainer *Image `json:"base-oscontainer,omitempty"` BuildArtifacts *BuildArtifacts `json:"images,omitempty"` BuildID string `json:"buildid"` BuildRef string `json:"ref,omitempty"` @@ -54,7 +50,7 @@ type Build struct { CosaImageChecksum string `json:"coreos-assembler.image-config-checksum,omitempty"` CosaImageVersion int `json:"coreos-assembler.image-genver,omitempty"` Extensions *Extensions `json:"extensions,omitempty"` - ExtensionsContainer *ExtensionsContainer `json:"extensions-container,omitempty"` + ExtensionsContainer *Image `json:"extensions-container,omitempty"` FedoraCoreOsParentCommit string `json:"fedora-coreos.parent-commit,omitempty"` FedoraCoreOsParentVersion string `json:"fedora-coreos.parent-version,omitempty"` Gcp *Gcp `json:"gcp,omitempty"` @@ -134,10 +130,6 @@ type Extensions struct { Sha256 string `json:"sha256"` } -type ExtensionsContainer struct { - Image string `json:"image"` -} - type Gcp struct { ImageFamily string `json:"family,omitempty"` ImageName string `json:"image"` @@ -154,7 +146,7 @@ type Git struct { type Image struct { Comment string `json:"comment,omitempty"` - Digest string `json:"digest"` + Digest string `json:"digest,omitempty"` Image string `json:"image"` } diff --git a/pkg/builds/schema_doc.go b/pkg/builds/schema_doc.go index 7c8f985691..936d80cc06 100644 --- a/pkg/builds/schema_doc.go +++ b/pkg/builds/schema_doc.go @@ -1,5 +1,5 @@ // Generated by ./generate-schema.sh -// Source hash: 3508b2f150e72b8e24151d870789809cf4070cec6b4716966a4e8bc585e0c5f1 +// Source hash: 1e32ab25dfdd0724f8e8246008b9d91b88a40e9ea834cf779ab0da818bf1cf25 // DO NOT EDIT package builds @@ -56,10 +56,10 @@ var generatedSchemaJSON = `{ "image": { "type": "object", "required": [ - "digest", "image" ], "optional": [ + "digest", "comment" ], "properties": { @@ -882,31 +882,13 @@ var generatedSchemaJSON = `{ "$id": "#/properties/base-oscontainer", "type": "object", "title": "Base OS container", - "required": [ - "image" - ], - "properties": { - "image": { - "$id": "#/properties/base-oscontainer/image", - "type": "string", - "title": "Image" - } - } + "$ref": "#/definitions/image" }, "extensions-container": { "$id": "#/properties/extensions-container", "type": "object", "title": "Extensions container", - "required": [ - "image" - ], - "properties": { - "image": { - "$id": "#/properties/extensions-container/image", - "type": "string", - "title": "Image" - } - } + "$ref": "#/definitions/image" }, "gcp": { "$id": "#/properties/gcp", diff --git a/src/cmd-push-container b/src/cmd-push-container index 2a8a8b5e95..ba1ddec687 100755 --- a/src/cmd-push-container +++ b/src/cmd-push-container @@ -68,7 +68,10 @@ with tempfile.NamedTemporaryFile(dir='tmp', prefix='push-container-digestfile') container = 'base-oscontainer' if args.image != 'ostree': container = args.image - meta[container] = {'image': f"{container_name}@{digest}"} + meta[container] = { + 'image': container_name, + 'digest': digest + } metapath_new = f"{metapath}.new" with open(metapath_new, 'w') as f: json.dump(meta, f, sort_keys=True) diff --git a/src/cmd-push-container-manifest b/src/cmd-push-container-manifest index a02867c98a..e0f61b666f 100755 --- a/src/cmd-push-container-manifest +++ b/src/cmd-push-container-manifest @@ -68,7 +68,10 @@ def main(): # Update the meta.json in each build/arch metadata for _, buildmeta in buildmetas.items(): - buildmeta[args.metajsonname] = {'image': f"{args.repo}@{digest}"} + buildmeta[args.metajsonname] = { + 'image': args.repo, + 'digest': digest + } buildmeta.write(artifact_name=args.metajsonname) diff --git a/src/v1.json b/src/v1.json index 0c3a3fa92e..827723cc7b 100644 --- a/src/v1.json +++ b/src/v1.json @@ -50,10 +50,10 @@ "image": { "type": "object", "required": [ - "digest", "image" ], "optional": [ + "digest", "comment" ], "properties": { @@ -876,31 +876,13 @@ "$id": "#/properties/base-oscontainer", "type": "object", "title": "Base OS container", - "required": [ - "image" - ], - "properties": { - "image": { - "$id": "#/properties/base-oscontainer/image", - "type": "string", - "title": "Image" - } - } + "$ref": "#/definitions/image" }, "extensions-container": { "$id": "#/properties/extensions-container", "type": "object", "title": "Extensions container", - "required": [ - "image" - ], - "properties": { - "image": { - "$id": "#/properties/extensions-container/image", - "type": "string", - "title": "Image" - } - } + "$ref": "#/definitions/image" }, "gcp": { "$id": "#/properties/gcp",