Skip to content
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

Merged
merged 10 commits into from
Sep 22, 2022

Conversation

wanjacki
Copy link
Contributor

@wanjacki wanjacki commented Aug 29, 2022

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:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • 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]

@gitpod-io
Copy link

gitpod-io bot commented Aug 29, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team August 29, 2022 15:19
@github-actions github-actions bot added the p2 label Aug 29, 2022
@TheRealAmazonKendra
Copy link
Contributor

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.

@TheRealAmazonKendra
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Sep 9, 2022

update

✅ Branch has been successfully updated

@TheRealAmazonKendra
Copy link
Contributor

When you commit, please don't use force-push. It makes seeing the changes between commits more difficult.

@TheRealAmazonKendra
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Sep 11, 2022

update

✅ Branch has been successfully updated

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a 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)
Copy link
Contributor

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.

Copy link
Contributor

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,
});

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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.

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review September 14, 2022 06:34

Pull request has been modified.

Copy link
Contributor

@kaizencc kaizencc left a 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

@wanjacki wanjacki changed the title feat(s3-deployment): Added unzipFile flag to disable automatic unzipping feat(s3-deployment): Added extract flag to disable automatic unzipping Sep 14, 2022
@mackalex
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Sep 14, 2022

@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.
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense

@mergify mergify bot dismissed rix0rrr’s stale review September 15, 2022 19:06

Pull request has been modified.

@mackalex
Copy link
Contributor

Force-push was required due to improper rebasing before pushing on my end.

@padaszewski
Copy link

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.

@wanjacki wanjacki requested a review from rix0rrr September 20, 2022 20:10
@kaizencc kaizencc changed the title feat(s3-deployment): Added extract flag to disable automatic unzipping feat(s3-deployment): extract flag to disable automatic unzipping Sep 21, 2022
Copy link
Contributor

@kaizencc kaizencc left a 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', () => {
Copy link
Contributor

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.

Copy link
Contributor

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,
});

Copy link
Contributor

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'); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor

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.

@mergify mergify bot dismissed kaizencc’s stale review September 22, 2022 05:22

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Sep 22, 2022

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: f566d6b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 91898b5 into aws:main Sep 22, 2022
@mergify
Copy link
Contributor

mergify bot commented Sep 22, 2022

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).

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Dec 1, 2022
…#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])
@eknochenhauer
Copy link

This change has not been added to the documentation just an FYI

@scr2em
Copy link

scr2em commented Aug 15, 2023

Is this documented ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants