-
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
feat(s3-deployment): extract flag to disable automatic unzipping #21805
Conversation
In the issue you linked has a discussion of why we have not gone in this direction. Please take another look at this comment. Given that we will not be going in this direction, I'm going to close this particular PR but, if a fix for this issue is something you'd like to continue pursuing, we can certainly continue the conversation in that linked issue. |
c3201c0
to
97f1839
Compare
@Mergifyio update |
✅ Branch has been successfully updated |
1223c03
to
fa49c09
Compare
When you commit, please don't use force-push. It makes seeing the changes between commits more difficult. |
@Mergifyio update |
✅ Branch has been successfully updated |
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.
Please make sure that your PR title confirms to the conventional commit standard (fix, feat, chore) and that it is written in a style that will reflect correctly in the change log (See Contributing Guide, Pull Requests).
Additionally, please see my comments inline.
logger.info("| markers: %s" % markers) | ||
extract_and_replace_markers(archive, contents_dir, markers) | ||
else: | ||
aws_command("s3", "cp", s3_source_zip, contents_dir) |
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.
Let's still providing logging info in the else.
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.
Logging added.
extract: false, | ||
retainOnDelete: false, | ||
}); | ||
|
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.
This should probably have some sort of assertion to test that it's both uploaded properly and that it hasn't been extracted.
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 made use of the AwsApiCall
construct and assertions feature provided by the integ-tests module to assert that the archive for the website folder is in the target bucket after deployment of the integ stack. Let me know if this is a solid assertion and proper use of the testing constructs.
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 this looks reasonable.
# if "cp" is called with a local destination, copy a test zip file to the destination or | ||
if sys.argv[2] == "cp" and not sys.argv[4].startswith("s3://"): | ||
# if "cp" is called to contents, copy a test zip file to contents | ||
# else if "cp" is called with a local destination, copy a test zip file to the destination or |
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.
This is kind of a nit, but these comments are the wrong order for what's the if
statement and what's the else if
statement.
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 attempted to correct this. Let me know if the order makes more sense now.
Pull request has been modified.
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.
Remember to update the title and PR description to reflect the correct property name of extract
rather than unzipFile
@Mergifyio update |
@mackalex is not allowed to run commands |
## Keep Files Zipped | ||
|
||
By default, files are zipped, then extracted into the destination bucket. | ||
You can use the option `extract: false` to disable this behavior, in which case, files will remain in a zip file when deployed to S3. |
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.
Say something about the target filename and how it can be acquired by users.
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 by target filename you are referring to the *.zip
file that is found in the target S3 bucket after bucket deployment. Is that 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.
Yes.
aws_command("s3", "cp", s3_source_zip, archive) | ||
logger.info("| extracting archive to: %s\n" % contents_dir) | ||
logger.info("| markers: %s" % markers) | ||
extract_and_replace_markers(archive, contents_dir, markers) |
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.
It looks like marker replacement won't work anymore if extract == false
.
Check for the combination of markers and extract == false
in the constructor of the BucketDeployment
and throw an error that these features cannot be combined.
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.
That's correct. I used the existing hasMarkers
const in a new conditional that checks if sources have markers and that extract is false, and then it throws an error on construction of BucketDeployment
. I added a unit test for this as well.
logger.info("| markers: %s" % markers) | ||
extract_and_replace_markers(archive, contents_dir, markers) | ||
else: | ||
aws_command("s3", "cp", s3_source_zip, contents_dir) |
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.
Return an output property that contains the full generated object key (excluding the bucket name). This is going to entail adding a field to the responseData
object here:
cfn_send(event, context, CFN_SUCCESS, physicalResourceId=physical_id, responseData={ |
And making it accessible as a property via a this.cr.getAtt()
like here:
this._deployedBucket = this._deployedBucket ?? s3.Bucket.fromBucketArn(this, 'DestinationBucket', cdk.Token.asString(this.cr.getAtt('DestinationBucketArn'))); |
It can be in a getter that returns a string. Don't forget to document it.
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.
There are multiple object keys if multiple sources are provided to the BucketDeployment
construct. Would it make the most sense to return a list of strings which are the object keys?
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, that makes sense
Pull request has been modified.
c207c61
to
a4ff605
Compare
Force-push was required due to improper rebasing before pushing on my end. |
Would love to see any progress here, as the guys have a deadline for implementing the service catalog assets (depends on this PR) feature, which is extremly important for all cdk + service catalog users. |
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 have a few minor comments but other than that I think this PR is good to go :).
}); | ||
}); | ||
|
||
test('deploy without extracting files in destination', () => { |
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.
this test has the same name as above.
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.
Good catch, thanks! Will update
extract: false, | ||
retainOnDelete: false, | ||
}); | ||
|
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 this looks reasonable.
@@ -339,6 +346,10 @@ export class BucketDeployment extends Construct { | |||
// the sources actually has markers. | |||
const hasMarkers = sources.some(source => source.markers); | |||
|
|||
// Markers are not replaced if zip sources are not extracted, so throw an error | |||
// if extraction is not wanted and sources have markers. | |||
if (hasMarkers && props.extract == false) { throw new Error('Extract cannot be false if sources have markers'); } |
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.
if (hasMarkers && props.extract == false) { throw new Error('Extract cannot be false if sources have markers'); } | |
if (hasMarkers && props.extract === false) { | |
throw new Error('Some sources are incompatible with extract=false; sources with deploy-time values (such as \'snsTopic.topicArn\') must be extracted.'); | |
} |
My problem here is that markers is an internal property that the user is not really privy to. Getting an error that says that your source has markers is pretty cryptic. Markers are substitutes for Ref
and Fn::GetAtt
objects, which come from deploy-time values. So lets create an error message that reflects that.
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.
Thank you for the suggestion. I'll incorporate this into a better error message.
Pull request has been modified.
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
…#21805) Currently S3 Deployment will unzip all files when deployed to S3. This PR adds an additional optional prop `extract`, that when set to false will allow files to remain zipped when deployed to S3. Adds the feature described in issue: aws#8065 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* ---- Co-authored-by: Alex Makoviecki [[email protected]](mailto:[email protected])
This change has not been added to the documentation just an FYI |
Is this documented ? |
Currently S3 Deployment will unzip all files when deployed to S3. This PR adds an additional optional prop
extract
, that when set to false will allow files to remain zipped when deployed to S3.Adds the feature described in issue: #8065
All Submissions:
Adding new Unconventional Dependencies:
New Features
yarn integ
to deploy the infrastructure and generate the snapshot (i.e.yarn integ
without--dry-run
)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
Co-authored-by: Alex Makoviecki [email protected]