Skip to content

Commit

Permalink
fix(ecr-assets): There is already a Construct with name 'Staging' whe…
Browse files Browse the repository at this point in the history
…n using tarball image (aws#15540)

Use `this` and not `scope` for the scope of `AssetStaging` in
`TarballImageAsset`.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold authored and TikiTDO committed Aug 3, 2021
1 parent 658200f commit 4b10708
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecr-assets/lib/tarball-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class TarballImageAsset extends CoreConstruct implements IAsset {
throw new Error(`Cannot find file at ${props.tarballFile}`);
}

const stagedTarball = new AssetStaging(scope, 'Staging', { sourcePath: props.tarballFile });
const stagedTarball = new AssetStaging(this, 'Staging', { sourcePath: props.tarballFile });

this.sourceHash = stagedTarball.assetHash;
this.assetHash = stagedTarball.assetHash;
Expand Down
13 changes: 8 additions & 5 deletions packages/@aws-cdk/aws-ecr-assets/test/tarball-asset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('image asset', () => {
testFutureBehavior('test instantiating Asset Image', flags, App, (app) => {
// GIVEN
const stack = new Stack(app);
const assset = new TarballImageAsset(stack, 'Image', {
const asset = new TarballImageAsset(stack, 'Image', {
tarballFile: __dirname + '/demo-tarball/empty.tar',
});

Expand All @@ -30,23 +30,26 @@ describe('image asset', () => {
expect(Object.keys(manifest.files ?? {}).length).toBe(1);
expect(Object.keys(manifest.dockerImages ?? {}).length).toBe(1);

expect(manifest.dockerImages?.[assset.assetHash]?.destinations?.['current_account-current_region']).toStrictEqual(
expect(manifest.dockerImages?.[asset.assetHash]?.destinations?.['current_account-current_region']).toStrictEqual(
{
assumeRoleArn: 'arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-image-publishing-role-${AWS::AccountId}-${AWS::Region}',
imageTag: assset.assetHash,
imageTag: asset.assetHash,
repositoryName: 'cdk-hnb659fds-container-assets-${AWS::AccountId}-${AWS::Region}',
},
);

expect(manifest.dockerImages?.[assset.assetHash]?.source).toStrictEqual(
expect(manifest.dockerImages?.[asset.assetHash]?.source).toStrictEqual(
{
executable: [
'sh',
'-c',
`docker load -i asset.${assset.assetHash}.tar | sed "s/Loaded image: //g"`,
`docker load -i asset.${asset.assetHash}.tar | sed "s/Loaded image: //g"`,
],
},
);

// AssetStaging in TarballImageAsset uses `this` as scope'
expect(asset.node.tryFindChild('Staging')).toBeDefined();
});

testFutureBehavior('asset.repository.grantPull can be used to grant a principal permissions to use the image', flags, App, (app) => {
Expand Down

0 comments on commit 4b10708

Please sign in to comment.