Skip to content

Commit 3d59fef

Browse files
committed
Merge pull request #2825 from lorieri/proxy
feat(builder+docker+user-data): proxy settings
2 parents 19d0371 + 82574fc commit 3d59fef

10 files changed

Lines changed: 105 additions & 3 deletions

File tree

builder/image/bin/boot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# fail hard and fast even on pipelines
77
set -eo pipefail
88

9+
source /etc/environment_proxy
10+
911
# set debug based on envvar
1012
[[ $DEBUG ]] && set -x
1113

builder/image/bin/entry

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -eo pipefail
33

4+
source /etc/environment_proxy
5+
46
# START jpetazzo/dind wrapper
57

68
# First, make sure that cgroups are mounted correctly.

builder/image/slugbuilder/builder/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
set -eo pipefail
33

4+
source /etc/environment_proxy
45

56
if [[ "$1" == "-" ]]; then
67
slug_file="$1"

builder/image/slugrunner/runner/init

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -eo pipefail
33

4+
source /etc/environment_proxy
5+
46
## Load slug from Bind Mount, URL or STDIN
57

68
export HOME=/app

builder/image/templates/builder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fi
8787

8888
BUILD_OPTS=()
8989
BUILD_OPTS+='/usr/bin/docker'
90-
BUILD_OPTS+=' run '
90+
BUILD_OPTS+=' run -v /etc/environment_proxy:/etc/environment_proxy'
9191
# get application configuration
9292
BUILD_OPTS+=$(echo $RESPONSE | /app/bin/get-app-values)
9393

builder/tests/builder_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import (
88
"github.com/deis/deis/tests/dockercli"
99
"github.com/deis/deis/tests/etcdutils"
1010
"github.com/deis/deis/tests/utils"
11+
12+
"io/ioutil"
13+
"os"
1114
)
1215

