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

Add config to deploymentBucket to support S3 bucket versioning #9912

Merged
merged 11 commits into from Oct 12, 2021

Conversation

mars-lan
Copy link
Contributor

@mars-lan mars-lan commented Sep 4, 2021

Closes: #5797 (again)

The original issue asked to support both encryption & versioning for the S3 deployment bucket and #5800 only addressed the first former. This PR adds an additional versioning config to support the latter.

@codecov
Copy link

codecov bot commented Sep 6, 2021

Codecov Report

Merging #9912 (25e8ad1) into master (db85602) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9912      +/-   ##
==========================================
+ Coverage   85.38%   85.41%   +0.02%     
==========================================
  Files         333      333              
  Lines       13571    13586      +15     
==========================================
+ Hits        11588    11604      +16     
+ Misses       1983     1982       -1     
Impacted Files Coverage Δ
lib/plugins/aws/provider.js 94.27% <ø> (+0.30%) ⬆️
...ib/plugins/aws/package/lib/generateCoreTemplate.js 95.55% <100.00%> (+0.20%) ⬆️
lib/plugins/aws/remove/lib/bucket.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db85602...25e8ad1. Read the comment docs.

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Thanks @mars-lan - great call 👍 I have only minor comments, please let me know what do you think.

Additionally, it would be good to add a note about this property here: https://github.com/serverless/serverless/blob/master/docs/providers/aws/guide/deploying.md#tips

@pgrzesik
Copy link
Contributor

pgrzesik commented Sep 6, 2021

Thanks @mars-lan 🙇 Before moving forward, I will test it out locally as I'm not 100% sure if bucket with versioning enabled will behave correctly when it comes to clearing previous deployment artifacts as well as during whole service teardown. Did you test that by any chance?

@mars-lan
Copy link
Contributor Author

mars-lan commented Sep 6, 2021

@pgrzesik you're correct. The current AWS bucket cleanup code is not version aware and will only delete the latest version when serverless remove is called. Will add support to remove all versions to this PR.

@mars-lan
Copy link
Contributor Author

mars-lan commented Sep 7, 2021

Thanks @mars-lan 🙇 Before moving forward, I will test it out locally as I'm not 100% sure if bucket with versioning enabled will behave correctly when it comes to clearing previous deployment artifacts as well as during whole service teardown. Did you test that by any chance?

Verified with the latest change,

  1. Deploy with versioning set to false
  2. Deploy with versioning set to true
  3. Modify code, deploy again to create a new directory in bucket
  4. Run serverless remove to teardown the stack

@mars-lan
Copy link
Contributor Author

mars-lan commented Sep 8, 2021

Ping @pgrzesik ?

@pgrzesik
Copy link
Contributor

pgrzesik commented Sep 8, 2021

Thanks for the update @mars-lan 🙇 I'm a bit swamped with other things at the moment but I will try my best to review and test it before the end of the week.

@mars-lan
Copy link
Contributor Author

Gentle ping, @pgrzesik

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Thank you @mars-lan, both for PR and your patience. Overall it looks good, I have minor comments about tests and one, a little bit more important, about the change being potentially breaking - @medikoo @mars-lan - please let me know what do you think

docs/providers/aws/guide/serverless.yml.md Outdated Show resolved Hide resolved
lib/plugins/aws/remove/lib/bucket.js Outdated Show resolved Hide resolved
test/unit/lib/plugins/aws/remove/lib/bucket.test.js Outdated Show resolved Hide resolved
@mars-lan
Copy link
Contributor Author

Ping @pgrzesik & @medikoo

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thank you @mars-lan ! It looks very good. I have just few very minor style concerns, and tests need to be updated to use our latest methodology

lib/plugins/aws/package/lib/generateCoreTemplate.js Outdated Show resolved Hide resolved
lib/plugins/aws/provider.js Outdated Show resolved Hide resolved
@@ -80,6 +80,66 @@ describe('emptyS3Bucket', () => {
});
});

describe('#listObjectVersions()', () => {
it('should resolve if no object versions are present', () => {
const listObjectVersionsStub = sinon.stub(awsRemove.provider, 'request').resolves();
Copy link
Contributor

Choose a reason for hiding this comment

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

All new tests should be configured with runServerless util.

It's documented here: https://github.com/serverless/test/blob/master/docs/run-serverless.md

Also search the code for many examples on how it's used.

I believe in this given case we need to stub AWS SDK with awsRequestStubMap option. And via stubs we should confirm that expected objest from S3 bucket were attempted to be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried my best to follow the new convesion base on the examples I could find. Let me know if I'm doing it wrong.

@mars-lan mars-lan requested a review from medikoo October 11, 2021 14:52
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

@mars-lan great thanks for update. It looks great!

Let's just use async/await syntax and it's good to take

test/unit/lib/plugins/aws/remove/lib/bucket.test.js Outdated Show resolved Hide resolved
@mars-lan mars-lan requested a review from medikoo October 11, 2021 16:56
@mars-lan
Copy link
Contributor Author

The failed test seems flakey and unrelated: https://github.com/serverless/serverless/pull/9912/checks?check_run_id=3861777865

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thank you @mars-lan ! There's still some parts where async/await is not applied.

We've also fixed flaky test, so please also rebase against master

lib/plugins/aws/remove/lib/bucket.js Outdated Show resolved Hide resolved
lib/plugins/aws/remove/lib/bucket.js Outdated Show resolved Hide resolved
@mars-lan
Copy link
Contributor Author

Thank you @mars-lan ! There's still some parts where async/await is not applied.

We've also fixed flaky test, so please also rebase against master

Merged

@mars-lan mars-lan requested a review from medikoo October 12, 2021 13:29
@mars-lan mars-lan requested a review from medikoo October 12, 2021 13:37
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thank you @mars-lan ! That looks great

@medikoo
Copy link
Contributor

medikoo commented Oct 12, 2021

@pgrzesik please review (it looks that it's needed to clear the status)

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Looks great, well done @mars-lan 👏

@mars-lan
Copy link
Contributor Author

@medikoo @pgrzesik could you merge this? Thanks.

@medikoo medikoo merged commit c4cb0f3 into serverless:master Oct 12, 2021
@mars-lan
Copy link
Contributor Author

@medikoo & @pgrzesik any idea when the next release will be cut to include this PR?

@pgrzesik
Copy link
Contributor

Hey @mars-lan - I plan to do a release today, it was supposed to come out yesterday, but Github had issues for the better part of the day so it was delayed.

@mars-lan
Copy link
Contributor Author

@pgrzesik gentle ping.

@pgrzesik
Copy link
Contributor

@mars-lan It has been released with 2.63.0 release

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

Successfully merging this pull request may close these issues.

AWS S3 Buckets Lack Encryption and Versioning
5 participants