Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable proxy settings for kubernetes build and update docs #20398

Merged
merged 2 commits into from
Feb 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,19 @@ When building final release tars, they are first staged into `_output/release-st
## Proxy Settings


If you are behind a proxy, you need to edit `build/build-image/Dockerfile` and add proxy settings to execute command in that container correctly.
If you are behind a proxy, you need to export proxy settings for kubernetes build, the following environment variables should be defined.

example:
```
export KUBE_BUILD_HTTP_PROXY=http://username:password@proxyaddr:proxyport
export KUBE_BUILD_HTTPS_PROXY=http://username:password@proxyaddr:proxyport
```

`ENV http_proxy http://username:password@proxyaddr:proxyport`
Optionally, you can specify addresses of no proxy for kubernetes build, for example

`ENV https_proxy http://username:password@proxyaddr:proxyport`

Besides, to avoid integration test touch the proxy while connecting to local etcd service, you need to set

`ENV no_proxy 127.0.0.1`
```
export KUBE_BUILD_NO_PROXY=127.0.0.1
```
If you are using sudo to make kubernetes build for example make quick-release, you need run `sudo -E make quick-release` to pass the environment variables.

## TODOs

Expand Down
4 changes: 4 additions & 0 deletions build/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ MAINTAINER Joe Beda <jbeda@google.com>
ENV GOARM 5
ENV GOOS linux
ENV GOARCH amd64
ENV http_proxy KUBE_BUILD_HTTP_PROXY
ENV https_proxy KUBE_BUILD_HTTPS_PROXY
ENV no_proxy KUBE_BUILD_NO_PROXY


# work around 64MB tmpfs size in Docker 1.6
ENV TMPDIR /tmp.k8s
Expand Down
25 changes: 19 additions & 6 deletions build/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ function kube::build::prepare_docker_machine() {
kube::log::status "docker-machine was found."
docker-machine inspect "${DOCKER_MACHINE_NAME}" >/dev/null || {
kube::log::status "Creating a machine to build Kubernetes"
docker-machine create --driver "${DOCKER_MACHINE_DRIVER}" "${DOCKER_MACHINE_NAME}" > /dev/null || {
docker-machine create --driver "${DOCKER_MACHINE_DRIVER}" \
--engine-env HTTP_PROXY="${KUBE_BUILD_HTTP_PROXY:-}" \
--engine-env HTTPS_PROXY="${KUBE_BUILD_HTTPS_PROXY:-}" \
--engine-env NO_PROXY="${KUBE_BUILD_NO_PROXY:-127.0.0.1}" \
"${DOCKER_MACHINE_NAME}" > /dev/null || {
kube::log::error "Something went wrong creating a machine."
kube::log::error "Try the following: "
kube::log::error "docker-machine create -d ${DOCKER_MACHINE_DRIVER} ${DOCKER_MACHINE_NAME}"
Expand Down Expand Up @@ -203,6 +207,18 @@ function kube::build::is_osx() {
[[ "$(uname)" == "Darwin" ]]
}

function kube::build::update_dockerfile() {
if kube::build::is_osx; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe slightly rework this, just to be consistent with the rest of this file:

if kube::build::is_osx; then
  local sed_opts=(-i \"\")
else
  local sed_opts=(-i)
fi
sed -i ${sed_opts[@]} "s/...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is just to remove sed -i and find a place for an outfile, then do a mv. That's the old POSIX way, before -i existed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ixdy I saw this suggestion from you before I made the fix.
On both Linux, either echo ${sed_opts[@]} or use ${sed_opts[@]} directly in sed command will lose the "", this causes build fail on OSX. So the current code you see is changed by me, to avoid using array for the empty "".

  1. Define in an array
    LM-SHC-16501199:work fmeng$ sed_opts=(-i "")
    LM-SHC-16501199:work fmeng$ echo $sed_opts
    -i
    sed $sed_opts "s/KUBE_BUILD_IMAGE_CROSS/${KUBE_BUILD_IMAGE_CROSS}/" ${build_context_dir}/Dockerfile
    sed: 1: "/Users/fmeng/code/kuber ...": invalid command code f

2.Define as a string
LM-SHC-16501199:kubernetes fmeng$ sed_opt=""
LM-SHC-16501199:kubernetes fmeng$ echo $sed_opt
""
LM-SHC-16501199:kubernetes fmeng$ sed -i $sed_opt "s/KUBE_BUILD_IMAGE_CROSS/${KUBE_BUILD_IMAGE_CROSS}/" ${build_context_dir}/Dockerfile
LM-SHC-16501199:kubernetes fmeng$

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're only getting the first element by referencing $sed_opts.
Try ${sed_opts[@]}

Also try single quotes in the array element instead:
sed_opts=("-i ''")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, thanks for pointing this out, I omitted the [@], will make the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I'm not sure that ("-i ''") is correct - that's just treating it as a single array element.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ixdy It works, I tested on both OSes.
I wrote simple scripts on my local laptop and verify it before I made the change, and the build succeeded on both OSes.
Checking my local build output, the
/Users/fmeng/code/kubernetes/src/k8s.io/validate/kubernetes/_output/images/kube-build:build-b4a36a2a04/Dockerfile
I can see the proxy settings are there.
LM-SHC-16501199:kubernetes fmeng$ more _output/images/kube-build:build-b4a36a2a04/Dockerfile
Here is the sample without environment variable set.
FROM kube-build:cross-1.5.3-1

MAINTAINER Joe Beda jbeda@google.com

(set an explicit GOARM of 5 for maximum compatibility)

ENV GOARM 5
ENV GOOS linux
ENV GOARCH amd64
ENV http_proxy ""
ENV https_proxy ""
ENV no_proxy 127.0.0.1

sed_opts=("-i ''")
else
sed_opts=(-i)
fi
sed ${sed_opts[@]} "s/KUBE_BUILD_IMAGE_CROSS/${KUBE_BUILD_IMAGE_CROSS}/" ${build_context_dir}/Dockerfile
sed ${sed_opts[@]} "s#KUBE_BUILD_HTTP_PROXY#${KUBE_BUILD_HTTP_PROXY:-\"\"}#" ${build_context_dir}/Dockerfile
sed ${sed_opts[@]} "s#KUBE_BUILD_HTTPS_PROXY#${KUBE_BUILD_HTTPS_PROXY:-\"\"}#" ${build_context_dir}/Dockerfile
sed ${sed_opts[@]} "s#KUBE_BUILD_NO_PROXY#${KUBE_BUILD_NO_PROXY:-127.0.0.1}#" ${build_context_dir}/Dockerfile
}

function kube::build::ensure_docker_in_path() {
if [[ -z "$(which docker)" ]]; then
kube::log::error "Can't find 'docker' in PATH, please fix and retry."
Expand Down Expand Up @@ -472,11 +488,8 @@ function kube::build::build_image() {
kube::version::save_version_vars "${build_context_dir}/kube-version-defs"

cp build/build-image/Dockerfile ${build_context_dir}/Dockerfile
if kube::build::is_osx; then
sed -i "" "s/KUBE_BUILD_IMAGE_CROSS/${KUBE_BUILD_IMAGE_CROSS}/" ${build_context_dir}/Dockerfile
else
sed -i "s/KUBE_BUILD_IMAGE_CROSS/${KUBE_BUILD_IMAGE_CROSS}/" ${build_context_dir}/Dockerfile
fi
kube::build::update_dockerfile

# We don't want to force-pull this image because it's based on a local image
# (see kube::build::build_image_cross), not upstream.
kube::build::docker_build "${KUBE_BUILD_IMAGE}" "${build_context_dir}" 'false'
Expand Down