diff --git a/build/build-image/Dockerfile b/build/build-image/Dockerfile index dcfb9df338a..612d1d93c47 100644 --- a/build/build-image/Dockerfile +++ b/build/build-image/Dockerfile @@ -13,15 +13,6 @@ # limitations under the License. # This file creates a standard build environment for building Kubernetes -# -# Usage: -# -# # Assemble the full dev environment. This is slow the first time. -# docker build -t kube-build . -# -# # Mount your source in an interactive container for quick testing: -# docker run -v `pwd`:/go/src/github.com/GoogleCloudPlatform/kubernetes -i -t docker bash -# FROM google/debian:wheezy MAINTAINER Joe Beda @@ -50,15 +41,17 @@ RUN cd /usr/local/go/src && \ bash -xc 'for platform in $KUBE_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done' # Set up Go Environment -ENV PATH /usr/local/go/bin:/go/bin:$PATH +ENV PATH /go/bin:$PATH ENV GOPATH /go:/go/src/github.com/GoogleCloudPlatform/kubernetes/third_party - -# Mark this as a kube-build container -RUN touch /kube-build-image +ENV GOOS linux +ENV GOARCH amd64 # Get the code coverage tool and etcd for integration tests RUN go get code.google.com/p/go.tools/cmd/cover github.com/coreos/etcd +# Mark this as a kube-build container +RUN touch /kube-build-image + WORKDIR /go/src/github.com/GoogleCloudPlatform/kubernetes # Upload Kubernetes diff --git a/build/build-image/common.sh b/build/build-image/common.sh index b3220460fb6..e2b205b3292 100644 --- a/build/build-image/common.sh +++ b/build/build-image/common.sh @@ -25,3 +25,33 @@ mkdir -p "${KUBE_TARGET}" if [[ ! -f "/kube-build-image" ]]; then echo "WARNING: This script should be run in the kube-build conrtainer image!" >&2 fi + +function make-binaries() { + readonly BINARIES=" + proxy + integration + apiserver + controller-manager + kubelet + cloudcfg + localkube" + + ARCH_TARGET="${KUBE_TARGET}/${GOOS}/${GOARCH}" + mkdir -p "${ARCH_TARGET}" + + function make-binary() { + echo "+++ Building $1 for ${GOOS}/${GOARCH}" + go build \ + -o "${ARCH_TARGET}/$1" \ + github.com/GoogleCloudPlatform/kubernetes/cmd/$1 + } + + if [[ -n $1 ]]; then + make-binary $1 + exit 0 + fi + + for b in ${BINARIES}; do + make-binary $b + done +} diff --git a/build/build-image/make-binaries.sh b/build/build-image/make-binaries.sh index 8781d305750..baab646c859 100755 --- a/build/build-image/make-binaries.sh +++ b/build/build-image/make-binaries.sh @@ -20,26 +20,4 @@ set -e source $(dirname $0)/common.sh -readonly BINARIES=" - proxy - integration - apiserver - controller-manager - kubelet - cloudcfg - localkube" - -if [[ -n $1 ]]; then - echo "+++ Building $1" - go build \ - -o "${KUBE_TARGET}/$1" \ - github.com/GoogleCloudPlatform/kubernetes/cmd/$1 - exit 0 -fi - -for b in ${BINARIES}; do - echo "+++ Building $b" - go build \ - -o "${KUBE_TARGET}/$b" \ - github.com/GoogleCloudPlatform/kubernetes/cmd/$b -done +make-binaries diff --git a/build/build-image/make-cross.sh b/build/build-image/make-cross.sh new file mode 100755 index 00000000000..b1c987d4d19 --- /dev/null +++ b/build/build-image/make-cross.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This and builds all go components. + +set -e + +source $(dirname $0)/common.sh + +readonly CROSS_BINARIES=" + cloudcfg +" + +for platform in ${KUBE_CROSSPLATFORMS}; do + ( + export GOOS=${platform%/*} + export GOARCH=${platform##*/} + for binary in ${CROSS_BINARIES}; do + make-binaries "${binary}" + done + ) +done diff --git a/build/common.sh b/build/common.sh index 2a83e3923c8..ec543f6ad9a 100644 --- a/build/common.sh +++ b/build/common.sh @@ -90,6 +90,7 @@ function build-image() { set +e # We are handling the error here manually local -r DOCKER_OUTPUT="$(${DOCKER_BUILD_CMD} 2>&1)" if [ $? -ne 0 ]; then + set -e echo "+++ Docker build command failed." >&2 echo >&2 echo "${DOCKER_OUTPUT}" >&2 @@ -100,6 +101,8 @@ function build-image() { echo >&2 return 1 fi + set -e + } # Run a command in the kube-build image. This assumes that the image has @@ -109,7 +112,7 @@ function run-build-command() { local -r DOCKER="docker run --rm --name=${DOCKER_CONTAINER_NAME} -it ${DOCKER_MOUNT} ${KUBE_BUILD_IMAGE}" - docker rm ${DOCKER_CONTAINER_NAME} >/dev/null 2>&1 + docker rm ${DOCKER_CONTAINER_NAME} >/dev/null 2>&1 || true ${DOCKER} "$@" @@ -130,10 +133,11 @@ function copy-output() { local DOCKER="docker run -a stdout --rm --name=${DOCKER_CONTAINER_NAME} ${DOCKER_MOUNT} ${KUBE_BUILD_IMAGE}" # Kill any leftover container - docker rm ${DOCKER_CONTAINER_NAME} >/dev/null 2>&1 + docker rm ${DOCKER_CONTAINER_NAME} >/dev/null 2>&1 || true echo "+++ Syncing back output directory from boot2docker VM" mkdir -p "${LOCAL_OUTPUT_DIR}" + rm -rf "${LOCAL_OUTPUT_DIR}/*" ${DOCKER} sh -c "tar c -C ${REMOTE_OUTPUT_DIR} ." \ | tar xv -C "${LOCAL_OUTPUT_DIR}" @@ -146,3 +150,5 @@ function copy-output() { # rsync --blocking-io -av -e "${DOCKER}" foo:${REMOTE_OUTPUT_DIR}/ ${LOCAL_OUTPUT_DIR} fi } + + diff --git a/build/copy-output.sh b/build/copy-output.sh new file mode 100755 index 00000000000..bf7dafafbb3 --- /dev/null +++ b/build/copy-output.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Make all of the Kubernetes binaries. +# +# This makes the docker build image, builds the binaries and copies them out +# of the docker container. + +set -e + +source $(dirname $0)/common.sh + +copy-output diff --git a/build/make-binaries.sh b/build/make-binaries.sh index fa5de2ef177..3df5e051930 100755 --- a/build/make-binaries.sh +++ b/build/make-binaries.sh @@ -25,4 +25,3 @@ source $(dirname $0)/common.sh build-image run-build-command build/build-image/make-binaries.sh "$@" -copy-output diff --git a/build/make-clean.sh b/build/make-clean.sh new file mode 100755 index 00000000000..a0b2192c816 --- /dev/null +++ b/build/make-clean.sh @@ -0,0 +1,27 @@ +#! /bin/bash + +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Make all of the Kubernetes binaries. +# +# This makes the docker build image, builds the binaries and copies them out +# of the docker container. + +set -e + +source $(dirname $0)/common.sh + +build-image +run-build-command rm -rf output/build/* diff --git a/build/make-cross.sh b/build/make-cross.sh new file mode 100755 index 00000000000..2fe8141649f --- /dev/null +++ b/build/make-cross.sh @@ -0,0 +1,27 @@ +#! /bin/bash + +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Make all of the Kubernetes binaries. +# +# This makes the docker build image, builds the binaries and copies them out +# of the docker container. + +set -e + +source $(dirname $0)/common.sh + +build-image +run-build-command build/build-image/make-cross.sh diff --git a/build/shell.sh b/build/shell.sh index 7f313a7eb3d..0fa412c7722 100755 --- a/build/shell.sh +++ b/build/shell.sh @@ -27,4 +27,3 @@ source $(dirname $0)/common.sh build-image run-build-command bash -copy-output