diff --git a/README.md b/README.md index c02cdb9..01266a1 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,13 @@ Install this with `ddev get rfay/ddev-proxy-support` It installs a docker-compose.proxy.yaml which adds proxy capabilities to DDEV v1.19.4+ +With this setup you should be able to use `webimage_extra_packages` against a proxy, and you should also be able to `ddev ssh` into the web container and use curl and see it using the proxy. `curl -v -I ` is a good test. See also the [tests](tests/test.bats). + # Testing -Testing +Details about how to lab-test this are in [Lab-testing a proxied environment](lab-testing.md). + +You can also find public proxies of varying reliability at [spys](https://spys.one/free-proxy-list/US/) and other places, and of course you would never trust them with any traffic, but they're useful for testing. **Contributed and maintained by [@rfay](https://github.com/rfay) based on the original [ddev-contrib recipe](https://github.com/drud/ddev-contrib/tree/master/recipes/proxy)** diff --git a/lab-testing.md b/lab-testing.md new file mode 100644 index 0000000..f80abc7 --- /dev/null +++ b/lab-testing.md @@ -0,0 +1,16 @@ + +# Lab-testing a proxied environment + +I used Parallels on macOS for the test lab. + +* Created a Parallels VM proxy server with a simple tiny Ubuntu 22.04 server running [tinyproxy](https://tinyproxy.github.io/), which was shockingly simple to install and configure (`apt-get install tinyproxy`), very small configuration changes ([example /etc/tinyproxy/tinyproxy.conf](tinyproxy.conf)). I'll call this machine "proxy". +* Added an additional "host-only" interface in Parallels and added it to the proxy VM +* Set up Parallels to use the name of the VM as its hostname. You should now be able to `ping proxy.host-only` +* Used an existing (different) Ubuntu 22.04 Parallels VM as the ddev/docker environment and added the host only interface to it. I'll call this machine "workstation". +* Turned off the primary network interface in the workstation, so it had no direct network connectivity, verified that ping of internet addresses failed. +* Configured the workstation VM with system-wide proxy settings using the regular Ubuntu network setting GUI (in this case HTTP/HTTPS proxies using proxy.host-only:8888). +* Configured the Firefox browser on "workstation" to use the system-configured proxy and verified that it could now operate. +* Verified that curl against internet https locations now worked on the "workstation". +* Configured the docker server as in step 2 above, and verified that `docker pull ubuntu` now worked on "workstation" using the proxy. +* Configured the docker client as in step 3 above and verified that proxy setup was now right in the container by `ddev start`, `ddev ssh`, and using curl inside the container against an HTTPS website. +* Added the .ddev/web-build/Dockerfile from step 4 into the ddev project on the "workstation" and `ddev start`, then `ddev ssh` and `sudo apt-get update` and saw the update happen successfully, all using the proxy. diff --git a/tests/test.bats b/tests/test.bats index 57df666..5429855 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -1,14 +1,15 @@ setup() { set -eu -o pipefail + unset HTTP_PROXY HTTPS_PROXY http_proxy NO_PROXY export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." export TESTDIR=~/tmp/testproxysupport # Test proxy from random public proxies listed at https://spys.one/en/free-proxy-list/ # This may not be reliable, don't know. - export TESTPROXY=http://96.242.29.93:3128 + export TESTPROXY=http://67.212.186.101:80 mkdir -p $TESTDIR export PROJNAME=test-proxy-support export DDEV_NON_INTERACTIVE=true - ddev delete -Oy ${PROJNAME} || true + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true cd "${TESTDIR}" ddev config --project-name=${PROJNAME} ddev start @@ -30,12 +31,16 @@ teardown() { ddev debug refresh ddev start export HTTP_PROXY=${TESTPROXY} + export http_proxy=${HTTP_PROXY} # export HTTPS_PROXY=${TESTPROXY} export NO_PROXY=127.0.0.1 + # Make sure that we can install extra packages using the proxy ddev config --webimage-extra-packages=autojump ddev start ddev exec "echo \${HTTP_PROXY} | grep ${TESTPROXY}" grep "ENV.*HTTP_PROXY" .ddev/.webimageBuild/Dockerfile +# ddev exec curl -I -v https://example.com | grep "Uses proxy env variable http_proxy == '${HTTP_PROXY}'" + ddev exec "curl -I -v https://example.com |& grep 'Uses proxy env variable'" } @test "install from release" { @@ -46,10 +51,14 @@ teardown() { ddev debug refresh ddev start export HTTP_PROXY=${TESTPROXY} + export http_proxy=${HTTP_PROXY} # export HTTPS_PROXY=${TESTPROXY} export NO_PROXY=127.0.0.1 + # Make sure that we can install extra packages using the proxy ddev config --webimage-extra-packages=autojump ddev start ddev exec "echo \${HTTP_PROXY} | grep ${TESTPROXY}" grep "ENV.*HTTP_PROXY" .ddev/.webimageBuild/Dockerfile +# ddev exec curl -I -v https://example.com | grep "Uses proxy env variable http_proxy == '${HTTP_PROXY}'" + ddev exec "curl -I -v https://example.com |& grep 'Uses proxy env variable'" }