Skip to content

Commit

Permalink
feat(assets): Add deploy-time content hash property
Browse files Browse the repository at this point in the history
Introduces an `IAsset` interface that centralizes common aspects about
assets, such as the `sourceHash` and `bundleHash` properties.

The `sourceHash` fingerprints the objects that are used as the source
for the asset bundling logic, and is available at synthesis time (it can
for example be injected in construct IDs when it one wants to ensure a
new logical ID is issued for every new version of the asset).

The `bundleHash` fingerprints the result of the bundling logic, and is
more accurate than `sourceHash` (in that, if the same source can produce
different artifacts at different points in time, the `sourceHash` will
remain un-changed, but the `bundleHash` will change. The `bundleHash` is
however a deploy-time value and thus cannot be used in construct IDs.

Fixes #1400
  • Loading branch information
RomainMuller committed Apr 19, 2019
1 parent 29340a1 commit bb0753b
Show file tree
Hide file tree
Showing 42 changed files with 565 additions and 4,355 deletions.
26 changes: 16 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
# VSCode extension
.vscode/
/.favorites.json

# TypeScript incremental build states
*.tsbuildinfo

.vscode
# VSCode extension
/.favorites.json
# Locak state files & OS specifics
.DS_Store
node_modules
node_modules/
lerna-debug.log
dist
pack
dist/
pack/
.BUILD_COMPLETED
.local-npm
.tools
coverage
.local-npm/
.tools/
coverage/
.nyc_output
.LAST_BUILD
*.sw[a-z]
*~

# we don't want tsconfig at the root
# We don't want tsconfig at the root
/tsconfig.json

# CDK Context & Staging files
cdk.context.json
.cdk.staging/
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ exports.handler = async function(event, context, _callback, respond) {
}
}

const repo = event.ResourceProperties.RepositoryName;
let repo = event.ResourceProperties.RepositoryName;
if (!repo) {
throw new Error('Missing required property "RepositoryName"');
}
const isRepoUri = repo.match(/^(\d+\.dkr\.ecr\.[^.]+\.[^/]+\/)(.+)$/i);
if (isRepoUri) {
console.log(`"${repo}" like a repository URI: dropping "${isRepoUri[1]}"`);
repo = isRepoUri[2];
}
console.log('RepositoryName', repo);

const adopter = await getAdopter(repo);
if (event.RequestType === 'Delete') {
Expand Down
9 changes: 4 additions & 5 deletions packages/@aws-cdk/assets-docker/lib/image-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class DockerImageAsset extends cdk.Construct implements assets.IAsset {
public repository: ecr.IRepository;

public readonly sourceHash: string;
public readonly bundleHash: string;

/**
* Directory where the source files are stored
Expand Down Expand Up @@ -73,9 +74,10 @@ export class DockerImageAsset extends cdk.Construct implements assets.IAsset {
});

const asset: cxapi.ContainerImageAssetMetadataEntry = {
id: this.node.uniqueId,
packaging: 'container-image',
path: this.directory,
id: this.node.uniqueId,
sourceHash: this.sourceHash,
imageNameParameter: imageNameParameter.logicalId,
repositoryName: props.repositoryName,
};
Expand All @@ -95,9 +97,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.repositoryUriForTag(imageTag);
}

public get bundleHash(): string {
return cdk.Fn.split('@sha256:', this.imageUri)[1];
this.bundleHash = imageTag;
}
}
Loading

0 comments on commit bb0753b

Please sign in to comment.