Skip to content

Commit 492f6af

Browse files
Merge pull request #45 from coreweave/cpierre/bitnami-upstream
feat(conf): add bitnami host and uri override
2 parents b178e2f + 3f83e3f commit 492f6af

4 files changed

Lines changed: 50 additions & 12 deletions

File tree

Dockerfile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# We start from my nginx fork which includes the proxy-connect module from tEngine
55
# Source is available at https://github.com/rpardini/nginx-proxy-connect-stable-alpine
66
# This is already multi-arch!
7-
ARG BASE_IMAGE="registry.gitlab.com/coreweave/nginx-proxy-connect-stable-alpine:v1.2.0"
7+
ARG BASE_IMAGE="registry.gitlab.com/coreweave/nginx-proxy-connect-stable-alpine:v1.5.0"
88
ARG DEBUG_IMAGE
99
# Could be "-debug"
1010

1111
ARG BASE_IMAGE_SUFFIX="${IMAGE_SUFFIX}"
1212
FROM ${BASE_IMAGE}${BASE_IMAGE_SUFFIX}
1313

1414
# Link image to original repository on GitHub
15-
LABEL org.opencontainers.image.source=https://github.com/rpardini/docker-registry-proxy
15+
LABEL org.opencontainers.image.source=https://github.com/coreweave/docker-registry-proxy
1616

1717
# apk packages that will be present in the final image both debug and release
1818
RUN apk add --no-cache --update bash ca-certificates-bundle coreutils openssl
@@ -23,11 +23,8 @@ ARG DO_DEBUG_BUILD="${DEBUG_IMAGE:-"0"}"
2323

2424
# Build mitmproxy via pip. This is heavy, takes minutes do build and creates a 90mb+ layer. Oh well.
2525
RUN [[ "a$DO_DEBUG_BUILD" == "a1" ]] && { echo "Debug build ENABLED." \
26-
&& apk add --no-cache --update su-exec cargo bsd-compat-headers git g++ libffi libffi-dev libstdc++ openssl-dev python3 python3-dev py3-pip py3-wheel py3-six py3-idna py3-certifi py3-setuptools \
27-
&& sed -i 's|v3\.\d*|edge|' /etc/apk/repositories \
28-
&& apk --no-cache upgrade rust \
26+
&& apk add --no-cache --update su-exec cargo bsd-compat-headers git g++ libffi libffi-dev libstdc++ openssl-dev python3 python3-dev py3-pip py3-wheel py3-six py3-idna py3-certifi py3-setuptools mitmproxy \
2927
&& rm /usr/lib/python3.*/EXTERNALLY-MANAGED \
30-
&& LDFLAGS=-L/lib pip install MarkupSafe mitmproxy \
3128
&& apk del --purge git g++ libffi-dev openssl-dev python3-dev py3-pip py3-wheel \
3229
&& rm -rf ~/.cache/pip \
3330
; } || { echo "Debug build disabled." ; }
@@ -149,8 +146,13 @@ ENV PROXY_CONNECT_READ_TIMEOUT="60s"
149146
ENV PROXY_CONNECT_CONNECT_TIMEOUT="60s"
150147
ENV PROXY_CONNECT_SEND_TIMEOUT="60s"
151148

152-
# Allow disabling IPV6 resolution, default to false
153-
ENV DISABLE_IPV6="false"
149+
# Allow disabling IPV6 resolution, default to true
150+
ENV DISABLE_IPV6="true"
151+
152+
# Bitnami dockerhub overrides
153+
ENV BITNAMI_DOCKERHUB_HOST_OVERRIDE="false"
154+
ENV BITNAMI_HOST=""
155+
ENV BITNAMI_LEGACY_DOCKERHUB_URI_REWRITE="false"
154156

155157
# 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.
156158
ENTRYPOINT ["/entrypoint.sh"]

