diff --git a/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/schema.ts b/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/schema.ts index e593328e9..d02b39e5e 100644 --- a/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/schema.ts +++ b/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/schema.ts @@ -81,10 +81,24 @@ export interface ArtifactManifest { /** * Associated metadata. * + * Metadata can be stored directly in the assembly manifest, as well as in a + * separate file (see `additionalMetadataFile`). It should prefer to be stored + * in the additional file, as that will reduce the size of the assembly + * manifest in cases of a lot of metdata (which CDK does emit by default). + * * @default - no metadata. */ readonly metadata?: { [path: string]: MetadataEntry[] }; + /** + * A file with additional metadata entries. + * + * The schema of this file is exactly the same as the type of the `metadata` field. + * + * @default - no additional metadata + */ + readonly additionalMetadataFile?: string; + /** * IDs of artifacts that must be deployed before this artifact. * diff --git a/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json b/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json index 855b0ba0b..ce3360b1c 100644 --- a/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json +++ b/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json @@ -49,7 +49,7 @@ "type": "string" }, "metadata": { - "description": "Associated metadata. (Default - no metadata.)", + "description": "Associated metadata.\n\nMetadata can be stored directly in the assembly manifest, as well as in a\nseparate file (see `additionalMetadataFile`). It should prefer to be stored\nin the additional file, as that will reduce the size of the assembly\nmanifest in cases of a lot of metdata (which CDK does emit by default). (Default - no metadata.)", "type": "object", "additionalProperties": { "type": "array", @@ -58,6 +58,10 @@ } } }, + "additionalMetadataFile": { + "description": "A file with additional metadata entries.\n\nThe schema of this file is exactly the same as the type of the `metadata` field. (Default - no additional metadata)", + "type": "string" + }, "dependencies": { "description": "IDs of artifacts that must be deployed before this artifact. (Default - no dependencies.)", "type": "array", diff --git a/packages/@aws-cdk/cloud-assembly-schema/schema/version.json b/packages/@aws-cdk/cloud-assembly-schema/schema/version.json index 8caae8e30..0d6f8054c 100644 --- a/packages/@aws-cdk/cloud-assembly-schema/schema/version.json +++ b/packages/@aws-cdk/cloud-assembly-schema/schema/version.json @@ -1,4 +1,4 @@ { - "schemaHash": "96958a4c40e0a00e850f0c14dd6e9c0fc8db0b075f1f155cea41ab198c0514be", - "revision": 43 + "schemaHash": "e03b716ea6f59e089369ce279c03a194917456d466994d434e5f9f366b745f12", + "revision": 44 } \ No newline at end of file diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/utilities/index.ts b/packages/@aws-cdk/toolkit-lib/lib/api/utilities/index.ts new file mode 100644 index 000000000..77fb751a2 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/lib/api/utilities/index.ts @@ -0,0 +1 @@ +export * from './manifest-reading'; diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/utilities/manifest-reading.ts b/packages/@aws-cdk/toolkit-lib/lib/api/utilities/manifest-reading.ts new file mode 100644 index 000000000..6adbcfa26 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/lib/api/utilities/manifest-reading.ts @@ -0,0 +1,21 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import type { ArtifactManifest, MetadataEntry } from '@aws-cdk/cloud-assembly-schema'; + +/** + * Read the metadata for the given artifact + * + * You must use this instead of accessing `ArtifactManifest.metadata` + * directly; this can also deal with the case of where the metadata + * has been written to a file. + */ +export function readArtifactMetadata(assemblyDirectory: string, x: ArtifactManifest): Record { + const ret = {}; + if (x.additionalMetadataFile) { + Object.assign(ret, JSON.parse(fs.readFileSync(path.join(assemblyDirectory, x.additionalMetadataFile), 'utf-8'))); + } + // FIXME: Conflicting paths + // FIXME: Rewrite stack tags + Object.assign(ret, x.metadata); + return ret; +}