-
-
Notifications
You must be signed in to change notification settings - Fork 1.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: tarball url redirect #1688
Conversation
|
Codecov Report
@@ Coverage Diff @@
## 5.x #1688 +/- ##
======================================
Coverage ? 83.86%
======================================
Files ? 48
Lines ? 2597
Branches ? 602
======================================
Hits ? 2178
Misses ? 414
Partials ? 5 |
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.
@favoyang could you elaborate a bit what's the benefit of this? At this point, I don't see why Verdacccio should handle redirections and seems to me just a workaround for a specific scenario.
The first case is surely a specific (but common) scenario, but there's no way to implement without changing the verdaccio main repository. If we reject for this reason, maybe we could think about offering a alternative solution? The second case is a common practice for web application. |
Not necessarily a rejection, but rather start a discussion about what we are trying to solve and which other issues this creates. As I exposed him worth to research whether a filter plugin might solve this #1620 (comment) (example: https://verdaccio.org/docs/en/dev-plugins#api-1) I have the same concerns as @DanielRuf exposes here #1620 (comment) , once this flag is enabled you lose the ability to use the proxy (uplinks) for all packages since I see the flag The unique way to go I see is you filter the packument then the package manager will download from the location you provide, then is not required any change at Verdaccio, you can read more here about it #1161.
|
I see. the
So filter can change the meta data. But seems filter was only invoked by
The intention is to let user download from S3/CDN infrastructure directly.
The benefit of HTTP 302 is that, verdaccio still get the access, so it can trace the DL stats (not available yet, but a popular feature request). If I change the tarball URL using filter, verdaccio will not be able to trace the access. |
Update PR to handle uplinks
|
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
This would make my life so much easier, any chance of it going in? |
Your point of view is valuable, could you share more in detail? perhaps helps to move this on. |
Sure, basically, we have users around the world who need to access our internal npm registry. Currently we are running multiple instances of this in different parts of the world, and have to jump through some hoops regarding auth/vpn/internal networks etc. Ideally we'd be able to have the actual download of the tarballs happen via cloudfront signed urls. This would mean that we would only need to run a single instance of verdaccio, while still having the tarball downloads for users in India come from the cloudfront edge cache in Mumbai, etc. I realize this PR doesn't support signed urls for the redirect, but it's a big step in the right direction. |
We use the a javascript config, so if there was also const config = {
tarball_url_redirect: 'http://d111111abcdef8.cloudfront.net/${packageName}/${filename}',
tarball_url_redirect_signing_func(tarballUrl) {
const signedUrl = // use aws sdk to generate signed url
return signedUrl;
}
} That would let us do what we want, as described above. |
@gordlea Thanks for your comment. I didn't realize that the verdaccio configuration supports js format? If so, it can be simplified to
|
It's been months since my last update, I'd like to summarize the status of the PR. Is the request useful? Yes, it is necessary if you want to work with modern content delivery network infrastructure. Will this PR break the uplink feature? No. It only redirects the URL if the local tarball file exists. Otherwise, it will fall back to the default logic to query uplinks. Can it be implemented using the filter plugin? With a filter plugin, you can hijack the packument and modify it. However, it seems the filter plugin is only applied to the uplinks. The only method invokes Even if a filter plugin applied to all packages, the approach of modifying the packument directly to change the tarball URL will make it hard to implement download stats feature like #1201 or #1489, which requires all download requests go through verdaccio at the first place.
Any other options? Plugin-middleware seems another option if there's a way to get the local storage instance. If we do this, then the download stats feature have to be implemented as a middleware plugin as well, since it should process before the tarball redirect. Whether it worth doing more research here depends on how bad to put this PR into the core system. |
Any chance you might add this to the PR? |
@favoyang please take a look at: favoyang#1 |
As requested in PR feedback.
feat: allow function for config.tarball_url_redirect
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
@gordlea your patch merged, also synced with the master branch. Next, shall we continue the discussion like #1688 (comment)? |
Great, sounds good. |
Just FYI I'm going to be trying this branch out in production soon. |
I'm using it on production (before your contribution) for a few months, works for me. |
We've been running this in production for about 3 weeks with no issues now. |
the variable `credentials` was already declared before the tarball url tests.
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
We've been running this in prod since May 2020 now, with no issues. This PR is so powerful, it basically lets you create a global CDN from a single verdaccio instance. |
Thanks for the feedback, I added this PR to |
chore: merge master into branch tarball-url-redirect
I changed the base branch to 5.x. I guess this would be a more stable branch to track with. |
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.
LGTM thanks @favoyang this keep this rebased, it was a long way 👍🏼
Type: feature
The following has been addressed in the PR:
Description:
Part of verdaccio/monorepo/issues/250, redirect tarball URL based on
config.experiments.tarball_url_redirect
. Major usage is to rewriting the redirect tarball URL to a CDN server.