-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(cli): add Cloud Assembly backwards compat tests #4625
Changes from all commits
c2479f2
ba04332
8945b4b
7f0421c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ coverage | |
*.snk | ||
|
||
!test/integ/run-wrappers/dist | ||
!test/integ/cli/**/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cdk.context.json |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":"0.36.0"} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"version": "0.36.0", | ||
"artifacts": { | ||
"InitStack": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": "aws://unknown-account/unknown-region", | ||
"properties": { | ||
"templateFile": "InitStack.template.json" | ||
} | ||
} | ||
}, | ||
"runtime": { | ||
"libraries": { | ||
"@aws-cdk/core": "1.12.0", | ||
"@aws-cdk/cx-api": "1.12.0", | ||
"jsii-runtime": "node.js/v8.11.4" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":"1.10.0"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
process.stdout.write(JSON.stringify({ | ||
"version": "1.10.0", | ||
"artifacts": { | ||
"InitStack": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": `aws://${process.env.TEST_ACCOUNT}/${process.env.TEST_REGION}`, | ||
"properties": { | ||
"templateFile": "InitStack.template.json" | ||
} | ||
} | ||
}, | ||
"runtime": { | ||
"libraries": { | ||
"@aws-cdk/core": "1.14.0", | ||
"@aws-cdk/cx-api": "1.14.0", | ||
"@aws-cdk/aws-ec2": "1.14.0", | ||
"@aws-cdk/aws-iam": "1.14.0", | ||
"@aws-cdk/region-info": "1.14.0", | ||
"@aws-cdk/aws-ssm": "1.14.0", | ||
"@aws-cdk/aws-cloudwatch": "1.14.0", | ||
"jsii-runtime": "node.js/v8.11.4" | ||
} | ||
}, | ||
"missing": [ | ||
{ | ||
"key": `vpc-provider:account=${process.env.TEST_ACCOUNT}:filter.isDefault=true:region=${process.env.TEST_REGION}`, | ||
"props": { | ||
"account": process.env.TEST_ACCOUNT, | ||
"region": process.env.TEST_REGION, | ||
"filter": { | ||
"isDefault": "true" | ||
} | ||
}, | ||
"provider": "vpc-provider" | ||
} | ||
] | ||
}, undefined, 2)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":"1.10.0"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
process.stdout.write(JSON.stringify({ | ||
"version": "1.10.0", | ||
"artifacts": { | ||
"InitStack": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": `aws://${process.env.TEST_ACCOUNT}/${process.env.TEST_REGION}`, | ||
"properties": { | ||
"templateFile": "InitStack.template.json" | ||
} | ||
} | ||
}, | ||
"runtime": { | ||
"libraries": { | ||
"@aws-cdk/core": "1.14.0", | ||
"@aws-cdk/cx-api": "1.14.0", | ||
"@aws-cdk/aws-ec2": "1.14.0", | ||
"@aws-cdk/aws-iam": "1.14.0", | ||
"@aws-cdk/region-info": "1.14.0", | ||
"@aws-cdk/aws-ssm": "1.14.0", | ||
"@aws-cdk/aws-cloudwatch": "1.14.0", | ||
"jsii-runtime": "node.js/v8.11.4" | ||
} | ||
}, | ||
"missing": [ | ||
{ | ||
"key": `availability-zones:account=${process.env.TEST_ACCOUNT}:region=${process.env.TEST_REGION}`, | ||
"props": { | ||
"account": process.env.TEST_ACCOUNT, | ||
"region": process.env.TEST_REGION, | ||
}, | ||
"provider": "availability-zones" | ||
} | ||
] | ||
}, undefined, 2)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
source ${scriptdir}/common.bash | ||
# ---------------------------------------------------------- | ||
|
||
tmpdir=$(dirname $(mktemp -u)) | ||
casmdir=$tmpdir/cdk-integ-cx | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But no. I want a predictable dir, for the following reasons:
Instead, I have a directory that's the same every time which gets reset every time. This is just a complex way of writing |
||
stderrfile=$casmdir/cdk.err | ||
|
||
# Copy the files from a cloud assembly source dir into the | ||
# tempdir. Evaluate .js files found their (interpret them | ||
# as templates). | ||
function prepare_cloud_assembly() { | ||
local asmdir=$1 | ||
echo "ASSEMBLY ${asmdir}" | ||
rm -rf $casmdir | ||
mkdir -p $casmdir | ||
cp -R $asmdir/* $casmdir | ||
|
||
# Execute templates to produce file with the same name | ||
# but without .js extension | ||
shopt -s nullglob | ||
for template in $casmdir/*.js; do | ||
node $template > ${template%.js} | ||
done | ||
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid loops in bash where possible; they are not very efficient but more importantly unnatural to shell scripting. Instead use pipes. Something like, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't make me do that. This is readable, writable and clear. All that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the records, |
||
} | ||
|
||
# Assert that there was no providerError in CDK's stderr | ||
# Because we rely on the app/framework to actually error in case the | ||
# provider fails, we inspect the logs here. | ||
function assert_no_error() { | ||
local asmdir=$1 | ||
|
||
if grep '$providerError' $stderrfile; then | ||
cat $stderrfile >&2 | ||
echo "There was an error executing the context provider for assembly ${asmdir}!" >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Echo the TEST_ACCOUNT, TEST_REGION vars to make bash abort if they're not set. | ||
echo "Running backwards compatibility test (account ${TEST_ACCOUNT}, region ${TEST_REGION})" | ||
|
||
for assembly in ${scriptdir}/cloud-assemblies/*; do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as the for loop, but I understand you might want to keep this one for readability. If it were up to me, I would group what is in the loop into a function and then use pipes and xargs. I'll leave it to you to decide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this code can be conveniently rewritten to use xargs. |
||
prepare_cloud_assembly $assembly | ||
|
||
rm -f cdk.context.json | ||
cdk -a $casmdir -v synth > /dev/null 2> $stderrfile | ||
|
||
assert_no_error $assembly | ||
done | ||
|
||
echo "✅ success" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit confused - Isn't
cdk.out
a directory that contains the manifest and template?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is. I think this file exists for backwards compatibility with some old version. Elad will know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. It is there since old CLIs would look for this file name in the output directory. The
version
field here will tell them that they can't do anything besides yelling. I assume we can probably get rid of it by now...