elementor / wp2static

WordPress static site generator for security, performance and cost benefits
https://wp2static.com
The Unlicense
1.39k stars 258 forks source link

Run wp2static on Kubernetes (unprivileged container) #903

Open drustan opened 11 months ago

drustan commented 11 months ago

For context, I have set up WordPress on Kubernetes using the Bitnami HELM chart. My goal is to be able to run a Kubernetes Job to execute a wp2static export.

The problem is that since executing containers as root in Kubernetes is discouraged, it prevents you from binding your web server (Apache) to ports 80/443. As an alternative, the container runs Apache on ports 8080/6443. To expose your website on ports 80/443 to the outside world, you then use an Ingress object, which basically is a TLS reverse proxy, to forward traffic to the container.

Considering this, when I run "wp2static detect" within my Wordpress container, I get this error: ''' $ wp wp2static detect [2023-08-02T16:58:01+02:00] Starting to detect WordPress site URLs. [02-Aug-2023 14:58:01 UTC] PHP Fatal error: Uncaught WP2StaticGuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to 127.0.0.1 port 443: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://127.0.0.1/robots.txt in /bitnami/wordpress/wp-content/plugins/wp2static/vendor/leonstafford/wp2staticguzzle/src/Handler/CurlFactory.php:210 '''

After some research, I tried to find a workaround with this : ''' $ wp --path=/ --http=https://127.0.0.1:6443 wp2static detect Error: Failed to get url 'https://127.0.0.1:6443': cURL error 60: SSL certificate problem: self signed certificate. ''' Unfortunately, I feel like I'm stuck here.

Do you see any easy workaround to this situation?

A potential workaround to address this would be to implement additional arguments into the wp2static CLI. One approach would be to allow users to set the address, port, and to bypass certificate verification directly from the command line.

For example, it could be something like this:

$ wp wp2static detect --address 127.0.0.1 --port 6443 --insecure
drustan commented 11 months ago

I see a reference to a variable wp2static_curl_port :

https://github.com/elementor/wp2static/blob/47980c2ad592c9b8b60d93d429fe5fa156034890/src/Crawler.php#L49

I don't see any mention of that in the documentation. How can I use it with the wp-cli command to set an alternative port?