Skip to content

Commit

Permalink
refactor(assets): remove content hash attribute (#4003)
Browse files Browse the repository at this point in the history
as part of the ci/cd design, we wish to reduce the surface area
of cdk templates to a minimum. content hash can only be determined
after the asset has been "prepared" (docker build/zip directory).

if the need arises to reintroduce this, we can always query the
content hash through a custom resource.

asset content hash is currently not used anywhere in the framework
or the aws construct library and introduces unwanted coupling between
the toolchain and the framework/app.

this change initially just removes the API from IAsset (and S3/ECR Asset classes)
to ensure code does not take a dependency on it. in a subsequent change we will
also remove the content hash cloudformation parameter.

BREAKING CHANGE: assets no longer expose a property `contentHash`. Use `sourceHash`
as a good approximation. if you have a strong use case for content hashes, please
raise a github issue and we will figure out a solution.
  • Loading branch information
Elad Ben-Israel authored and mergify[bot] committed Sep 9, 2019
1 parent 9db7fff commit 181b58b
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 30 deletions.
9 changes: 0 additions & 9 deletions packages/@aws-cdk/assets/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,4 @@ export interface IAsset {
* the content hash has changed.
*/
readonly sourceHash: string;

/**
* A hash of the bundle for of this asset, which is only available at deployment time. As this is
* a late-bound token, it may not be used in construct IDs, but can be passed as a resource
* property in order to force a change on a resource when an asset is effectively updated. This is
* more reliable than `sourceHash` in particular for assets which bundling phase involve external
* resources that can change over time (such as Docker image builds).
*/
readonly artifactHash: string;
}
2 changes: 0 additions & 2 deletions packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class DockerImageAsset extends cdk.Construct implements assets.IAsset {
public repository: ecr.IRepository;

public readonly sourceHash: string;
public readonly artifactHash: string;

/**
* Directory where the source files are stored
Expand Down Expand Up @@ -115,7 +114,6 @@ export class DockerImageAsset extends cdk.Construct implements assets.IAsset {
// haven't already started using the image.
this.repository = new AdoptedRepository(this, 'AdoptRepository', { repositoryName });
this.imageUri = `${this.repository.repositoryUri}@sha256:${imageSha}`;
this.artifactHash = imageSha;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,6 @@
}
},
"Outputs": {
"ArtifactHash": {
"Value": {
"Fn::Select": [
1,
{
"Fn::Split": [
"@sha256:",
{
"Ref": "DockerImageImageName266E5998"
}
]
}
]
}
},
"ImageUri": {
"Value": {
"Fn::Join": [
Expand Down Expand Up @@ -319,4 +304,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const asset = new assets.DockerImageAsset(stack, 'DockerImage', {
directory: path.join(__dirname, 'demo-image'),
});

new cdk.CfnOutput(stack, 'ArtifactHash', { value: asset.artifactHash });
new cdk.CfnOutput(stack, 'ImageUri', { value: asset.imageUri });

app.synth();
2 changes: 0 additions & 2 deletions packages/@aws-cdk/aws-s3-assets/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class Asset extends cdk.Construct implements assets.IAsset {
public readonly isZipArchive: boolean;

public readonly sourceHash: string;
public readonly artifactHash: string;

/**
* The S3 prefix where all different versions of this asset are stored
Expand Down Expand Up @@ -117,7 +116,6 @@ export class Asset extends cdk.Construct implements assets.IAsset {
this.s3Prefix = cdk.Fn.select(0, cdk.Fn.split(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.valueAsString)).toString();
const s3Filename = cdk.Fn.select(1, cdk.Fn.split(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.valueAsString)).toString();
this.s3ObjectKey = `${this.s3Prefix}${s3Filename}`;
this.artifactHash = hashParam.valueAsString;

this.bucket = s3.Bucket.fromBucketName(this, 'AssetBucket', this.s3BucketName);

Expand Down

0 comments on commit 181b58b

Please sign in to comment.