diff --git a/build/build-image/common.sh b/build/build-image/common.sh index a43b3bd4070..734e1a57bcb 100644 --- a/build/build-image/common.sh +++ b/build/build-image/common.sh @@ -34,17 +34,17 @@ else echo "WARNING: No version information provided in build image" fi -function make-binary() { +function kube::build::make_binary() { local -r gopkg=$1 local -r bin=${gopkg##*/} echo "+++ Building ${bin} for ${GOOS}/${GOARCH}" - pushd "${KUBE_REPO_ROOT}" + pushd "${KUBE_REPO_ROOT}" >/dev/null godep go build -ldflags "${KUBE_LD_FLAGS-}" -o "${ARCH_TARGET}/${bin}" "${gopkg}" - popd + popd >/dev/null } -function make-binaries() { +function kube::build::make_binaries() { if [[ ${#targets[@]} -eq 0 ]]; then targets=( cmd/proxy @@ -66,12 +66,12 @@ function make-binaries() { mkdir -p "${ARCH_TARGET}" if [[ -n "$1" ]]; then - make-binary "$1" + kube::build::make_binary "$1" exit 0 fi local b for b in "${binaries[@]}"; do - make-binary "$b" + kube::build::make_binary "$b" done } diff --git a/build/build-image/make-binaries.sh b/build/build-image/make-binaries.sh index 6731f1751e8..2ee1b7e2e9e 100755 --- a/build/build-image/make-binaries.sh +++ b/build/build-image/make-binaries.sh @@ -14,10 +14,8 @@ # 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 -make-binaries "$@" +kube::build::make_binaries "$@" diff --git a/build/build-image/make-cross.sh b/build/build-image/make-cross.sh index 4c1c9c88582..81befd040c2 100755 --- a/build/build-image/make-cross.sh +++ b/build/build-image/make-cross.sh @@ -14,14 +14,12 @@ # 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=( - "./cmd/kubecfg" + ./cmd/kubecfg ) for platform in ${KUBE_CROSSPLATFORMS}; do @@ -29,7 +27,7 @@ for platform in ${KUBE_CROSSPLATFORMS}; do export GOOS=${platform%/*} export GOARCH=${platform##*/} for binary in "${CROSS_BINARIES[@]}"; do - make-binaries "${binary}" + kube::build::make_binaries "${binary}" done ) done diff --git a/build/build-image/run-integration.sh b/build/build-image/run-integration.sh index 7fdce7d1c56..bd8a2e6fe28 100755 --- a/build/build-image/run-integration.sh +++ b/build/build-image/run-integration.sh @@ -18,13 +18,15 @@ set -e source $(dirname $0)/common.sh -ETCD_DIR="${KUBE_REPO_ROOT}/_output/etcd" +kube::build::make_binaries "./cmd/integration" + +readonly ETCD_DIR="${KUBE_REPO_ROOT}/_output/etcd" mkdir -p "${ETCD_DIR}" echo "+++ Running integration test" etcd -name test -data-dir ${ETCD_DIR} > "${KUBE_REPO_ROOT}/_output/etcd.log" & -ETCD_PID=$! +readonly ETCD_PID=$! sleep 5 diff --git a/build/build-image/run-tests.sh b/build/build-image/run-tests.sh index b6eb869f88a..bd7ff0edada 100755 --- a/build/build-image/run-tests.sh +++ b/build/build-image/run-tests.sh @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - set -e source $(dirname $0)/common.sh diff --git a/build/common.sh b/build/common.sh index d09c7f9c052..9e23430f9ee 100644 --- a/build/common.sh +++ b/build/common.sh @@ -56,7 +56,7 @@ readonly RELEASE_DIR="${KUBE_REPO_ROOT}/_output/release" # Basic setup functions # Verify that the right utilities and such are installed for building Kube. -function kube::build::verify-prereqs() { +function kube::build::verify_prereqs() { if [[ -z "$(which docker)" ]]; then echo "Can't find 'docker' in PATH, please fix and retry." >&2 echo "See https://docs.docker.com/installation/#installation for installation instructions." >&2 @@ -91,9 +91,9 @@ function kube::build::verify-prereqs() { # Building # 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=( +function kube::build::build_image() { + local -r build_context_dir="${KUBE_REPO_ROOT}/_output/images/${KUBE_BUILD_IMAGE}" + local -r source=( api build cmd @@ -106,97 +106,98 @@ function kube::build::build-image() { README.md third_party ) - mkdir -p ${BUILD_CONTEXT_DIR} - tar czf ${BUILD_CONTEXT_DIR}/kube-source.tar.gz "${SOURCE[@]}" - cat >${BUILD_CONTEXT_DIR}/kube-version-defs <"${build_context_dir}/kube-version-defs" <" | awk '{print $3}') 2> /dev/null + docker rmi $(docker images | awk '/^/ {print $3}') 2> /dev/null || true } # 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. -function kube::build::docker-build() { - local -r IMAGE=$1 - local -r CONTEXT_DIR=$2 - local -r BUILD_CMD="docker build -t ${IMAGE} ${CONTEXT_DIR}" +function kube::build::docker_build() { + local -r image=$1 + local -r context_dir=$2 + local -r build_cmd="docker build -t ${image} ${context_dir}" - echo "+++ Building Docker image ${IMAGE}. This can take a while." + echo "+++ Building Docker image ${image}. This can take a while." set +e # We are handling the error here manually - local -r DOCKER_OUTPUT="$(${BUILD_CMD} 2>&1)" + local -r docker_output="$(${build_cmd} 2>&1)" if [ $? -ne 0 ]; then set -e - echo "+++ Docker build command failed for ${IMAGE}" >&2 + echo "+++ Docker build command failed for ${image}" >&2 echo >&2 - echo "${DOCKER_OUTPUT}" >&2 + echo "${docker_output}" >&2 echo >&2 echo "To retry manually, run:" >&2 echo >&2 - echo " ${DOCKER_BUILD_CMD}" >&2 + echo " ${build_cmd}" >&2 echo >&2 return 1 fi set -e } -function kube::build::clean-image() { - local -r IMAGE=$1 +function kube::build::clean_image() { + local -r image=$1 - echo "+++ Deleting docker image ${IMAGE}" - docker rmi ${IMAGE} 2> /dev/null || true + 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() { +function kube::build::run_build_command() { [[ -n "$@" ]] || { echo "Invalid input." >&2; return 4; } - local -r DOCKER="docker run --rm --name=${DOCKER_CONTAINER_NAME} -it ${DOCKER_MOUNT} ${KUBE_BUILD_IMAGE}" + 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 || true - ${DOCKER} "$@" + ${docker} "$@" } # If the Docker server is remote, copy the results back out. -function kube::build::copy-output() { +function kube::build::copy_output() { if [[ "$OSTYPE" == "darwin"* ]]; then # When we are on the Mac with boot2docker we need to copy the results back # out. Ideally we would leave the container around and use 'docker cp' to @@ -207,7 +208,7 @@ function kube::build::copy-output() { # The easiest thing I (jbeda) could figure out was to launch another # container pointed at the same volume, tar the output directory and ship # that tar over stdou. - local DOCKER="docker run -a stdout --rm --name=${DOCKER_CONTAINER_NAME} ${DOCKER_MOUNT} ${KUBE_BUILD_IMAGE}" + local -r 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 || true @@ -215,7 +216,7 @@ function kube::build::copy-output() { 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} ." \ + ${docker} sh -c "tar c -C ${REMOTE_OUTPUT_DIR} ." \ | tar xv -C "${LOCAL_OUTPUT_DIR}" # I (jbeda) also tried getting rsync working using 'docker run' as the @@ -232,27 +233,25 @@ function kube::build::copy-output() { # Build final release artifacts # Package up all of the cross compiled clients -function kube::build::package-tarballs() { +function kube::build::package_tarballs() { mkdir -p "${RELEASE_DIR}" # Find all of the built kubecfg binaries local platform for platform in _output/build/*/* ; do - local PLATFORM_TAG=${platform} - PLATFORM_TAG=${PLATFORM_TAG#*/*/} # remove the first two path components - PLATFORM_TAG=${PLATFORM_TAG/\//-} # Replace a "/" for a "-" - echo "+++ Building client package for $PLATFORM_TAG" + local platform_tag=${platform} + platform_tag=${platform_tag#*/*/} # remove the first two path components + platform_tag=${platform_tag/\//-} # Replace a "/" for a "-" + echo "+++ Building client package for $platform_tag" - local CLIENT_RELEASE_STAGE="${KUBE_REPO_ROOT}/_output/release-stage/${PLATFORM_TAG}/kubernetes" - mkdir -p "${CLIENT_RELEASE_STAGE}" - mkdir -p "${CLIENT_RELEASE_STAGE}/bin" + local client_release_stage="${KUBE_REPO_ROOT}/_output/release-stage/${platform_tag}/kubernetes" + mkdir -p "${client_release_stage}" + mkdir -p "${client_release_stage}/bin" - cp "${platform}"/* "${CLIENT_RELEASE_STAGE}/bin" + cp "${platform}"/* "${client_release_stage}/bin" - local CLIENT_PACKAGE_NAME="${RELEASE_DIR}/kubernetes-${PLATFORM_TAG}.tar.gz" - tar czf "${CLIENT_PACKAGE_NAME}" \ - -C "${CLIENT_RELEASE_STAGE}/.." \ - . + local client_package_name="${RELEASE_DIR}/kubernetes-${platform_tag}.tar.gz" + tar czf "${client_package_name}" -C "${client_release_stage}/.." . done } @@ -260,14 +259,14 @@ function kube::build::package-tarballs() { # GCS Release function kube::release::gcs::release() { - kube::release::gcs::verify-prereqs - kube::release::gcs::ensure-release-bucket - kube::release::gcs::push-images - kube::release::gcs::copy-release-tarballs + kube::release::gcs::verify_prereqs + kube::release::gcs::ensure_release_bucket + kube::release::gcs::push_images + kube::release::gcs::copy_release_tarballs } # Verify things are set up for uploading to GCS -function kube::release::gcs::verify-prereqs() { +function kube::release::gcs::verify_prereqs() { if [[ -z "$(which gsutil)" || -z "$(which gcloud)" ]]; then echo "Releasing Kubernetes requires gsutil and gcloud. Please download," echo "install and authorize through the Google Cloud SDK: " @@ -298,7 +297,7 @@ function kube::release::gcs::verify-prereqs() { } # Create a unique bucket name for releasing Kube and make sure it exists. -function kube::release::gcs::ensure-release-bucket() { +function kube::release::gcs::ensure_release_bucket() { local project_hash if which md5 > /dev/null 2>&1; then project_hash=$(md5 -q -s "$GCLOUD_PROJECT") @@ -316,65 +315,66 @@ function kube::release::gcs::ensure-release-bucket() { fi } -function kube::release::gcs::ensure-docker-registry() { - local -r REG_CONTAINER_NAME="gcs-registry" +function kube::release::gcs::ensure_docker_registry() { + local -r reg_container_name="gcs-registry" - local -r RUNNING=$(docker inspect ${REG_CONTAINER_NAME} 2>/dev/null \ + local -r running=$(docker inspect ${reg_container_name} 2>/dev/null \ | build/json-extractor.py 0.State.Running 2>/dev/null) - [[ "$RUNNING" != "true" ]] || return 0 + [[ "$running" != "true" ]] || return 0 # Grovel around and find the OAuth token in the gcloud config - local -r BOTO=~/.config/gcloud/legacy_credentials/${GCLOUD_ACCOUNT}/.boto - local -r REFRESH_TOKEN=$(grep 'gs_oauth2_refresh_token =' $BOTO | awk '{ print $3 }') + local -r boto=~/.config/gcloud/legacy_credentials/${GCLOUD_ACCOUNT}/.boto + local -r refresh_token=$(grep 'gs_oauth2_refresh_token =' $boto | awk '{ print $3 }') - if [[ -z $REFRESH_TOKEN ]]; then - echo "Couldn't find OAuth 2 refresh token in ${BOTO}" >&2 + if [[ -z "$refresh_token" ]]; then + echo "Couldn't find OAuth 2 refresh token in ${boto}" >&2 return 1 fi # If we have an old one sitting around, remove it - docker rm ${REG_CONTAINER_NAME} >/dev/null 2>&1 || true + docker rm ${reg_container_name} >/dev/null 2>&1 || true echo "+++ Starting GCS backed Docker registry" - local DOCKER="docker run -d --name=${REG_CONTAINER_NAME} " - DOCKER+="-e GCS_BUCKET=${KUBE_RELEASE_BUCKET} " - DOCKER+="-e STORAGE_PATH=${KUBE_DOCKER_REG_PREFIX} " - DOCKER+="-e GCP_OAUTH2_REFRESH_TOKEN=${REFRESH_TOKEN} " - DOCKER+="-p 127.0.0.1:5000:5000 " - DOCKER+="google/docker-registry" + local docker="docker run -d --name=${reg_container_name} " + docker+="-e GCS_BUCKET=${KUBE_RELEASE_BUCKET} " + docker+="-e STORAGE_PATH=${KUBE_DOCKER_REG_PREFIX} " + docker+="-e GCP_OAUTH2_REFRESH_TOKEN=${refresh_token} " + docker+="-p 127.0.0.1:5000:5000 " + docker+="google/docker-registry" - ${DOCKER} + ${docker} # Give it time to spin up before we start throwing stuff at it sleep 5 } -function kube::release::gcs::push-images() { - kube::release::gcs::ensure-docker-registry +function kube::release::gcs::push_images() { + kube::release::gcs::ensure_docker_registry # Tag each of our run binaries with the right registry and push - local b + local b image_name 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" - docker rmi "localhost:5000/${KUBE_RUN_IMAGE_BASE}-$b" + image_name="${KUBE_RUN_IMAGE_BASE}-${b}" + echo "+++ Tagging and pushing ${image_name} to GCS bucket ${KUBE_RELEASE_BUCKET}" + docker tag "${KUBE_RUN_IMAGE_BASE}-$b" "localhost:5000/${image_name}" + docker push "localhost:5000/${image_name}" + docker rmi "localhost:5000/${image_name}" done } -function kube::release::gcs::copy-release-tarballs() { +function kube::release::gcs::copy_release_tarballs() { # TODO: This isn't atomic. There will be points in time where there will be # no active release. Also, if something fails, the release could be half- # copied. The real way to do this would perhaps to have some sort of release # version so that we are never overwriting a destination. - local -r GCS_DESTINATION="gs://${KUBE_RELEASE_BUCKET}/${KUBE_RELEASE_PREFIX}" + local -r gcs_destination="gs://${KUBE_RELEASE_BUCKET}/${KUBE_RELEASE_PREFIX}" - echo "+++ Copying client tarballs to ${GCS_DESTINATION}" + echo "+++ Copying client tarballs to ${gcs_destination}" # First delete all objects at the destination - gsutil -q rm -f -R "${GCS_DESTINATION}" >/dev/null 2>&1 || true + gsutil -q rm -f -R "${gcs_destination}" >/dev/null 2>&1 || true # Now upload everything in release directory - gsutil -m cp -r "${RELEASE_DIR}" "${GCS_DESTINATION}" >/dev/null 2>&1 + gsutil -m cp -r "${RELEASE_DIR}" "${gcs_destination}" >/dev/null 2>&1 } diff --git a/build/copy-output.sh b/build/copy-output.sh index e9c4f889d74..1729545ca76 100755 --- a/build/copy-output.sh +++ b/build/copy-output.sh @@ -23,5 +23,5 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::copy-output +kube::build::verify_prereqs +kube::build::copy_output diff --git a/build/make-binaries.sh b/build/make-binaries.sh index 4b9d835ea6a..c38ef27a366 100755 --- a/build/make-binaries.sh +++ b/build/make-binaries.sh @@ -23,6 +23,6 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image -kube::build::run-build-command build/build-image/make-binaries.sh "$@" +kube::build::verify_prereqs +kube::build::build_image +kube::build::run_build_command build/build-image/make-binaries.sh "$@" diff --git a/build/make-build-image.sh b/build/make-build-image.sh index 6206da57eaa..e553ffaaa74 100755 --- a/build/make-build-image.sh +++ b/build/make-build-image.sh @@ -25,5 +25,5 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image +kube::build::verify_prereqs +kube::build::build_image diff --git a/build/make-clean.sh b/build/make-clean.sh index c66c01d1a92..f8f60cd6b82 100755 --- a/build/make-clean.sh +++ b/build/make-clean.sh @@ -20,10 +20,10 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image +kube::build::verify_prereqs +kube::build::build_image echo "+++ Cleaning out _output/build/*" -kube::build::run-build-command rm -rf _output/build/* +kube::build::run_build_command rm -rf _output/build/* -kube::build::clean-images +kube::build::clean_images diff --git a/build/make-cross.sh b/build/make-cross.sh index a4b5fa15b11..bdbf6eff1fc 100755 --- a/build/make-cross.sh +++ b/build/make-cross.sh @@ -23,6 +23,6 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image -kube::build::run-build-command build/build-image/make-cross.sh +kube::build::verify_prereqs +kube::build::build_image +kube::build::run_build_command build/build-image/make-cross.sh diff --git a/build/make-run-image.sh b/build/make-run-image.sh index 90e334c2e64..bec7270ffaa 100755 --- a/build/make-run-image.sh +++ b/build/make-run-image.sh @@ -23,8 +23,8 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image -kube::build::run-build-command build/build-image/make-binaries.sh "$@" -kube::build::copy-output -kube::build::run-image +kube::build::verify_prereqs +kube::build::build_image +kube::build::run_build_command build/build-image/make-binaries.sh "$@" +kube::build::copy_output +kube::build::run_image diff --git a/build/release.sh b/build/release.sh index 7cf9db99d27..d7c1a681954 100755 --- a/build/release.sh +++ b/build/release.sh @@ -22,13 +22,13 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image -kube::build::run-build-command build/build-image/make-binaries.sh -kube::build::run-build-command build/build-image/make-cross.sh -kube::build::run-build-command build/build-image/run-tests.sh -kube::build::run-build-command build/build-image/run-integration.sh -kube::build::copy-output -kube::build::run-image -kube::build::package-tarballs +kube::build::verify_prereqs +kube::build::build_image +kube::build::run_build_command build/build-image/make-binaries.sh +kube::build::run_build_command build/build-image/make-cross.sh +kube::build::run_build_command build/build-image/run-tests.sh +kube::build::run_build_command build/build-image/run-integration.sh +kube::build::copy_output +kube::build::run_image +kube::build::package_tarballs kube::release::gcs::release diff --git a/build/run-integration.sh b/build/run-integration.sh index d0fc8b24735..d0f163ca0c9 100755 --- a/build/run-integration.sh +++ b/build/run-integration.sh @@ -20,7 +20,7 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image -kube::build::run-build-command build/build-image/make-binaries.sh "./cmd/integration" -kube::build::run-build-command build/build-image/run-integration.sh +kube::build::verify_prereqs +kube::build::build_image +kube::build::run_build_command build/build-image/make-binaries.sh "./cmd/integration" +kube::build::run_build_command build/build-image/run-integration.sh diff --git a/build/run-tests.sh b/build/run-tests.sh index b38bb1c1867..e413516de45 100755 --- a/build/run-tests.sh +++ b/build/run-tests.sh @@ -20,6 +20,6 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image -kube::build::run-build-command build/build-image/run-tests.sh "$@" +kube::build::verify_prereqs +kube::build::build_image +kube::build::run_build_command build/build-image/run-tests.sh "$@" diff --git a/build/shell.sh b/build/shell.sh index 7a6253d49e9..dd9b5389c4b 100755 --- a/build/shell.sh +++ b/build/shell.sh @@ -22,6 +22,6 @@ set -e source $(dirname $0)/common.sh -kube::build::verify-prereqs -kube::build::build-image -kube::build::run-build-command bash +kube::build::verify_prereqs +kube::build::build_image +kube::build::run_build_command bash