From 7fc3a6c05093c8cbc502160e781b814a222b86d4 Mon Sep 17 00:00:00 2001 From: Joe Beda Date: Mon, 8 Sep 2014 16:12:38 -0700 Subject: [PATCH] Added scheduler binaries plus other misc fixes * Support cleaning out built docker images * Use bash arrays in places * Lock etcd version we are testing against --- build/build-image/Dockerfile | 9 +++-- build/build-image/common.sh | 49 +++++++++++++++++---------- build/build-image/make-cross.sh | 8 ++--- build/common.sh | 43 +++++++++++++++++------ build/make-clean.sh | 4 +++ build/run-images/base/Dockerfile | 4 +-- build/run-images/scheduler/Dockerfile | 24 +++++++++++++ build/run-images/scheduler/run.sh | 17 ++++++++++ build/run-integration.sh | 2 +- 9 files changed, 122 insertions(+), 38 deletions(-) create mode 100644 build/run-images/scheduler/Dockerfile create mode 100755 build/run-images/scheduler/run.sh diff --git a/build/build-image/Dockerfile b/build/build-image/Dockerfile index 87e7cb16bbd..a6c78ab25ab 100644 --- a/build/build-image/Dockerfile +++ b/build/build-image/Dockerfile @@ -49,8 +49,13 @@ ENV GOPATH /go 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 github.com/tools/godep +# Get the code coverage tool and godep +RUN go get code.google.com/p/go.tools/cmd/cover github.com/tools/godep + +RUN mkdir -p /go/src/github.com/coreos/etcd && \ + cd /go/src/github.com/coreos/etcd && \ + git clone https://github.com/coreos/etcd.git . -b v0.4.6 --depth=1 && \ + go install github.com/coreos/etcd # Mark this as a kube-build container RUN touch /kube-build-image diff --git a/build/build-image/common.sh b/build/build-image/common.sh index 2bfc98f2162..9539f4f6d43 100644 --- a/build/build-image/common.sh +++ b/build/build-image/common.sh @@ -28,31 +28,44 @@ if [[ ! -f "/kube-build-image" ]]; then echo "WARNING: This script should be run in the kube-build conrtainer image!" >&2 fi +function make-binary() { + local -r gopkg=$1 + local -r bin=${gopkg##*/} + + echo "+++ Building ${bin} for ${GOOS}/${GOARCH}" + pushd "${KUBE_REPO_ROOT}" + godep go build -o "${ARCH_TARGET}/${bin}" "${gopkg}" + popd +} + function make-binaries() { - readonly BINARIES=" - proxy - integration - apiserver - controller-manager - kubelet - kubecfg" + if [[ ${#targets[@]} -eq 0 ]]; then + targets=( + cmd/proxy + cmd/apiserver + cmd/controller-manager + cmd/kubelet + cmd/kubecfg + plugin/cmd/scheduler + ) + fi + + binaries=() + local target + for target in "${targets[@]}"; do + binaries+=("${KUBE_GO_PACKAGE}/${target}") + done ARCH_TARGET="${KUBE_TARGET}/${GOOS}/${GOARCH}" mkdir -p "${ARCH_TARGET}" - function make-binary() { - echo "+++ Building $1 for ${GOOS}/${GOARCH}" - godep go build \ - -o "${ARCH_TARGET}/$1" \ - github.com/GoogleCloudPlatform/kubernetes/cmd/$1 - } - - if [[ -n $1 ]]; then - make-binary $1 + if [[ -n "$1" ]]; then + make-binary "$1" exit 0 fi - for b in ${BINARIES}; do - make-binary $b + local b + for b in "${binaries[@]}"; do + make-binary "$b" done } diff --git a/build/build-image/make-cross.sh b/build/build-image/make-cross.sh index 5864392ee3e..4c1c9c88582 100755 --- a/build/build-image/make-cross.sh +++ b/build/build-image/make-cross.sh @@ -20,15 +20,15 @@ set -e source $(dirname $0)/common.sh -readonly CROSS_BINARIES=" - kubecfg -" +readonly CROSS_BINARIES=( + "./cmd/kubecfg" + ) for platform in ${KUBE_CROSSPLATFORMS}; do ( export GOOS=${platform%/*} export GOARCH=${platform##*/} - for binary in ${CROSS_BINARIES}; do + for binary in "${CROSS_BINARIES[@]}"; do make-binaries "${binary}" done ) diff --git a/build/common.sh b/build/common.sh index 11b11a4cc6c..bf6e73ff4a6 100644 --- a/build/common.sh +++ b/build/common.sh @@ -38,11 +38,13 @@ readonly DOCKER_CONTAINER_NAME=kube-build readonly DOCKER_MOUNT="-v ${LOCAL_OUTPUT_DIR}:${REMOTE_OUTPUT_DIR}" readonly KUBE_RUN_IMAGE_BASE="kubernetes" -readonly KUBE_RUN_BINARIES=" - apiserver - controller-manager - proxy - " +readonly KUBE_RUN_BINARIES=( + apiserver + controller-manager + proxy + scheduler +) + # This is where the final release artifacts are created locally readonly RELEASE_DIR="${KUBE_REPO_ROOT}/_output/release" @@ -88,7 +90,7 @@ function kube::build::verify-prereqs() { # Set up the context directory for the kube-build image and build it. function kube::build::build-image() { local -r BUILD_CONTEXT_DIR="${KUBE_REPO_ROOT}/_output/images/${KUBE_BUILD_IMAGE}" - local -r SOURCE=" + local -r SOURCE=( api build cmd @@ -100,9 +102,9 @@ function kube::build::build-image() { plugin README.md third_party - " + ) mkdir -p ${BUILD_CONTEXT_DIR} - tar czf ${BUILD_CONTEXT_DIR}/kube-source.tar.gz ${SOURCE} + tar czf ${BUILD_CONTEXT_DIR}/kube-source.tar.gz "${SOURCE[@]}" cp build/build-image/Dockerfile ${BUILD_CONTEXT_DIR}/Dockerfile kube::build::docker-build "${KUBE_BUILD_IMAGE}" "${BUILD_CONTEXT_DIR}" } @@ -116,11 +118,12 @@ function kube::build::run-image() { mkdir -p "${BUILD_CONTEXT_BASE}" tar czf ${BUILD_CONTEXT_BASE}/kube-bins.tar.gz \ -C "_output/build/linux/amd64" \ - ${KUBE_RUN_BINARIES} + "${KUBE_RUN_BINARIES[@]}" cp -R build/run-images/base/* "${BUILD_CONTEXT_BASE}/" kube::build::docker-build "${KUBE_RUN_IMAGE_BASE}" "${BUILD_CONTEXT_BASE}" - for b in $KUBE_RUN_BINARIES ; do + local b + for b in "${KUBE_RUN_BINARIES[@]}" ; do local SUB_CONTEXT_DIR="${BUILD_CONTEXT_BASE}-$b" mkdir -p "${SUB_CONTEXT_DIR}" cp -R build/run-images/$b/* "${SUB_CONTEXT_DIR}/" @@ -128,6 +131,16 @@ function kube::build::run-image() { done } +function kube::build::clean-images() { + # Clean the build image + kube::build::clean-image "${KUBE_BUILD_IMAGE}" + + local b + for b in "${KUBE_RUN_BINARIES[@]}" ; do + kube::build::clean-image "${KUBE_RUN_IMAGE_BASE}-${b}" + done +} + # Build a docker image from a Dockerfile. # $1 is the name of the image to build # $2 is the location of the "context" directory, with the Dockerfile at the root. @@ -154,6 +167,13 @@ function kube::build::docker-build() { set -e } +function kube::build::clean-image() { + local -r IMAGE=$1 + + echo "+++ Deleting docker image ${IMAGE}" + docker rmi ${IMAGE} 2> /dev/null || true +} + # Run a command in the kube-build image. This assumes that the image has # already been built. This will sync out all output data from the build. function kube::build::run-build-command() { @@ -325,7 +345,8 @@ function kube::release::gcs::push-images() { kube::release::gcs::ensure-docker-registry # Tag each of our run binaries with the right registry and push - for b in ${KUBE_RUN_BINARIES} ; do + local b + for b in "${KUBE_RUN_BINARIES[@]}" ; do echo "+++ Tagging and pushing ${KUBE_RUN_IMAGE_BASE}-$b to GCS bucket ${KUBE_RELEASE_BUCKET}" docker tag "${KUBE_RUN_IMAGE_BASE}-$b" "localhost:5000/${KUBE_RUN_IMAGE_BASE}-$b" docker push "localhost:5000/${KUBE_RUN_IMAGE_BASE}-$b" diff --git a/build/make-clean.sh b/build/make-clean.sh index b596d857810..c66c01d1a92 100755 --- a/build/make-clean.sh +++ b/build/make-clean.sh @@ -22,4 +22,8 @@ source $(dirname $0)/common.sh kube::build::verify-prereqs kube::build::build-image + +echo "+++ Cleaning out _output/build/*" kube::build::run-build-command rm -rf _output/build/* + +kube::build::clean-images diff --git a/build/run-images/base/Dockerfile b/build/run-images/base/Dockerfile index e386b2d65a5..56c6cb568c2 100644 --- a/build/run-images/base/Dockerfile +++ b/build/run-images/base/Dockerfile @@ -14,10 +14,10 @@ # This file creates a minimal container for running Kubernetes binaries -FROM google/debian:wheezy +FROM google/debian:wheezy MAINTAINER Joe Beda WORKDIR /kubernetes -# Upload Kubernetes +# Upload Kubernetes server binaries ADD kube-bins.tar.gz /kubernetes diff --git a/build/run-images/scheduler/Dockerfile b/build/run-images/scheduler/Dockerfile new file mode 100644 index 00000000000..416369d0bab --- /dev/null +++ b/build/run-images/scheduler/Dockerfile @@ -0,0 +1,24 @@ +# 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 file creates a minimal container for running Kubernetes binaries + +FROM kubernetes +MAINTAINER Joe Beda + +ENV API_SERVER 127.0.0.1:8080 + +ADD . /kubernetes + +CMD ["/kubernetes/run.sh"] diff --git a/build/run-images/scheduler/run.sh b/build/run-images/scheduler/run.sh new file mode 100755 index 00000000000..96b35e00bfc --- /dev/null +++ b/build/run-images/scheduler/run.sh @@ -0,0 +1,17 @@ +#! /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. + +./scheduler -master="${API_SERVER}" diff --git a/build/run-integration.sh b/build/run-integration.sh index 012c7134dfa..d0fc8b24735 100755 --- a/build/run-integration.sh +++ b/build/run-integration.sh @@ -22,5 +22,5 @@ source $(dirname $0)/common.sh kube::build::verify-prereqs kube::build::build-image -kube::build::run-build-command build/build-image/make-binaries.sh "integration" +kube::build::run-build-command build/build-image/make-binaries.sh "./cmd/integration" kube::build::run-build-command build/build-image/run-integration.sh