Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(assets): Add deploy-time content hash #2334

Merged
merged 14 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]}"`);
RomainMuller marked this conversation as resolved.
Show resolved Hide resolved
repo = isRepoUri[2];
}
console.log('RepositoryName', repo);
RomainMuller marked this conversation as resolved.
Show resolved Hide resolved

const adopter = await getAdopter(repo);
if (event.RequestType === 'Delete') {
Expand Down
10 changes: 8 additions & 2 deletions packages/@aws-cdk/assets-docker/lib/image-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface DockerImageAssetProps {
*
* The image will be created in build time and uploaded to an ECR repository.
*/
export class DockerImageAsset extends cdk.Construct {
export class DockerImageAsset extends cdk.Construct implements assets.IAsset {
/**
* The full URI of the image (including a tag). Use this reference to pull
* the asset.
Expand All @@ -41,6 +41,9 @@ export class DockerImageAsset extends cdk.Construct {
*/
public repository: ecr.IRepository;

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

/**
* Directory where the source files are stored
*/
Expand All @@ -63,16 +66,18 @@ export class DockerImageAsset extends cdk.Construct {
});

this.directory = staging.stagedPath;
this.sourceHash = staging.sourceHash;

const imageNameParameter = new cdk.CfnParameter(this, 'ImageName', {
type: 'String',
description: `ECR repository name and tag asset "${this.node.path}"`,
});

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 @@ -92,5 +97,6 @@ export class DockerImageAsset extends cdk.Construct {
// haven't already started using the image.
this.repository = new AdoptedRepository(this, 'AdoptRepository', { repositoryName });
this.imageUri = this.repository.repositoryUriForTag(imageTag);
this.bundleHash = imageTag;
}
}
Loading