Skip to content

Commit

Permalink
add integration test to verify docker bootstrapping and publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Ben-Israel committed Jun 3, 2020
1 parent 778c70f commit 15945e8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/aws-cdk/lib/api/bootstrap/bootstrap-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ Outputs:
Description: The domain name of the S3 bucket owned by the CDK toolkit stack
Value:
Fn::Sub: "${StagingBucket.RegionalDomainName}"
ImageRepositoryName:
Description: The name of the ECR repository which hosts docker image assets
Value:
Fn::Sub: "${ContainerAssetsRepository}"
BootstrapVersion:
Description: The version of the bootstrap resources that are currently mastered
in this stack
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Compilation of the tests is done as part of the normal package build, at
which point it is using the dependencies brought in by the containing
`aws-cdk` package's `package.json`.

When run in a non-develompent repo (as done during integ tests or canary runs),
When run in a non-development repo (as done during integ tests or canary runs),
the required dependencies are brought in just-in-time via `test-jest.sh`. Any
new dependencies added for the tests should be added there as well. But, better
yet, don't add any dependencies at all. You shouldn't need to, these tests
Expand Down
5 changes: 5 additions & 0 deletions packages/aws-cdk/test/integ/cli/aws-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export let testEnv = async (): Promise<Env> => {

export const cloudFormation = makeAwsCaller(AWS.CloudFormation);
export const s3 = makeAwsCaller(AWS.S3);
export const ecr = makeAwsCaller(AWS.ECR);
export const sns = makeAwsCaller(AWS.SNS);
export const iam = makeAwsCaller(AWS.IAM);
export const lambda = makeAwsCaller(AWS.Lambda);
Expand Down Expand Up @@ -188,6 +189,10 @@ export async function emptyBucket(bucketName: string) {
});
}

export async function deleteImageRepository(repositoryName: string) {
await ecr('deleteRepository', { repositoryName, force: true });
}

export async function deleteBucket(bucketName: string) {
try {
await emptyBucket(bucketName);
Expand Down
23 changes: 23 additions & 0 deletions packages/aws-cdk/test/integ/cli/bootstrapping.integtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ test('deploy new style synthesis to new style bootstrap', async () => {
});
});

test('deploy new style synthesis to new style bootstrap (with docker image)', async () => {
const bootstrapStackName = fullStackName('bootstrap-stack');

await cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--qualifier', QUALIFIER,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess',
], {
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
},
});

// Deploy stack that uses file assets
await cdkDeploy('docker', {
options: [
'--toolkit-stack-name', bootstrapStackName,
'--context', `@aws-cdk/core:bootstrapQualifier=${QUALIFIER}`,
'--context', '@aws-cdk/core:newStyleStackSynthesis=1',
],
});
});

test('deploy old style synthesis to new style bootstrap', async () => {
const bootstrapStackName = fullStackName('bootstrap-stack');

Expand Down
8 changes: 6 additions & 2 deletions packages/aws-cdk/test/integ/cli/cdk-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as child_process from 'child_process';
import * as os from 'os';
import * as path from 'path';
import { cloudFormation, deleteBucket, deleteStacks, emptyBucket, outputFromStack, testEnv } from './aws-helpers';
import { cloudFormation, deleteBucket, deleteImageRepository, deleteStacks, emptyBucket, outputFromStack, testEnv } from './aws-helpers';

export const INTEG_TEST_DIR = path.join(os.tmpdir(), 'cdk-integ-test2');

Expand Down Expand Up @@ -155,6 +155,10 @@ export async function cleanup(): Promise<void> {
const bucketNames = stacksToDelete.map(stack => outputFromStack('BucketName', stack)).filter(defined);
await Promise.all(bucketNames.map(emptyBucket));

// Bootstrap stacks have ECR repositories with images which should be deleted
const imageRepositoryNames = stacksToDelete.map(stack => outputFromStack('ImageRepositoryName', stack)).filter(defined);
await Promise.all(imageRepositoryNames.map(deleteImageRepository));

await deleteStacks(...stacksToDelete.map(s => s.StackName));

// We might have leaked some buckets by upgrading the bootstrap stack. Be
Expand Down Expand Up @@ -209,7 +213,7 @@ export async function shell(command: string[], options: ShellOptions = {}): Prom
if (code === 0 || options.allowErrExit) {
resolve((Buffer.concat(stdout).toString('utf-8') + Buffer.concat(stderr).toString('utf-8')).trim());
} else {
reject(new Error(`'${command.join(' ')}' exited with error code ${code}`));
reject(new Error(`'${command.join(' ')}' exited with error code ${code}: ${Buffer.concat(stderr).toString('utf-8').trim()}`));
}
});
});
Expand Down
6 changes: 5 additions & 1 deletion packages/cdk-assets/lib/private/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function shell(command: string[], options: ShellOptions = {}): Prom
}

const stdout = new Array<any>();
const stderr = new Array<any>();

// Both write to stdout and collect
child.stdout.on('data', chunk => {
Expand All @@ -43,6 +44,8 @@ export async function shell(command: string[], options: ShellOptions = {}): Prom
if (!options.quiet) {
process.stderr.write(chunk);
}

stderr.push(chunk);
});

child.once('error', reject);
Expand All @@ -51,7 +54,8 @@ export async function shell(command: string[], options: ShellOptions = {}): Prom
if (code === 0) {
resolve(Buffer.concat(stdout).toString('utf-8'));
} else {
reject(new ProcessFailed(code, `${renderCommandLine(command)} exited with error code ${code}`));
const out = Buffer.concat(stderr).toString('utf-8').trim();
reject(new ProcessFailed(code, `${renderCommandLine(command)} exited with error code ${code}: ${out}`));
}
});
});
Expand Down

0 comments on commit 15945e8

Please sign in to comment.