Skip to content

Commit

Permalink
Merge branch 'master' into bootstrap-docker-pull
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jun 4, 2021
2 parents 21a441d + f932e0f commit b2f63cf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ export class Bucket extends BucketBase {
transitionDate: t.transitionDate,
transitionInDays: t.transitionAfter && t.transitionAfter.toDays(),
})),
expiredObjectDeleteMarker: rule.expiredObjectDeleteMarker,
tagFilters: self.parseTagFilters(rule.tagFilters),
};

Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-s3/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export interface LifecycleRule {
* @default Rule applies to all objects
*/
readonly tagFilters?: {[tag: string]: any};

/**
* Indicates whether Amazon S3 will remove a delete marker with no noncurrent versions.
* If set to true, the delete marker will be expired.
*
* @default false
*/
readonly expiredObjectDeleteMarker?: boolean;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions packages/@aws-cdk/aws-s3/test/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,28 @@ nodeunitShim({

test.done();
},

'Bucket with expiredObjectDeleteMarker'(test: Test) {
// GIVEN
const stack = new Stack();

// WHEN
new Bucket(stack, 'Bucket', {
lifecycleRules: [{
expiredObjectDeleteMarker: true,
}],
});

// THEN
expect(stack).to(haveResource('AWS::S3::Bucket', {
LifecycleConfiguration: {
Rules: [{
ExpiredObjectDeleteMarker: true,
Status: 'Enabled',
}],
},
}));

test.done();
},
});
4 changes: 2 additions & 2 deletions packages/cdk-assets/lib/private/handlers/container-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export class ContainerImageAssetHandler implements IAssetHandler {
public async publish(): Promise<void> {
const destination = await replaceAwsPlaceholders(this.asset.destination, this.host.aws);
const ecr = await this.host.aws.ecrClient(destination);
const account = (await this.host.aws.discoverCurrentAccount()).accountId;
const account = async () => (await this.host.aws.discoverCurrentAccount())?.accountId;
const repoUri = await repositoryUri(ecr, destination.repositoryName);

if (!repoUri) {
throw new Error(`No ECR repository named '${destination.repositoryName}' in account ${account}. Is this account bootstrapped?`);
throw new Error(`No ECR repository named '${destination.repositoryName}' in account ${await account()}. Is this account bootstrapped?`);
}

const imageUri = `${repoUri}:${destination.imageTag}`;
Expand Down
12 changes: 12 additions & 0 deletions packages/cdk-assets/test/docker-images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ describe('with a complete manifest', () => {
}));
});

test('Displays an error if the ECR repository cannot be found', async () => {
aws.mockEcr.describeImages = mockedApiFailure('RepositoryNotFoundException', 'Repository not Found');

await expect(pub.publish()).rejects.toThrow('Error publishing: Repository not Found');
});

test('successful run does not need to query account ID', async () => {
aws.mockEcr.describeImages = mockedApiResult({ /* No error == image exists */ });
await pub.publish();
expect(aws.discoverCurrentAccount).not.toHaveBeenCalled();
});

test('upload docker image if not uploaded yet but exists locally', async () => {
aws.mockEcr.describeImages = mockedApiFailure('ImageNotFoundException', 'File does not exist');
aws.mockEcr.getAuthorizationToken = mockedApiResult({
Expand Down

0 comments on commit b2f63cf

Please sign in to comment.