File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -121,8 +121,51 @@ http {
121121 alias /ca/ca.crt;
122122 }
123123
124- # @TODO: add a dynamic root path that generates instructions for usage on docker clients
125- }
124+ location /setup/systemd {
125+ add_header "Content-type" "text/plain" always;
126+ return 200 '
127+ set -e
128+
129+ if [ ! -d /etc/systemd ]; then
130+ echo "Not a systemd system"
131+ exit 1
132+ fi
133+
134+ if [[ $EUID -ne 0 ]]; then
135+ echo "Must be root to change system files"
136+ exit 1
137+ fi
138+
139+ if [[ $( systemctl is-active --quiet docker.service) -ne 0 ]]; then
140+ echo "Docker service missing"
141+ exit 1
142+ fi
143+
144+ mkdir -p /etc/systemd/system/docker.service.d
145+ cat << EOD > /etc/systemd/system/docker.service.d/http -proxy.conf
146+ [Service]
147+ Environment="HTTPS_PROXY=$scheme://$http_host/"
148+ EOD
149+
150+ # Get the CA certificate from the proxy and make it a trusted root.
151+ curl $scheme ://$http_host /ca.crt > /usr/share/ca-certificates/docker_registry_proxy.crt
152+ if fgrep -q "docker_registry_proxy.crt" /etc/ca-certificates.conf ; then
153+ echo "certificate refreshed"
154+ else
155+ echo "docker_registry_proxy.crt" >> /etc/ca-certificates.conf
156+ fi
157+
158+ update-ca-certificates --fresh
159+
160+ # Reload systemd
161+ systemctl daemon -reload
162+
163+ # Restart dockerd
164+ systemctl restart docker.service
165+ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
166+ ';
167+ } # end location /setup/systemd
168+ } # end server
126169
127170
128171 # The caching layer
You can’t perform that action at this time.
0 commit comments