Skip to content

Commit f977456

Browse files
authored
Merge pull request #3 from rpardini/master
feat(merge-upstream): merge upstream changes
2 parents d0101cb + 45ad55d commit f977456

File tree

7 files changed

+182
-9
lines changed

7 files changed

+182
-9
lines changed

.github/workflows/master-latest.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ jobs:
3636
uses: docker/login-action@v1
3737
with:
3838
registry: ghcr.io
39-
username: ${{ secrets.DOCKER_GITHUB_USERNAME }}
40-
password: ${{ secrets.DOCKER_GITHUB_PAT }}
39+
username: ${{ github.repository_owner }} # github username or org
40+
password: ${{ secrets.GITHUB_TOKEN }} # github actions builtin token. repo has to have pkg access.
4141

4242
# the arm64 is of course much slower due to qemu, so build and push amd64 **first**
4343
# due to the way manifests work, the gap between this and the complete push below

.github/workflows/tags.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ jobs:
4949
uses: docker/login-action@v1
5050
with:
5151
registry: ghcr.io
52-
username: ${{ secrets.DOCKER_GITHUB_USERNAME }}
53-
password: ${{ secrets.DOCKER_GITHUB_PAT }}
52+
username: ${{ github.repository_owner }} # github username or org
53+
password: ${{ secrets.GITHUB_TOKEN }} # github actions builtin token. repo has to have pkg access.
5454

5555
# the arm64 is of course much slower due to qemu, so build and push amd64 **first**
5656
# due to the way manifests work, the gap between this and the complete push below

