Skip to content

Commit

Permalink
Make the docker proxy a standalone binary not a re-exec
Browse files Browse the repository at this point in the history
This reduces memory usage with a lot of docker proxy processes.
On Docker for Mac we are currently carrying a patch to replace
the binary as we modify it to forward ports to the Mac rather
than the Linux VM, this allows us to simply replace this binary
in our packaging with one that has a compatible interface. This
patch does not provide an easy way to substitute a binary as
the interface is complex and there are few use cases, but where
needed this can be done.

Signed-off-by: Justin Cormack <[email protected]>
  • Loading branch information
justincormack committed Jul 7, 2016
1 parent 656c66d commit 0682468
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 549 deletions.
3 changes: 3 additions & 0 deletions hack/.vendor-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ clean() {
findArgs+=( -path "vendor/src/$import" )
done

# The docker proxy command is built from libnetwork
findArgs+=( -or -path vendor/src/github.com/docker/libnetwork/cmd/proxy )

local IFS=$'\n'
local prune=( $($find vendor -depth -type d -not '(' "${findArgs[@]}" ')') )
unset IFS
Expand Down
1 change: 1 addition & 0 deletions hack/make/.binary-setup
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

DOCKER_CLIENT_BINARY_NAME='docker'
DOCKER_DAEMON_BINARY_NAME='dockerd'
DOCKER_PROXY_BINARY_NAME='docker-proxy'
1 change: 1 addition & 0 deletions hack/make/.build-deb/rules
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ override_dh_auto_install:
mkdir -p debian/docker-engine/usr/bin
cp -aT "$$(readlink -f bundles/$(VERSION)/dynbinary-client/docker)" debian/docker-engine/usr/bin/docker
cp -aT "$$(readlink -f bundles/$(VERSION)/dynbinary-daemon/dockerd)" debian/docker-engine/usr/bin/dockerd
cp -aT "$$(readlink -f bundles/$(VERSION)/dynbinary-daemon/docker-proxy)" debian/docker-engine/usr/bin/docker-proxy
cp -aT /usr/local/bin/containerd debian/docker-engine/usr/bin/docker-containerd
cp -aT /usr/local/bin/containerd-shim debian/docker-engine/usr/bin/docker-containerd-shim
cp -aT /usr/local/bin/ctr debian/docker-engine/usr/bin/docker-containerd-ctr
Expand Down
1 change: 1 addition & 0 deletions hack/make/.build-rpm/docker-engine.spec
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export DOCKER_GITCOMMIT=%{_gitcommit}
install -d $RPM_BUILD_ROOT/%{_bindir}
install -p -m 755 bundles/%{_origversion}/dynbinary-client/docker-%{_origversion} $RPM_BUILD_ROOT/%{_bindir}/docker
install -p -m 755 bundles/%{_origversion}/dynbinary-daemon/dockerd-%{_origversion} $RPM_BUILD_ROOT/%{_bindir}/dockerd
install -p -m 755 bundles/%{_origversion}/dynbinary-daemon/docker-proxy-%{_origversion} $RPM_BUILD_ROOT/%{_bindir}/docker-proxy

# install containerd
install -p -m 755 /usr/local/bin/containerd $RPM_BUILD_ROOT/%{_bindir}/docker-containerd
Expand Down
3 changes: 3 additions & 0 deletions hack/make/binary-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ set -e
export BINARY_SHORT_NAME="$DOCKER_DAEMON_BINARY_NAME"
export SOURCE_PATH='./cmd/dockerd'
source "${MAKEDIR}/.binary"
export BINARY_SHORT_NAME="$DOCKER_PROXY_BINARY_NAME"
export SOURCE_PATH='./vendor/src/github.com/docker/libnetwork/cmd/proxy'
source "${MAKEDIR}/.binary"
copy_containerd "$DEST" 'hash'
)
3 changes: 3 additions & 0 deletions hack/make/dynbinary-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ set -e
export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary
export BUILDFLAGS=( "${BUILDFLAGS[@]/static_build /}" ) # we're not building a "static" binary here
source "${MAKEDIR}/.binary"
export BINARY_SHORT_NAME='docker-proxy'
export SOURCE_PATH='./vendor/src/github.com/docker/libnetwork/cmd/proxy'
source "${MAKEDIR}/.binary"
)
18 changes: 18 additions & 0 deletions hack/make/gccgo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ BINARY_NAME="dockerd-$VERSION"
BINARY_EXTENSION="$(binary_extension)"
BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"

