Skip to content

Commit 5158567

Browse files
authored
DRP-70: add timeoutes as ENVs, update README.md, update nginx config (#73)
Authored-by: Bulent <[email protected]>
1 parent c52c7d3 commit 5158567

File tree

4 files changed

+76
-12
lines changed

4 files changed

+76
-12
lines changed

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,20 @@ ENV MANIFEST_CACHE_DEFAULT_TIME="1h"
9797
# Should we allow actions different than pull, default to false.
9898
ENV ALLOW_PUSH="false"
9999

100+
# Timeouts
101+
# ngx_http_core_module
102+
ENV SEND_TIMEOUT="60s"
103+
ENV CLIENT_BODY_TIMEOUT="60s"
104+
ENV CLIENT_HEADER_TIMEOUT="60s"
105+
ENV KEEPALIVE_TIMEOUT="300s"
106+
# ngx_http_proxy_module
107+
ENV PROXY_READ_TIMEOUT="60s"
108+
ENV PROXY_CONNECT_TIMEOUT="60s"
109+
ENV PROXY_SEND_TIMEOUT="60s"
110+
# ngx_http_proxy_connect_module - external module
111+
ENV PROXY_CONNECT_READ_TIMEOUT="60s"
112+
ENV PROXY_CONNECT_CONNECT_TIMEOUT="60s"
113+
ENV PROXY_CONNECT_SEND_TIMEOUT="60s"
114+
100115
# Did you want a shell? Sorry, the entrypoint never returns, because it runs nginx itself. Use 'docker exec' if you need to mess around internally.
101116
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ for this to work it requires inserting a root CA certificate into system trusted
6363
## master/:latest is unstable/beta
6464

6565
- `:latest` and `:latest-debug` Docker tag is unstable, built from master, and amd64-only
66-
- Production/stable is `0.6.1`, see [0.6.1 tag on Github](https://github.com/rpardini/docker-registry-proxy/tree/0.6.1) - this image is multi-arch amd64/arm64
66+
- Production/stable is `0.6.2`, see [0.6.2 tag on Github](https://github.com/rpardini/docker-registry-proxy/tree/0.6.2) - this image is multi-arch amd64/arm64
6767
- The previous version is `0.5.0`, without any manifest caching, see [0.5.0 tag on Github](https://github.com/rpardini/docker-registry-proxy/tree/0.5.0) - this image is multi-arch amd64/arm64
6868

6969
## Also hosted on GitHub Container Registry (ghcr.io)
@@ -79,21 +79,34 @@ for this to work it requires inserting a root CA certificate into system trusted
7979
- Expose port 3128 to the network
8080
- Map volume `/docker_mirror_cache` for up to `CACHE_MAX_SIZE` (32gb by default) of cached images across all cached registries
8181
- Map volume `/ca`, the proxy will store the CA certificate here across restarts. **Important** this is security sensitive.
82+
- Env `ALLOW_PUSH` : This bypasses the proxy when pushing, default to false - if kept to false, pushing will not work. For more info see this [commit](https://github.com/rpardini/docker-registry-proxy/commit/536f0fc8a078d03755f1ae8edc19a86fc4b37fcf).
8283
- Env `CACHE_MAX_SIZE` (default `32g`): set the max size to be used for caching local Docker image layers. Use [Nginx sizes](http://nginx.org/en/docs/syntax.html).
8384
- Env `ENABLE_MANIFEST_CACHE`, see the section on pull rate limiting.
8485
- Env `REGISTRIES`: space separated list of registries to cache; no need to include DockerHub, its already done internally.
8586
- Env `AUTH_REGISTRIES`: space separated list of `hostname:username:password` authentication info.
8687
- `hostname`s listed here should be listed in the REGISTRIES environment as well, so they can be intercepted.
8788
- 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`.
8889
- 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+
- 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.:
91+
- SEND_TIMEOUT : see [send_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#send_timeout)
92+
- CLIENT_BODY_TIMEOUT : see [client_body_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_timeout)
93+
- CLIENT_HEADER_TIMEOUT : see [client_header_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_header_timeout)
94+
- KEEPALIVE_TIMEOUT : see [keepalive_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout
95+
- PROXY_READ_TIMEOUT : see [proxy_read_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout)
96+
- PROXY_CONNECT_TIMEOUT : see [proxy_connect_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout)
97+
- PROXY_SEND_TIMEOUT : see [proxy_send_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout)
98+
- PROXY_CONNECT_READ_TIMEOUT : see [proxy_connect_read_timeout](https://github.com/chobits/ngx_http_proxy_connect_module#proxy_connect_read_timeout)
99+
- PROXY_CONNECT_CONNECT_TIMEOUT : see [proxy_connect_connect_timeout](https://github.com/chobits/ngx_http_proxy_connect_module#proxy_connect_connect_timeout)
100+
- PROXY_CONNECT_SEND_TIMEOUT : see [proxy_connect_send_timeout](https://github.com/chobits/ngx_http_proxy_connect_module#proxy_connect_send_timeout))
101+
89102

90103
### Simple (no auth, all cache)
91104
```bash
92105
docker run --rm --name docker_registry_proxy -it \
93106
-p 0.0.0.0:3128:3128 -e ENABLE_MANIFEST_CACHE=true \
94107
-v $(pwd)/docker_mirror_cache:/docker_mirror_cache \
95108
-v $(pwd)/docker_mirror_certs:/ca \
96-
rpardini/docker-registry-proxy:0.6.1
109+
rpardini/docker-registry-proxy:0.6.2
97110
```
98111

99112
### DockerHub auth
@@ -109,7 +122,7 @@ docker run --rm --name docker_registry_proxy -it \
109122
-v $(pwd)/docker_mirror_certs:/ca \
110123
-e REGISTRIES="k8s.gcr.io gcr.io quay.io your.own.registry another.public.registry" \
111124
-e AUTH_REGISTRIES="auth.docker.io:dockerhub_username:dockerhub_password your.own.registry:username:password" \
112-
rpardini/docker-registry-proxy:0.6.1
125+
rpardini/docker-registry-proxy:0.6.2
113126
```
114127

115128
### Simple registries auth (HTTP Basic auth)
@@ -137,7 +150,7 @@ docker run --rm --name docker_registry_proxy -it \
137150
-v $(pwd)/docker_mirror_certs:/ca \
138151
-e REGISTRIES="reg.example.com git.example.com" \
139152
-e AUTH_REGISTRIES="git.example.com:USER:PASSWORD" \
140-
rpardini/docker-registry-proxy:0.6.1
153+
rpardini/docker-registry-proxy:0.6.2
141154
```
142155

143156
### Google Container Registry (GCR) auth
@@ -160,7 +173,7 @@ docker run --rm --name docker_registry_proxy -it \
160173
-e AUTH_REGISTRIES_DELIMITER=";;;" \
161174
-e AUTH_REGISTRY_DELIMITER=":::" \
162175
-e AUTH_REGISTRIES="gcr.io:::_json_key:::$(cat servicekey.json);;;auth.docker.io:::dockerhub_username:::dockerhub_password" \
163-
rpardini/docker-registry-proxy:0.6.1
176+
rpardini/docker-registry-proxy:0.6.2
164177
```
165178

166179
## Configuring the Docker clients using Docker Desktop for Mac
@@ -188,10 +201,18 @@ Environment="HTTP_PROXY=http://192.168.66.72:3128/"
188201
Environment="HTTPS_PROXY=http://192.168.66.72:3128/"
189202
EOD
190203

204+
### UBUNTU
191205
# Get the CA certificate from the proxy and make it a trusted root.
192206
curl http://192.168.66.72:3128/ca.crt > /usr/share/ca-certificates/docker_registry_proxy.crt
193207
echo "docker_registry_proxy.crt" >> /etc/ca-certificates.conf
194208
update-ca-certificates --fresh
209+
###
210+
211+
### CENTOS
212+
# Get the CA certificate from the proxy and make it a trusted root.
213+
curl http://192.168.66.72:3128/ca.crt > /etc/pki/ca-trust/source/anchors/docker_registry_proxy.crt
214+
update-ca-trust
215+
###
195216

196217
# Reload systemd
197218
systemctl daemon-reload
@@ -223,7 +244,7 @@ docker run --rm --name docker_registry_proxy -it
223244
-p 0.0.0.0:3128:3128 -e ENABLE_MANIFEST_CACHE=true \
224245
-v $(pwd)/docker_mirror_cache:/docker_mirror_cache \
225246
-v $(pwd)/docker_mirror_certs:/ca \
226-
rpardini/docker-registry-proxy:0.6.1-debug
247+
rpardini/docker-registry-proxy:0.6.2-debug
227248
```
228249

229250
- `DEBUG=true` enables the mitmweb proxy between Docker clients and the caching layer, accessible on port 8081
@@ -234,7 +255,7 @@ docker run --rm --name docker_registry_proxy -it
234255

235256
- 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*
236257
- Repeat, **this will make your private images very public if you're not careful**.
237-
- **Currently you cannot push images while using the proxy** which is a shame. PRs welcome.
258+
- ~~**Currently you cannot push images while using the proxy** which is a shame. PRs welcome.~~ **SEE `ALLOW_PUSH` ENV FROM USAGE SECTION.**
238259
- Setting this on Linux is relatively easy.
239260
- On Mac and Windows the CA-certificate part will be very different but should work in principle.
240261
- Please send PRs with instructions for Windows and Mac if you succeed!

entrypoint.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ EOD
117117
}
118118
EOD
119119

120-
echo "Manifest caching config: ---"
120+
echo -e "\nManifest caching config: ---\n"
121121
cat /etc/nginx/nginx.manifest.caching.config.conf
122122
echo "---"
123123

@@ -201,6 +201,33 @@ if [[ "a${DEBUG_NGINX}" == "atrue" ]]; then
201201
NGINX_BIN="/usr/sbin/nginx-debug"
202202
fi
203203

204+
205+
# Timeout configurations
206+
echo "" > /etc/nginx/nginx.timeouts.config.conf
207+
cat <<EOD >>/etc/nginx/nginx.timeouts.config.conf
208+
# Timeouts
209+
210+
# ngx_http_core_module
211+
keepalive_timeout ${KEEPALIVE_TIMEOUT};
212+
send_timeout ${SEND_TIMEOUT};
213+
client_body_timeout ${CLIENT_BODY_TIMEOUT};
214+
client_header_timeout ${CLIENT_HEADER_TIMEOUT};
215+
216+
# ngx_http_proxy_module
217+
proxy_read_timeout ${PROXY_READ_TIMEOUT};
218+
proxy_connect_timeout ${PROXY_CONNECT_TIMEOUT};
219+
proxy_send_timeout ${PROXY_SEND_TIMEOUT};
220+
221+
# ngx_http_proxy_connect_module - external module
222+
proxy_connect_read_timeout ${PROXY_CONNECT_READ_TIMEOUT};
223+
proxy_connect_connect_timeout ${PROXY_CONNECT_CONNECT_TIMEOUT};
224+
proxy_connect_send_timeout ${PROXY_CONNECT_SEND_TIMEOUT};
225+
EOD
226+
227+
echo -e "\nTimeout configs: ---"
228+
cat /etc/nginx/nginx.timeouts.config.conf
229+
echo -e "---\n"
230+
204231
# Upstream SSL verification.
205232
echo "" > /etc/nginx/docker.verify.ssl.conf
206233
if [[ "a${VERIFY_SSL}" == "atrue" ]]; then
@@ -217,7 +244,6 @@ else
217244
echo "Upstream SSL certificate verification is DISABLED."
218245
fi
219246

220-
221247
echo "Testing nginx config..."
222248
${NGINX_BIN} -t
223249

nginx.conf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ http {
1414
map_hash_bucket_size 128;
1515
include /etc/nginx/mime.types;
1616
default_type application/octet-stream;
17+
18+
# Include nginx timeout configs
19+
include /etc/nginx/nginx.timeouts.config.conf;
1720

1821
# Use a debug-oriented logging format.
1922
log_format debugging escape=json
@@ -73,7 +76,6 @@ http {
7376
'"upstream":"$upstream_addr"'
7477
'}';
7578

76-
keepalive_timeout 300;
7779
gzip off;
7880

7981
# Entrypoint generates the proxy_cache_path here, so it is configurable externally.
@@ -131,7 +133,7 @@ http {
131133
# The proxy director layer, listens on 3128
132134
server {
133135
listen 3128;
134-
server_name _;
136+
server_name proxy_director_;
135137

136138
# dont log the CONNECT proxy.
137139
#access_log /var/log/nginx/access.log debug_proxy;
@@ -199,7 +201,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
199201
# actually could be 443 or 444, depending on debug. this is now generated by the entrypoint.
200202
listen 80 default_server;
201203
include /etc/nginx/caching.layer.listen;
202-
server_name _;
204+
server_name proxy_caching_;
203205

204206
# Do some tweaked logging.
205207
access_log /var/log/nginx/access.log tweaked;

0 commit comments

Comments
 (0)