Skip to content

Commit 75cba4f

Browse files
feat(http_scheme): Allow to force http for some registries
1 parent 9db22a6 commit 75cba4f

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ if [[ ${AUTH_REGISTRIES+x} ]]; then
9090
done
9191
fi
9292

93+
# Target scheme interception. Used to force the http scheme of a registry host
94+
echo -n "" >/opt/openresty/nginx/conf/docker.targetScheme.map
95+
96+
if [[ ${FORCE_HTTP_REGISTRIES+x} ]]; then
97+
for ONEREGISTRYIN in ${FORCE_HTTP_REGISTRIES}; do
98+
ONEREGISTRY=$(echo ${ONEREGISTRYIN} | xargs) # Remove whitespace
99+
echo "${ONEREGISTRY} http;" >>/opt/openresty/nginx/conf/docker.targetScheme.map
100+
done
101+
fi
102+
93103
# create default config for the caching layer to listen on 8443.
94104
echo " listen 8443 ssl default_server;" >/opt/openresty/nginx/conf/caching.layer.listen
95105

nginx.conf

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ http {
3535
'"bytes_sent":"$body_bytes_sent",'
3636
'"host":"$host",'
3737
'"proxy_host":"$proxy_host",'
38-
'"upstream":"$upstream_addr"'
38+
'"upstream":"$upstream_addr",'
39+
'"scheme_upstream":"$targetScheme",'
3940
'"upstream_status":"$upstream_status",'
4041
'"ssl_protocol":"$ssl_protocol",'
4142
'"connect_host":"$connect_host",'
4243
'"connect_port":"$connect_port",'
4344
'"connect_addr":"$connect_addr",'
4445
'"upstream_http_location":"$upstream_http_location",'
4546
'"upstream_cache_status":"$upstream_cache_status",'
46-
'"http_authorization":"$http_authorization",'
47+
'"http_authorization":"$http_authorization"'
4748
'}';
4849

4950
log_format debug_proxy escape=json
@@ -56,15 +57,16 @@ http {
5657
'"bytes_sent":"$body_bytes_sent",'
5758
'"host":"$host",'
5859
'"proxy_host":"$proxy_host",'
59-
'"upstream":"$upstream_addr"'
60+
'"upstream":"$upstream_addr",'
61+
'"scheme_upstream":"$targetScheme",'
6062
'"upstream_status":"$upstream_status",'
6163
'"ssl_protocol":"$ssl_protocol",'
6264
'"connect_host":"$connect_host",'
6365
'"connect_port":"$connect_port",'
6466
'"connect_addr":"$connect_addr",'
6567
'"upstream_http_location":"$upstream_http_location",'
6668
'"upstream_cache_status":"$upstream_cache_status",'
67-
'"http_authorization":"$http_authorization",'
69+
'"http_authorization":"$http_authorization"'
6870
'}';
6971

7072
log_format tweaked escape=json
@@ -79,7 +81,8 @@ http {
7981
'"upstream_response_time":"$upstream_response_time",'
8082
'"host":"$host",'
8183
'"proxy_host":"$proxy_host",'
82-
'"upstream":"$upstream_addr"'
84+
'"upstream":"$upstream_addr",'
85+
'"scheme_upstream":"$targetScheme"'
8386
'}';
8487

8588
gzip off;
@@ -97,6 +100,13 @@ http {
97100
default $host;
98101
}
99102

103+
# A map to force http scheme for some docker registries if needed.
104+
map $host $targetScheme {
105+
hostnames;
106+
include /opt/openresty/nginx/conf/docker.targetScheme.map;
107+
default https;
108+
}
109+
100110
# A map to enable authentication to some specific docker registries.
101111
# This is auto-generated by the entrypoint.sh based on environment variables
102112
map $host $dockerAuth {
@@ -287,7 +297,7 @@ http {
287297

288298
# by default, dont cache anything.
289299
location / {
290-
proxy_pass https://$targetHost;
300+
proxy_pass $targetScheme://$targetHost;
291301
proxy_cache off;
292302
}
293303
}

nginx.manifest.common.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# nginx config fragment included in every manifest-related location{} block.
22
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
33
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
4-
proxy_pass https://$targetHost;
4+
proxy_pass $targetScheme://$targetHost;
55
proxy_cache cache;
66
proxy_cache_key $uri;
77
proxy_intercept_errors on;

0 commit comments

Comments
 (0)