Repository navigation
Conversation
This is prerequisite change. Since we change the S3 artifacts structure, not all files will get uploaded to directory with the timestamp.
Also move it to common aws plugin utils directory
This one is based on listing Cloudformation template files from the last n [5] deployments and reading associated artifacts from its resources.
To be used within the commands: - deploy list, deploy (s3 cleanup phase) and rollback
|
@remi00 thanks for new PR! Is this assumed as ready for review? If so can you check CI fails? Thank you! |
Codecov Report
@@ Coverage Diff @@
## master #9876 +/- ##
==========================================
+ Coverage 86.20% 86.24% +0.04%
==========================================
Files 329 329
Lines 12811 12858 +47
==========================================
+ Hits 11044 11090 +46
- Misses 1767 1768 +1
Continue to review full report at Codecov.
|
|
@medikoo some broken tests which was not expected... Apologies for that. I can't find the capability to switch the PR into draft once it's created. Maybe I miss the permission. Hopefully I will address the test issues shortly. |
|
@remi00 not a problem, again great thanks for working on this, as it's a highly anticipated optimization we'd love to have in. I've converted it to draft. Let us know, once you feel it's ready, and if you need any help, don't hesitate to ask. |
c2f67e9 to
58d911d
Compare
58d911d to
4cb5090
Compare
|
@medikoo Tests are now ✅ PR ready for review ☺ |
|
|
||
| const BbPromise = require('bluebird'); | ||
|
|
||
| const MAX_CONCURRENT_S3_DOWNLOADS = Number(process.env.SLS_MAX_CONCURRENT_S3_DOWNLOADS) || 7; |
There was a problem hiding this comment.
Do we need to introduce an option for this? Or could we go with a sane default?
(any extra option is BC surface, as well as documentation, so if we can avoid it that's best :) )
There was a problem hiding this comment.
I removed this env variable 👍
medikoo
left a comment
There was a problem hiding this comment.
@remi00 great thanks for this PR!
Please see my comments, I think we can minimize needed set of changes, and ideally would be that we go as close to spec as possible, Ifyou feel that we need to derive from it, can we first discuss it (?) with this approach I think we may save time on producing unnecessary changes.
Anyway, great work! Let me know your thoughts
| let params = { | ||
| Bucket: this.bucketName, | ||
| Key: `${this.serverless.service.package.artifactDirectoryName}/${compiledTemplateFileName}`, | ||
| Key: `${deploymentDirectoryPrefix}/${timestamp}/${compiledTemplateFileName}`, |
There was a problem hiding this comment.
I think we should not do any changes here (it's about storing CF template, and we do not alter this location in any way)
There was a problem hiding this comment.
It is about the fact that previously artifactDirectoryName included the timestamp. E.g.:
serverless/test/2021-10-21T20:12:00
Now, CFN template lands in the same place. But other artifacts and pieces land in
serverless/test/code-artifacts
Common part of both paths is now deploymentDirectoryPrefix and timestamp is just timestamp.
Presumably, we could just generate and store the timestamp, and create the destination S3 prefix ad hoc (when needed) with serviceName and getStage(). WDYT?
There was a problem hiding this comment.
We actually cannot change value or remove this.serverless.service.package.artifactDirectoryName property, as it's used by some plugins (just checked that).
To avoid confusion we may stop using internallythis.serverless.service.package.artifactDirectoryName (it'll be just good to add comment above it's assignment that's left for legacy purposes), and maybe introduce a more accurate:
serverless.getProvider('aws').s3CodeArtifactsDirectoryPath = `${prefix}/${service}/${stage}/code-artifacts`
serverless.getProvider('aws').s3DeploymentDirectoryPath = `${prefix}/${service}/${stage}/${timestamp}`Still I would precede such change with a separate PR, that:
- Introduces
serverless.getProvider('aws').s3DeploymentDirectoryPath - Replaces
service.package.artifactDirectoryNameusage withserverless.getProvider('aws').s3DeploymentDirectoryPath
WDYT?
There was a problem hiding this comment.
Thanks a lot for checking with plugins. I will apply the change as suggested within a dedicated PR preceding this one.
| const data = fs.readFileSync(artifactFilePath); | ||
| const fileHash = crypto.createHash('sha256').update(data).digest('base64'); |
There was a problem hiding this comment.
It will be nice to introduce (with other PR) a refactor where we rely on memoized getHashForFilePath util
There was a problem hiding this comment.
Sounds like a good idea. Other PR sounds good too :)
| @@ -0,0 +1,63 @@ | |||
| 'use strict'; | |||
|
|
|||
| const BbPromise = require('bluebird'); | |||
There was a problem hiding this comment.
Let's stick to native promises
| } | ||
| }, | ||
| { | ||
| concurrency: MAX_CONCURRENT_S3_DOWNLOADS, |
There was a problem hiding this comment.
Once we will limit the amount of CF stacks we check, to inspect them only when needed, I think there's no need for extra environment flag to control that.
If users will stick to default of 5 versions max, it will be at most 5 request, which I think can be done in parallel. Still just to be on safe side I would probably still limit the concurrency, to hardocded 5, and let's limit it with ext/promise/limit
| Bucket: this.bucketName, | ||
| Key: key, | ||
| }; | ||
| await this.provider.request('S3', 'headObject', params); |
There was a problem hiding this comment.
I guess it's more efficient to resolve all file names with one call and confirm against that, instead of issuing AWS request per each file name
There was a problem hiding this comment.
As in my previous response, changing this sounds like premature optimization. AWS SDK for JS is by far robust. It reuses connections from HTTP pool, and since we limit number of simultaneous upload processes, it takes advantage of that mechanism very nicely. Doing headObject is seamless. Checked within the project using Serverless with more than 25 Lambda functions.
There was a problem hiding this comment.
@remi00 ok, so situation with AWS SDK, is that it creates some sort of long-polling connection? and then works in similar way as e.g. SSE on browser side?
What are the observed times of above requests when done locally? (e.g. if you read time at 59 line and then check difference at 61 or 63, what difference you will observe)
Note that reusing collection of obtained names will make this logic also simpler, this try/catch looks a bit convoluted
There was a problem hiding this comment.
Thanks, I will revisit this suggestion.
Here some excerpt from the logs as advised. No patterns on the length I think.
serverless/***/dev/code-artifacts/83f3ab22220623a3e0a1c1006019aa0ffabf38f4a45968dfc4bc4502c7ab61d0.zip 218
serverless/***/dev/code-artifacts/83f3ab22220623a3e0a1c1006019aa0ffabf38f4a45968dfc4bc4502c7ab61d0.zip 176
serverless/***/dev/code-artifacts/b511cc239fc18dc2d18346fe920c3d0e121b91d20c81ac618c1d7b0f769959e7.zip 117
serverless/***/dev/code-artifacts/485c82da1d982767d9eb21fade33ba806a7abd8dd771ef3de8543eb31629f669.zip 288
serverless/***/dev/code-artifacts/1b833dd49100cb6c9e36b6c6d20415e7c466d6bb5f6923140cc819b9abc04103.zip 230
serverless/***/dev/code-artifacts/dffd763a7238dbe18460add36070d3209ddac83cba220d3f5ecd8022a390601d.zip 153
serverless/***/dev/code-artifacts/da861085fbf6494e427b50f32f9c927e7464d8e520c9713d5f09b7cc54ab8808.zip 204
serverless/***/dev/code-artifacts/575d4ad4cec1c94d98e10093db22647a03bef195ba8af3cfedd5d5aac23f57af.zip 161
serverless/***/dev/code-artifacts/d74729b6433436d3cceb680e14beec0395de1ff8caec18a2281839fc11cb7424.zip 234
serverless/***/dev/code-artifacts/b63d6a4580589d317eeb70fc42a9af30f84fdb24cab4942231107cf83c5618c7.zip 175
serverless/***/dev/code-artifacts/e4b3bac7adf8c7225cb85f1e325035c54a619da6826c300684a787f83c3e12e2.zip 259
serverless/***/dev/code-artifacts/8ba0344dbe71bc345b24578f1c47bfac539d4cdb39fe28f82db1bf2977add7e2.zip 172
serverless/***/dev/code-artifacts/77439124b0d653e31791603625324e307caeb512f6a4e56f741ec22823714f2d.zip 265
serverless/***/dev/code-artifacts/54894d0ef4600e96d1daccd3b7f7044e594875e2f517876500dc2e2041d77ac1.zip 159
serverless/***/dev/code-artifacts/fc90c0887ffb90dcd665f75b34fb6217d79af15dd933d2abe2205918e8db6172.zip 252
serverless/***/dev/code-artifacts/bd026b838d11e1eb1dc94ba15cf4fe8d69914418a6526aee00e54daed314d40f.zip 222
serverless/***/dev/code-artifacts/3ada44b12dcb546cd20822d72299e60ea65ed0afe34b87af5c43c61bfdc184a0.zip 358
serverless/***/dev/code-artifacts/61462cfdf3d771a3db7ec9800e662a3adc628703e19d9937979639cbbf030c4b.zip 173
serverless/***/dev/code-artifacts/49219f38ee34b704f85b97c703254f4a221daa0df66d057a0725bc0922c508f5.zip 245
serverless/***/dev/code-artifacts/41ee01fc2e0ba0a24754b5fd0b9e624e8da4643f926fd2ac629312e8590d01cb.zip 146
serverless/***/dev/code-artifacts/ca1c96a41c510f746cb672a4754814e3adeaf7f8c7e0d3e4988bdb88c7779054.zip 241
serverless/***/dev/code-artifacts/351e89375570a91b23b6c95b395adbe9a1ba0f19930cc44e7521bf54f19809b5.zip 127
serverless/***/dev/code-artifacts/3fd826bcaa3151bc6686d6fc71ffa22f217d5f3fa36aeefcf24ccf20078a1fbc.zip 224
serverless/***/dev/code-artifacts/d16fbf824d82059a66774daa640b0eb86a5959547597357646a8711a09005029.zip 127
serverless/***/dev/code-artifacts/43aac618fcbdc02de0c3c305c066304d161007671a33f52b2a031e79da77ca56.zip 232
serverless/***/dev/code-artifacts/793a9307b335f1c3983c3a0772bdde95cd9f13f6a1d2749c8e7f2990c79f059d.zip 127
serverless/***/dev/code-artifacts/f1277ced42f21780f1bb700c83e527e841cf5cf86568867059de5bb51dfb6fc3.zip 231
serverless/***/dev/code-artifacts/9191bc6f87cc446b5c1443311b674ca0699ec8004a702a5fdd3c64ef8f79704f.zip 148
serverless/***/dev/code-artifacts/17c0bfd498cd9e1099893c7239d541466db18d979f192bacdd1bebc0e3357ce1.zip 150
serverless/***/dev/code-artifacts/799693245bf0be41ec88c98a9b6abb29bc23d39bf75fb9f994ef98b95020548d.zip 333
serverless/***/dev/code-artifacts/5a047b1f7d7740e90d2c70c1d6dba9c08818423c845a88bdb6505a5608e7ad7c.zip 315
serverless/***/dev/code-artifacts/4d4b58c3a0669b8aa0651926bc43fa7d9def1d709b6df22b1492f0eecb470604.zip 119
serverless/***/dev/code-artifacts/c3bba113d4fa343160618174c07f5558386f00bffe6a78d4c55aac0afe77743d.zip 117
serverless/***/dev/code-artifacts/70b74fd9325fbeaa9d358db1c462ce2c763ccce00c0044c595182627ef5257ae.zip 236
serverless/***/dev/code-artifacts/4117fda13f45243c05b873400f1793863f03abde1417bf36eb63e6a88cf8aa69.zip 288
serverless/***/dev/code-artifacts/15687690138badea2a00a73a72cfe55444e1b3d807688614a9aa0db657477706.zip 193
serverless/***/dev/code-artifacts/1f446e0670f8b80edf91de08684bbfcab2779e82486037b09787498d1ade3868.zip 219
serverless/***/dev/code-artifacts/fa28e148a46344b92cfad5072d689b05239cf60381fabeaa0b1c4e375b6882b5.zip 140
serverless/***/dev/code-artifacts/82e85fa46cfc7824ba73d80675aa17dfdc5cdac36c241065cadd4828eee4f8cc.zip 223
serverless/***/dev/code-artifacts/7b42199932a71a568a8bc009b4c73e38075f4a520b00740dcba77d023983069e.zip 140
serverless/***/dev/code-artifacts/e622158507b1b09ab1dd38ec8a32deaeff5ecc5df747d64b31d45509ed3b728a.zip 212
serverless/***/dev/code-artifacts/7452b7ed022dccfe826c1525bcd8dde91c52ec0f49a8602338aecaca66f6dd0b.zip 139
serverless/***/dev/code-artifacts/4ab258938a9fe37d835411179248303cb3888e6d0525f0305902346179e32ea5.zip 208
serverless/***/dev/code-artifacts/336fb9ecd70f00118f67d2be150b4fd924f5d8cf5cc517ab5c03d476f350fb31.zip 131
| const validate = require('./lib/validate'); | ||
| const findAndGroupDeployments = require('./utils/findAndGroupDeployments'); | ||
| const setBucketName = require('./lib/setBucketName'); | ||
| const findDeployments = require('./lib/findDeployments'); |
There was a problem hiding this comment.
I think we do not need any changes here (?)
| const compiledTemplateFileName = this.provider.naming.getCompiledTemplateS3Suffix(); | ||
| const s3Endpoint = getS3EndpointForRegion(this.provider.getRegion()); | ||
| const templateUrl = `https://${s3Endpoint}/${this.bucketName}/${this.serverless.service.package.artifactDirectoryName}/${compiledTemplateFileName}`; | ||
| const { deploymentDirectoryPrefix, timestamp } = this.serverless.service.package; |
There was a problem hiding this comment.
We don't need any changes here I think (?)
| @@ -0,0 +1,18 @@ | |||
| 'use strict'; | |||
There was a problem hiding this comment.
I think this introduction is not really necessary (?) What does it aid?
| individually: this.serverless.service.package.individually, | ||
| artifactDirectoryName: this.serverless.service.package.artifactDirectoryName, | ||
| deploymentDirectoryPrefix: this.serverless.service.package.deploymentDirectoryPrefix, | ||
| timestamp: this.serverless.service.package.timestamp, |
There was a problem hiding this comment.
Per spec initially we agreed simply to add list file hash list (still I've proposed to simplify that in last comment in an issue). What's the reasoning behind different approach?
There was a problem hiding this comment.
As part of the rework I eventually added the artifactsMap. My previous idea to rely on compiled Cloudformation template failed due to the inconsistency between layers and lambda functions and also separate approach to custom resources. I think I found relatively lightweight approach to store the artifacts mapping as you initially suggested. Please take a look on added commits.
There was a problem hiding this comment.
My previous idea to rely on compiled Cloudformation template failed due to the inconsistency between layers and lambda functions and also separate approach to custom resources
Do you mean that it's difficult to retrieve generated paths for those resources from CF template?
Ideally if any deviations from specifications are signaled with proper reasoning at the origin issue: #8666
Flow we usually practice (documented at CONTRIBUTING.md) is that first we agree on implementation spec and it's after that when we jump to implementation.
I understand that some things are hard to resolve without actually trying to implement the solution, but in such case best if outcome of a tries is signaled at the issue spec with comments as e.g. X is probably better to be approached via Y, due A and B, and not proposed via PR's.
Currently this PR derives from spec in many places and it's hard for me to understand why. If you feel that spec at #8666 is insufficient can you comment over there what's missing? It'll be great if over there we first clarify all details, and only after this PR matches the spec we jump into reviewing it.
| individually: this.serverless.service.package.individually, | ||
| artifactDirectoryName: this.serverless.service.package.artifactDirectoryName, | ||
| deploymentDirectoryPrefix: this.serverless.service.package.deploymentDirectoryPrefix, | ||
| timestamp: this.serverless.service.package.timestamp, |
There was a problem hiding this comment.
My previous idea to rely on compiled Cloudformation template failed due to the inconsistency between layers and lambda functions and also separate approach to custom resources
Do you mean that it's difficult to retrieve generated paths for those resources from CF template?
Ideally if any deviations from specifications are signaled with proper reasoning at the origin issue: #8666
Flow we usually practice (documented at CONTRIBUTING.md) is that first we agree on implementation spec and it's after that when we jump to implementation.
I understand that some things are hard to resolve without actually trying to implement the solution, but in such case best if outcome of a tries is signaled at the issue spec with comments as e.g. X is probably better to be approached via Y, due A and B, and not proposed via PR's.
Currently this PR derives from spec in many places and it's hard for me to understand why. If you feel that spec at #8666 is insufficient can you comment over there what's missing? It'll be great if over there we first clarify all details, and only after this PR matches the spec we jump into reviewing it.
I appreciate this feedback and agree with that. I will take a step back and elaborate on the challenges faced within the issue thread. |
|
Hi guys, it looks like this PR stalled. Can I help? |
@remi00 I looked at 9904 and started with trying to merge in latest master. It appears there's some upstream work that accomplishes what you were after... I think. Perhaps take a look and tell me what I might be able to assist with. Best |
|
This is already far away from possibility of merging to main |
Closes: #8666
What it does?
S3.uploadwithS3.headObjectto avoid re-upload of already existing S3 artifactsWhat else is important?
More changes to come in upcoming PRs:
individually: truecan significantly reduce the deployment duration, especially in CI/CD use cases.