PROXY_NAME="docker-proxy-$VERSION"
PROXY_FULLNAME="$PROXY_NAME$BINARY_EXTENSION"

CLIENTBIN_NAME="docker-$VERSION"
CLIENTBIN_FULLNAME="$CLIENTBIN_NAME$BINARY_EXTENSION"

Expand All @@ -29,6 +32,21 @@ go build -compiler=gccgo \
echo "Created binary: $DEST/$BINARY_FULLNAME"
ln -sf "$BINARY_FULLNAME" "$DEST/dockerd$BINARY_EXTENSION"

go build -compiler=gccgo \
-o "$DEST/$PROXY_FULLNAME" \
"${BUILDFLAGS[@]}" \
-gccgoflags "
-g
$EXTLDFLAGS_STATIC
-Wl,--no-export-dynamic
-ldl
-pthread
" \
./vendor/src/github.com/docker/libnetwork/cmd/proxy

echo "Created binary: $DEST/$PROXY_FULLNAME"
ln -sf "$PROXY_FULLNAME" "$DEST/docker-proxy$BINARY_EXTENSION"

copy_containerd "$DEST" "hash"
hash_files "$DEST/$BINARY_FULLNAME"

Expand Down
1 change: 1 addition & 0 deletions hack/make/install-binary-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ rm -rf "$DEST"
DEST="$(dirname $DEST)/binary-daemon"
source "${MAKEDIR}/.binary-setup"
install_binary "${DEST}/${DOCKER_DAEMON_BINARY_NAME}"
install_binary "${DEST}/${DOCKER_PROXY_BINARY_NAME}"
)
5 changes: 5 additions & 0 deletions hack/make/tgz
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ for d in "$CROSS/"*/*; do

BINARY_NAME="${DOCKER_CLIENT_BINARY_NAME}-$VERSION"
DAEMON_BINARY_NAME="${DOCKER_DAEMON_BINARY_NAME}-$VERSION"
PROXY_BINARY_NAME="${DOCKER_PROXY_BINARY_NAME}-$VERSION"
BINARY_EXTENSION="$(export GOOS && binary_extension)"
if [ "$GOOS" = 'windows' ]; then
# if windows use a zip, not tgz
Expand All @@ -29,6 +30,7 @@ for d in "$CROSS/"*/*; do
fi
BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
DAEMON_BINARY_FULLNAME="$DAEMON_BINARY_NAME$BINARY_EXTENSION"
PROXY_BINARY_FULLNAME="$PROXY_BINARY_NAME$BINARY_EXTENSION"
mkdir -p "$DEST/$GOOS/$GOARCH"
TGZ="$DEST/$GOOS/$GOARCH/$BINARY_NAME$BUNDLE_EXTENSION"

Expand All @@ -47,6 +49,9 @@ for d in "$CROSS/"*/*; do
if [ -f "$d/$DAEMON_BINARY_FULLNAME" ]; then
cp -L "$d/$DAEMON_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_DAEMON_BINARY_NAME}${BINARY_EXTENSION}"
fi
if [ -f "$d/$PROXY_BINARY_FULLNAME" ]; then
cp -L "$d/$PROXY_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_PROXY_BINARY_NAME}${BINARY_EXTENSION}"
fi

# copy over all the containerd binaries
copy_containerd $TAR_PATH
Expand Down
216 changes: 0 additions & 216 deletions pkg/proxy/network_proxy_test.go

This file was deleted.

37 changes: 0 additions & 37 deletions pkg/proxy/proxy.go

This file was deleted.

31 changes: 0 additions & 31 deletions pkg/proxy/stub_proxy.go

This file was deleted.

Loading

0 comments on commit 0682468

Please sign in to comment.