Docker-Desktop-Windows.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Configure Docker Desktop on Windows to use the proxy and trust its certificate
2+
3+
1. Let's say you set up the proxy on host `192.168.66.72`. Get the certificate using a browser (go to <http://192.168.66.72:3128/ca.crt>) and save it as a file (e.g., to `d:\ca.crt`)
4+
5+
1. Add the certificate to Windows:
6+
7+
1. Double click the certificate
8+
1. Chose to _Install certificate..._, then click _Next_
9+
1. Chose _Current user_, then click _Next_
10+
1. Select option _Place all certificates in the following store_, click _browse_, and select _Trusted Root Certification Authorities_
11+
1. Proceed with Ok and confirm to install the certificate
12+
13+
If you are not using the WSL2 backend for Docker, then restart Docker Desktop and skip the next step.
14+
15+
1. If you are using WSL2 for Docker, then you need to add the certificate to WSL too:
16+
17+
1. Open a terminal
18+
19+
1. Check the name of the WSL distribution:
20+
21+
```
22+
PS C:\> wsl --list
23+
Windows Subsystem for Linux Distributions:
24+
docker-desktop (Default)
25+
docker-desktop-data
26+
```
27+
28+
The distribution we are looking for is _docker-desktop_. If you installed another distribution, such as Ubuntu, and configured Docker to use that, and proceed with that distribution instead.
29+
30+
1. Get a shell into WSL
31+
32+
```
33+
PS C:\> wsl --distribution docker-desktop
34+
XXXYYYZZZ:/tmp/docker-desktop-root/mnt/host/c#
35+
```
36+
37+
1. Copy the certificate into WSL and import it
38+
39+
Note: The directory and the command below are for the _docker-desktop_ WSL distribution. On other systems you might need to tweak the commands a little, but they seem to be the same for [Ubuntu](https://www.pmichaels.net/2020/12/29/add-certificate-into-wsl/) and [Debian](https://github.com/microsoft/WSL/issues/3161#issue-320777324) as well.
40+
41+
```
42+
XXXYYYZZZ:/tmp/docker-desktop-root/mnt/host/c# cp /mnt/host/d/ca.crt /usr/local/share/ca-certificates/
43+
XXXYYYZZZ:/tmp/docker-desktop-root/mnt/host/c# update-ca-certificates
44+
WARNING: ca-certificates.crt does not contain exactly one certificate or CRL: skipping
45+
```
46+
47+
Don't mind the warning, the operation still succeeded.
48+
49+
1. We are done with WSL, you can `exit` this shell
50+
51+
1. Configure the proxy in Docker Desktop:
52+
53+
1. Open Docker Desktop settings
54+
1. Go to _Resources/Proxies_
55+
1. Enable the proxy and set `http://192.168.66.72:3128` as both the HTTP and HTTPS URL.
56+
57+
1. Done. Verify that pulling works:
58+
59+
```
60+
# execute this in a Windows shell, not in WSL
61+
docker pull hello-world
62+
```
63+
64+
You can check the logs of the proxy to confirm that it was used.
65+
66+
If pulling does not work and complains about not trusting the certificate then Docker and/or the WSL distribution might need a restart. You might try restarting Docker, or you can restart Windows too to force WSL to restart.

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# We start from my nginx fork which includes the proxy-connect module from tEngine
22
# Source is available at https://github.com/rpardini/nginx-proxy-connect-stable-alpine
33
# This is already multi-arch!
4-
ARG BASE_IMAGE="docker.io/rpardini/nginx-proxy-connect-stable-alpine:nginx-1.18.0-alpine-3.12.1"
4+
ARG BASE_IMAGE="docker.io/rpardini/nginx-proxy-connect-stable-alpine:nginx-1.20.1-alpine-3.12.7"
55
# Could be "-debug"
66
ARG BASE_IMAGE_SUFFIX=""
77
FROM ${BASE_IMAGE}${BASE_IMAGE_SUFFIX}
@@ -97,6 +97,11 @@ ENV MANIFEST_CACHE_DEFAULT_TIME="1h"
9797
# Should we allow actions different than pull, default to false.
9898
ENV ALLOW_PUSH="false"
9999

100+
# If push is allowed, buffering requests can cause issues on slow upstreams.
101+
# If you have trouble pushing, set this to false first, then fix remainig timouts.
102+
# Default is true to not change default behavior.
103+
ENV PROXY_REQUEST_BUFFERING="true"
104+
100105
# Timeouts
101106
# ngx_http_core_module
102107
ENV SEND_TIMEOUT="60s"

README.md

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ for this to work it requires inserting a root CA certificate into system trusted
8787
- `hostname`s listed here should be listed in the REGISTRIES environment as well, so they can be intercepted.
8888
- Env `AUTH_REGISTRIES_DELIMITER` to change the separator between authentication info. By default, a space: "` `". If you use keys that contain spaces (as with Google Cloud Registry), you should update this variable, e.g. setting it to `AUTH_REGISTRIES_DELIMITER=";;;"`. In that case, `AUTH_REGISTRIES` could contain something like `registry1.com:user1:pass1;;;registry2.com:user2:pass2`.
8989
- Env `AUTH_REGISTRY_DELIMITER` to change the separator between authentication info *parts*. By default, a colon: "`:`". If you use keys that contain single colons, you should update this variable, e.g. setting it to `AUTH_REGISTRIES_DELIMITER=":::"`. In that case, `AUTH_REGISTRIES` could contain something like `registry1.com:::user1:::pass1 registry2.com:::user2:::pass2`.
90+
- Env `PROXY_REQUEST_BUFFERING`: If push is allowed, buffering requests can cause issues on slow upstreams.
91+
If you have trouble pushing, set this to `false` first, then fix remainig timeouts.
92+
Default is `true` to not change default behavior.
93+
ENV PROXY_REQUEST_BUFFERING="true"
9094
- Timeouts ENVS - all of them can pe specified to control different timeouts, and if not set, the defaults will be the ones from `Dockerfile`. The directives will be added into `http` block.:
9195
- SEND_TIMEOUT : see [send_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#send_timeout)
9296
- CLIENT_BODY_TIMEOUT : see [client_body_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_timeout)
@@ -176,6 +180,87 @@ docker run --rm --name docker_registry_proxy -it \
176180
rpardini/docker-registry-proxy:0.6.2
177181
```
178182

183+
### Kind Cluster
184+
185+
[Kind](https://github.com/kubernetes-sigs/kind/) is a tool for running local Kubernetes clusters using Docker container “nodes”.
186+
187+
Because cluster nodes are Docker containers, docker-registry-proxy needs to be in the same docker network.
188+
189+
Example joining the _kind_ docker network and using hostname _docker-registry-proxy_ as hostname :
190+
191+
```bash
192+
docker run --rm --name docker_registry_proxy -it \
193+
--net kind --hostname docker-registry-proxy \
194+
-p 0.0.0.0:3128:3128 -e ENABLE_MANIFEST_CACHE=true \
195+
-v $(pwd)/docker_mirror_cache:/docker_mirror_cache \
196+
-v $(pwd)/docker_mirror_certs:/ca \
197+
rpardini/docker-registry-proxy:0.6.2
198+
```
199+
200+
Now deploy your Kind cluster and then automatically configure the nodes with the following script :
201+
202+
```bash
203+
#!/bin/sh
204+
KIND_NAME=${1-kind}
205+
SETUP_URL=http://docker-registry-proxy:3128/setup/systemd
206+
pids=""
207+
for NODE in $(kind get nodes --name "$KIND_NAME"); do
208+
docker exec "$NODE" sh -c "\
209+
curl $SETUP_URL \
210+
| sed s/docker\.service/containerd\.service/g \
211+
| sed '/Environment/ s/$/ \"NO_PROXY=127.0.0.0\/8,10.0.0.0\/8,172.16.0.0\/12,192.168.0.0\/16\"/' \
212+
| bash" & pids="$pids $!" # Configure every node in background
213+
done
214+
wait $pids # Wait for all configurations to end
215+
```
216+
217+
### K3D Cluster
218+
219+
[K3d](https://k3d.io/) is similar to Kind but is based on k3s. In order to run with its registry you need to setup settings like shown below.
220+
221+
```sh
222+
# docker-registry-proxy
223+
docker run -d --name registry-proxy --restart=always \
224+
-v /tmp/registry-proxy/mirror_cache:/docker_mirror_cache \
225+
-v /tmp/registry-proxy/certs:/ca \
226+
rpardini/docker-registry-proxy:0.6.4
227+
228+
export PROXY_HOST=registry-proxy
229+
export PROXY_PORT=3128
230+
export NOPROXY_LIST="localhost,127.0.0.1,0.0.0.0,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.local,.svc"
231+
232+
cat <<EOF > /etc/k3d-proxy-config.yaml
233+
apiVersion: k3d.io/v1alpha3
234+
kind: Simple
235+
name: mycluster
236+
servers: 1
237+
agents: 0
238+
options:
239+
k3d:
240+
wait: true
241+
timeout: "60s"
242+
kubeconfig:
243+
updateDefaultKubeconfig: true
244+
switchCurrentContext: true
245+
env:
246+
- envVar: HTTP_PROXY=http://$PROXY_HOST:$PROXY_PORT
247+
nodeFilters:
248+
- all
249+
- envVar: HTTPS_PROXY=http://$PROXY_HOST:$PROXY_PORT
250+
nodeFilters:
251+
- all
252+
- envVar: NO_PROXY='$NOPROXY_LIST'
253+
nodeFilters:
254+
- all
255+
volumes:
256+
- volume: $REGISTRY_DIR/docker_mirror_certs/ca.crt:/etc/ssl/certs/registry-proxy-ca.pem
257+
nodeFilters:
258+
- all
259+
EOF
260+
261+
k3d cluster create --config /etc/k3d-proxy-config.yaml
262+
```
263+
179264
## Configuring the Docker clients using Docker Desktop for Mac
180265

181266
Separate instructions for Mac clients available in [this dedicated Doc Desktop for Mac document](Docker-for-Mac.md).
@@ -256,9 +341,9 @@ docker run --rm --name docker_registry_proxy -it
256341
- If you authenticate to a private registry and pull through the proxy, those images will be served to any client that can reach the proxy, even without authentication. *beware*
257342
- Repeat, **this will make your private images very public if you're not careful**.
258343
- ~~**Currently you cannot push images while using the proxy** which is a shame. PRs welcome.~~ **SEE `ALLOW_PUSH` ENV FROM USAGE SECTION.**
259-
- Setting this on Linux is relatively easy.
260-
- On Mac and Windows the CA-certificate part will be very different but should work in principle.
261-
- Please send PRs with instructions for Windows and Mac if you succeed!
344+
- Setting this on Linux is relatively easy.
345+
- On Mac follow the instructions [here](Docker-for-Mac.md).
346+
- On Windows follow the instructions [here](Docker-Desktop-Windows.md).
262347

263348
### Why not use Docker's own registry, which has a mirror feature?
264349

@@ -280,7 +365,7 @@ Yeah. Docker Inc should do it. So should NPM, Inc. Wonder why they don't. 😼
280365
### TODO:
281366

282367
- [x] Basic Docker-for-Mac set-up instructions
283-
- [ ] Basic Docker-for-Windows set-up instructions.
368+
- [x] Basic Docker-for-Windows set-up instructions.
284369
- [ ] Test and make auth work with quay.io, unfortunately I don't have access to it (_hint, hint, quay_)
285370
- [x] Hide the mitmproxy building code under a Docker build ARG.
286371
- [ ] "Developer Office" proxy scenario, where many developers on a fast LAN share a proxy for bandwidth and speed savings (already works for pulls, but messes up pushes, which developers tend to use a lot)

entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ echo -e "\nTimeout configs: ---"
254254
cat /etc/nginx/nginx.timeouts.config.conf
255255
echo -e "---\n"
256256

257+
# Request buffering
258+
echo "" > /etc/nginx/proxy.request.buffering.conf
259+
if [[ "a${PROXY_REQUEST_BUFFERING}" == "afalse" ]]; then
260+
cat << EOD > /etc/nginx/proxy.request.buffering.conf
261+
proxy_max_temp_file_size 0;
262+
proxy_request_buffering off;
263+
proxy_http_version 1.1;
264+
EOD
265+
fi
266+
267+
echo -e "\nRequest buffering: ---"
268+
cat /etc/nginx/proxy.request.buffering.conf
269+
echo -e "---\n"
270+
257271
# Upstream SSL verification.
258272
echo "" > /etc/nginx/docker.verify.ssl.conf
259273
if [[ "a${VERIFY_SSL}" == "atrue" ]]; then

nginx.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
227227

228228
proxy_read_timeout 900;
229229

230+
# Request buffering
231+
include /etc/nginx/proxy.request.buffering.conf;
232+
230233
# Use cache locking, with a huge timeout, so that multiple Docker clients asking for the same blob at the same time
231234
# will wait for the first to finish instead of doing multiple upstream requests.
232235
proxy_cache_lock on;

0 commit comments

Comments
 (0)