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

Support alternative transport or proxy #408

Closed
skyred opened this issue Jun 9, 2022 · 9 comments
Closed

Support alternative transport or proxy #408

skyred opened this issue Jun 9, 2022 · 9 comments

Comments

@skyred
Copy link
Contributor

skyred commented Jun 9, 2022

When ALL_PROXY, HTTPS_PROXY, HTTP_PROXY are present in the environment, composer can work with them, but patching stops working, below is an example error message:

Gathering patches for dependencies. This might take a minute.
  - Installing drupal/commerce_stripe (dev-1.x 66b6b4d): Cloning 66b6b4de23 from cache
  - Applying patches for drupal/commerce_stripe
    https://www.drupal.org/files/issues/2021-10-04/commerce_stripe-allow-off_session-payment-intents-for-recurring-payments-3171408-34.patch (Allow off_session payment intents for recurring payments)
   Could not apply patch! Skipping. The error was: The "https://www.drupal.org/files/issues/2021-10-04/commerce_stripe-allow-off_session-payment-intents-for-recurring-payments-3171408-34.patch" file could not be downloaded: Failed to open stream: Unable to find the socket transport "socks5" - did you forget to enable it when you configured PHP?

                                                                                                                                                                                 
  [Exception]                                                                                                                                                                    
  Cannot apply patch Allow off_session payment intents for recurring payments (https://www.drupal.org/files/issues/2021-10-04/commerce_stripe-allow-off_session-payment-intents  
  -for-recurring-payments-3171408-34.patch)!

Probably, this is caused by http client isn't configured to support proxy (socks5), the solution is to find the code, and copy it from composer.

@noot-to-the-noot
Copy link

I am currently running into a similar problem with a HTTP(S) proxy, I've also tried SOCKS5 but to no avail.

Composer is running fine after the installation inside the php/8.1-fpm-bullseye docker container.
This image contains cURL and OpenSSL bundled with PHP so composer can use cURL to connect to the proxy and install everything usually (as it seems so far from my testing).

Now comes this plugin. I've dug trough some of the error messages and some code to come across this line here

$downloader = new RemoteFilesystem($this->io, $this->composer->getConfig());

It creates it's own RemoteFilesystem instance that apparently isn't aware of any proxy usage and thus fails in an error (for me: "You must enable the curl extension to make https requests through a secure proxy.").

I have zero knowledge of PHP but if possible can you use the code used by composer, or get composer to download those resources for you? Otherwise here is the merge that added proxy capabilities to composer, it's quite a old so maybe you're better of looking into the current source code here.

Hope to hear back and if I can help in any way just contact me!

skyred added a commit to skyred/composer-patches that referenced this issue Jan 20, 2023
@skyred
Copy link
Contributor Author

skyred commented Jan 20, 2023

@noot-to-the-noot Thanks a lot for digging into the details. They are very helpful. I was able to put together a PR to fix the issue.

@skyred
Copy link
Contributor Author

skyred commented Jan 26, 2023

This feature can improve a lot of developers' lives in China and some behind corporate firewall. @danepowell Can you please consider roll a minor release? or merge it to 1.x-dev?

Because most packages who use patches specified "cweagans/composer-patches": "~1.0" in their composer.json, there is no easy way to switch a project to use dev-master branch right now to use proxies.

danepowell added a commit to danepowell/composer-patches that referenced this issue Jan 26, 2023
danepowell added a commit that referenced this issue Jan 26, 2023
@danepowell
Copy link
Collaborator

I merged it into 1.x. Since there's no automated tests on 1.x, this needs extensive manual testing. Can the folks in this thread please test and confirm this works as expected on 1.x-dev before we cut a new release?

@cweagans
Copy link
Owner

cweagans commented Feb 6, 2023

Just to confirm: I have maintained this functionality in #447 as well, so this should continue working in 2.x.

@cweagans
Copy link
Owner

cweagans commented Feb 7, 2023

Let us know if this doesn't work for you and we can reopen. Closing for now.

@cweagans cweagans closed this as completed Feb 7, 2023
@skyred
Copy link
Contributor Author

skyred commented Feb 10, 2023

I merged it into 1.x. Since there's no automated tests on 1.x, this needs extensive manual testing. Can the folks in this thread please test and confirm this works as expected on 1.x-dev before we cut a new release?

Yes, I tested it. It is working in 1.x. All I need to do is composer require cweagans/composer-patches 1.x-dev . @danepowell Thanks again

@cweagans
Copy link
Owner

@skyred if you can provide some details about how you tested, that would be helpful. I'd be open to tagging a 1.x release so you don't have to use a dev version.

@skyred
Copy link
Contributor Author

skyred commented Feb 13, 2023

For testing, one would need a proxy server. It could be a remote or at your local. Then, you can up those environment variables, so curl, composer and composer-patches would automatically use proxy.

ALL_PROXY=socks5://host.docker.internal:9999
HTTP_PROXY=socks5://host.docker.internal:9999
HTTPS_PROXY=socks5://host.docker.internal:9999

Above example is to let docker container use a socks5 proxy on the host machine at port 9999

With the current stable composer-patches, one would run into errors like what described at the beginning of this issue, after switching to 1.x-dev, it simply works.

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

No branches or pull requests

4 participants