1316
func TestBuilder(t *testing.T) {
1417
var err error
18+
var errfile error
1519
setkeys := []string{
1620
"/deis/registry/protocol",
1721
"/deis/registry/host",
@@ -31,6 +35,15 @@ func TestBuilder(t *testing.T) {
3135
"/deis/domains",
3236
"/deis/services",
3337
}
38+
setproxy := []byte("HTTP_PROXY=\nhttp_proxy=\n")
39+
40+
tmpfile, errfile := ioutil.TempFile("/tmp", "deis-test-")
41+
if errfile != nil {
42+
t.Fatal(errfile)
43+
}
44+
ioutil.WriteFile(tmpfile.Name(), setproxy, 0644)
45+
defer os.Remove(tmpfile.Name())
46+
3447
tag, etcdPort := utils.BuildTag(), utils.RandomPort()
3548
etcdName := "deis-etcd-" + tag
3649
cli, stdout, stdoutPipe := dockercli.NewClient()
@@ -52,7 +65,9 @@ func TestBuilder(t *testing.T) {
5265
"-e", "HOST="+host,
5366
"-e", "ETCD_PORT="+etcdPort,
5467
"-e", "EXTERNAL_PORT="+port,
55-
"--privileged", "deis/builder:"+tag)
68+
"--privileged",
69+
"-v", tmpfile.Name()+":/etc/environment_proxy",
70+
"deis/builder:"+tag)
5671
}()
5772
dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-builder running")
5873
if err != nil {

contrib/coreos/user-data.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ write_files:
8989
- path: /etc/systemd/system/docker.service.d/50-insecure-registry.conf
9090
content: |
9191
[Service]
92+
EnvironmentFile=/etc/environment_proxy
9293
Environment="DOCKER_OPTS=--insecure-registry 10.0.0.0/8 --insecure-registry 172.16.0.0/12 --insecure-registry 192.168.0.0/16 --insecure-registry 100.64.0.0/10"
9394
- path: /run/deis/bin/get_image
9495
permissions: '0755'
@@ -141,3 +142,14 @@ write_files:
141142
TOOLBOX_DOCKER_IMAGE=ubuntu-debootstrap
142143
TOOLBOX_DOCKER_TAG=14.04
143144
TOOLBOX_USER=root
145+
- path: /etc/environment_proxy
146+
owner: core
147+
content: |
148+
HTTP_PROXY=
149+
HTTPS_PROXY=
150+
ALL_PROXY=
151+
NO_PROXY=
152+
http_proxy=
153+
https_proxy=
154+
all_proxy=
155+
no_proxy=

deisctl/units/deis-builder.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ExecStartPre=/bin/sh -c "docker inspect deis-builder-data >/dev/null 2>&1 || doc
88
ExecStartPre=/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/builder` && docker history $IMAGE >/dev/null || docker pull $IMAGE"
99
ExecStartPre=/bin/sh -c "docker inspect deis-builder >/dev/null && docker rm -f deis-builder || true"
1010
ExecStartPre=-/bin/sh -c "/sbin/losetup -f"
11-
ExecStart=/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/builder` && docker run --name deis-builder --rm -p 2223:22 --volumes-from=deis-builder-data -c 800 -e EXTERNAL_PORT=2223 -e HOST=$COREOS_PRIVATE_IPV4 --privileged $IMAGE"
11+
ExecStart=/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/builder` && docker run --name deis-builder --rm -p 2223:22 --volumes-from=deis-builder-data -c 800 -e EXTERNAL_PORT=2223 -e HOST=$COREOS_PRIVATE_IPV4 --privileged -v /etc/environment_proxy:/etc/environment_proxy $IMAGE"
1212
ExecStartPost=/bin/sh -c "echo 'Waiting for builder on 2223/tcp...' && until echo 'dummy-value' | ncat $COREOS_PRIVATE_IPV4 2223 >/dev/null 2>&1; do sleep 1; done"
1313
ExecStartPost=/usr/bin/docker exec deis-builder /usr/local/bin/push-images
1414
ExecStopPost=-/usr/bin/docker rm -f deis-builder

docs/managing_deis/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ Managing Deis
2323
security_considerations
2424
ssl-endpoints
2525
upgrading-deis
26+
using-a-proxy-server
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
:title: Using a Proxy Server
2+
:description: How to configure Deis to use a proxy server.
3+
4+
.. _using-a-proxy-server:
5+
6+
Using a Proxy Server
7+
====================
8+
9+
In some environments, HTTP connections must pass through a proxy. The Deis builder component supports
10+
proxies by respecting the proxy-related environment variables defined in ``/etc/environment_proxy``.
11+
12+
Additionally, Docker is also configured to respect the settings in this file.
13+
14+
By default, ``/etc/environment_proxy`` has all environment variables set to blank values:
15+
16+
.. code-block:: console
17+
18+
HTTP_PROXY=
19+
HTTPS_PROXY=
20+
ALL_PROXY=
21+
NO_PROXY=
22+
http_proxy=
23+
https_proxy=
24+
all_proxy=
25+
no_proxy=
26+
27+
.. note::
28+
29+
Proxy settings must be respected by the applications you're building.
30+
When using custom buildpacks, make sure they respect proxy settings.
31+
32+
33+
Configuring before server launch
34+
--------------------------------
35+
36+
Before provisioning the servers using the provision scripts in the Deis repository, edit
37+
``contrib/coreos/user-data.example`` and replace the contents of the file to suit your environment.
38+
39+
For example:
40+
41+
.. code-block:: console
42+
43+
- path: /etc/environment_proxy
44+
owner: core
45+
content: |
46+
HTTP_PROXY=http://proxy.example.com:3128
47+
HTTPS_PROXY=http://proxy.example.com:3128
48+
ALL_PROXY=http://proxy.example.com:3128
49+
NO_PROXY="127.0.0.1,localhost,.example.com"
50+
http_proxy=http://proxy.example.com:3128
51+
https_proxy=http://proxy.example.com:3128
52+
all_proxy=http://proxy.example.com:3128
53+
no_proxy="127.0.0.1,localhost,.example.com"
54+
55+
After running ``make discovery-url`` and provisioning your servers, the platform will come up with
56+
your proxy settings.
57+
58+
Configuring after server launch
59+
-------------------------------
60+
61+
It's also possible to configure these settings after the server has been provisioned, but this will
62+
result in downtime of the Deis platform as components are restarted.
63+
64+
You'll need to edit ``/etc/environment_proxy`` on all CoreOS hosts (as the builder component can
65+
be relocated to any host in the cluster). Then, restart Docker with ``sudo systemctl restart docker``
66+
and monitor Deis components with ``deisctl list``. It may be necessary to restart components
67+
if they do not recover automatically from the Docker restart.

0 commit comments

Comments
 (0)