entrypoint.sh

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ echo "DEBUG, determined RESOLVERS from /etc/resolv.conf: '$RESOLVERS'"
2525
conf=""
2626
for ONE_RESOLVER in ${RESOLVERS}; do
2727
echo "Possible resolver: $ONE_RESOLVER"
28-
conf="resolver $ONE_RESOLVER ipv6=off; "
28+
conf="resolver $ONE_RESOLVER; "
2929
done
3030

3131
echo "Final chosen resolver: $conf"
@@ -50,7 +50,7 @@ ALLDOMAINS=""
5050
echo -n "" > /etc/nginx/docker.intercept.map
5151

5252
# Some hosts/registries are always needed, but others can be configured in env var REGISTRIES
53-
for ONEREGISTRYIN in docker.caching.proxy.internal registry-1.docker.io auth.docker.io ${REGISTRIES}; do
53+
for ONEREGISTRYIN in docker.caching.proxy.internal index.docker.io registry-1.docker.io auth.docker.io ${REGISTRIES}; do
5454
ONEREGISTRY=$(echo ${ONEREGISTRYIN} | xargs) # Remove whitespace
5555
echo "Adding certificate for registry: $ONEREGISTRY"
5656
ALLDOMAINS="${ALLDOMAINS},DNS:${ONEREGISTRY}"
@@ -399,6 +399,37 @@ fi
399399
# Set worker processes if provided
400400
sed -i "s/worker_processes auto;/worker_processes ${WORKER_PROCESSES};/g" /etc/nginx/nginx.conf
401401

402+
echo "" > /etc/nginx/nginx.manifest.override.conf
403+
if [[ "a${BITNAMI_DOCKERHUB_HOST_OVERRIDE}" == "atrue" && ${BITNAMI_HOST} != "" ]]; then
404+
cat << EOD >> /etc/nginx/nginx.manifest.override.conf
405+
set \$overrideHost 0;
406+
if (\$request_uri ~ ^/v2/bitnami/) {
407+
set \$overrideHost 1;
408+
}
409+
if (\$host !~* (^|\.)docker\.io$) {
410+
set \$overrideHost 0;
411+
}
412+
if (\$overrideHost) {
413+
set \$targetHost "${BITNAMI_HOST}";
414+
}
415+
EOD
416+
fi
417+
418+
if [[ "a${BITNAMI_LEGACY_DOCKERHUB_URI_REWRITE}" == "atrue" ]]; then
419+
cat << EOD >> /etc/nginx/nginx.manifest.override.conf
420+
set \$doRewrite 0;
421+
if (\$request_uri ~ ^/v2/bitnami/) {
422+
set \$doRewrite 1;
423+
}
424+
if (\$host !~* (^|\.)docker\.io$) {
425+
set \$doRewrite 0;
426+
}
427+
if (\$doRewrite) {
428+
rewrite ^/v2/bitnami/(.*)$ /v2/bitnamilegacy\$1 break;
429+
}
430+
EOD
431+
fi
432+
402433
echo -e "\nFinal resolver configuration: ---"
403434
cat "${confpath}"
404435
echo -e "---\n"
@@ -407,4 +438,4 @@ echo "Testing nginx config..."
407438
${NGINX_BIN} -t
408439

409440
echo "Starting nginx! Have a nice day."
410-
${NGINX_BIN} -g "daemon off;"
441+
${NGINX_BIN} -g "daemon off;"

nginx.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ http {
8181
'"upstream_response_time":"$upstream_response_time",'
8282
'"host":"$host",'
8383
'"proxy_host":"$proxy_host",'
84-
'"upstream":"$upstream_addr"'
84+
'"upstream":"$upstream_addr",'
85+
'"user_agent":"$http_user_agent",'
86+
'"remote_addr":"$remote_addr",'
87+
'"upstream_bytes_received":"$upstream_response_length",'
88+
'"upstream_response_time":"$upstream_response_time"'
8589
'}';
8690

8791
gzip off;

nginx.manifest.common.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# nginx config fragment included in every manifest-related location{} block.
2+
include "/etc/nginx/nginx.manifest.override.conf";
23
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
34
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
45
proxy_pass https://$targetHost;

0 commit comments

Comments
 (0)