2014-10-14 14:51:50 +00:00
|
|
|
#!/bin/bash
|
2014-06-17 06:16:40 +00:00
|
|
|
|
2015-05-01 16:19:44 +00:00
|
|
|
# Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-06-17 06:16:40 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2014-10-14 14:51:50 +00:00
|
|
|
# Common utilities, variables and checks for all build scripts.
|
2014-09-15 18:57:13 +00:00
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
2014-06-17 06:16:40 +00:00
|
|
|
|
2014-11-26 21:51:29 +00:00
|
|
|
DOCKER_OPTS=${DOCKER_OPTS:-""}
|
|
|
|
DOCKER_NATIVE=${DOCKER_NATIVE:-""}
|
|
|
|
DOCKER=(docker ${DOCKER_OPTS})
|
2015-02-20 23:55:39 +00:00
|
|
|
DOCKER_HOST=${DOCKER_HOST:-""}
|
2016-04-19 18:52:35 +00:00
|
|
|
DOCKER_MACHINE_NAME=${DOCKER_MACHINE_NAME:-"kube-dev"}
|
|
|
|
readonly DOCKER_MACHINE_DRIVER=${DOCKER_MACHINE_DRIVER:-"virtualbox --virtualbox-memory 4096 --virtualbox-cpu-count -1"}
|
2014-11-26 21:51:29 +00:00
|
|
|
|
2016-04-24 04:45:03 +00:00
|
|
|
# This will canonicalize the path
|
|
|
|
KUBE_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd -P)
|
2014-10-09 21:08:34 +00:00
|
|
|
|
2014-10-22 23:26:59 +00:00
|
|
|
source hack/lib/init.sh
|
2014-09-08 23:55:57 +00:00
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
# Incoming options
|
2014-10-01 18:42:45 +00:00
|
|
|
#
|
2014-10-07 20:49:18 +00:00
|
|
|
readonly KUBE_SKIP_CONFIRMATIONS="${KUBE_SKIP_CONFIRMATIONS:-n}"
|
2014-10-01 18:42:45 +00:00
|
|
|
readonly KUBE_GCS_UPLOAD_RELEASE="${KUBE_GCS_UPLOAD_RELEASE:-n}"
|
|
|
|
readonly KUBE_GCS_NO_CACHING="${KUBE_GCS_NO_CACHING:-y}"
|
|
|
|
readonly KUBE_GCS_MAKE_PUBLIC="${KUBE_GCS_MAKE_PUBLIC:-y}"
|
|
|
|
# KUBE_GCS_RELEASE_BUCKET default: kubernetes-releases-${project_hash}
|
2014-11-11 23:16:04 +00:00
|
|
|
readonly KUBE_GCS_RELEASE_PREFIX=${KUBE_GCS_RELEASE_PREFIX-devel}/
|
|
|
|
readonly KUBE_GCS_DOCKER_REG_PREFIX=${KUBE_GCS_DOCKER_REG_PREFIX-docker-reg}/
|
2015-09-30 17:15:59 +00:00
|
|
|
readonly KUBE_GCS_PUBLISH_VERSION=${KUBE_GCS_PUBLISH_VERSION:-}
|
2015-08-04 00:01:50 +00:00
|
|
|
readonly KUBE_GCS_DELETE_EXISTING="${KUBE_GCS_DELETE_EXISTING:-n}"
|
2014-09-15 18:57:13 +00:00
|
|
|
|
|
|
|
# Constants
|
|
|
|
readonly KUBE_BUILD_IMAGE_REPO=kube-build
|
2016-05-10 06:26:42 +00:00
|
|
|
readonly KUBE_BUILD_IMAGE_CROSS_TAG="v1.6.2-2"
|
2016-02-09 03:21:44 +00:00
|
|
|
# KUBE_BUILD_DATA_CONTAINER_NAME=kube-build-data-<hash>"
|
2014-09-15 18:57:13 +00:00
|
|
|
|
2014-10-22 23:26:59 +00:00
|
|
|
# Here we map the output directories across both the local and remote _output
|
|
|
|
# directories:
|
2014-06-17 06:16:40 +00:00
|
|
|
#
|
2014-10-22 23:26:59 +00:00
|
|
|
# *_OUTPUT_ROOT - the base of all output in that environment.
|
|
|
|
# *_OUTPUT_SUBPATH - location where golang stuff is built/cached. Also
|
|
|
|
# persisted across docker runs with a volume mount.
|
|
|
|
# *_OUTPUT_BINPATH - location where final binaries are placed. If the remote
|
|
|
|
# is really remote, this is the stuff that has to be copied
|
|
|
|
# back.
|
2016-03-28 23:34:07 +00:00
|
|
|
# OUT_DIR can come in from the Makefile, so honor it.
|
|
|
|
readonly LOCAL_OUTPUT_ROOT="${KUBE_ROOT}/${OUT_DIR:-_output}"
|
2014-10-22 23:26:59 +00:00
|
|
|
readonly LOCAL_OUTPUT_SUBPATH="${LOCAL_OUTPUT_ROOT}/dockerized"
|
|
|
|
readonly LOCAL_OUTPUT_BINPATH="${LOCAL_OUTPUT_SUBPATH}/bin"
|
2014-10-11 14:34:22 +00:00
|
|
|
readonly LOCAL_OUTPUT_IMAGE_STAGING="${LOCAL_OUTPUT_ROOT}/images"
|
2014-09-15 18:57:13 +00:00
|
|
|
|
2014-11-26 21:51:29 +00:00
|
|
|
readonly OUTPUT_BINPATH="${CUSTOM_OUTPUT_BINPATH:-$LOCAL_OUTPUT_BINPATH}"
|
|
|
|
|
2014-10-22 23:26:59 +00:00
|
|
|
readonly REMOTE_OUTPUT_ROOT="/go/src/${KUBE_GO_PACKAGE}/_output"
|
|
|
|
readonly REMOTE_OUTPUT_SUBPATH="${REMOTE_OUTPUT_ROOT}/dockerized"
|
|
|
|
readonly REMOTE_OUTPUT_BINPATH="${REMOTE_OUTPUT_SUBPATH}/bin"
|
|
|
|
|
2016-02-11 05:44:05 +00:00
|
|
|
readonly DOCKER_MOUNT_ARGS_BASE=(
|
|
|
|
--volume "${OUTPUT_BINPATH}:${REMOTE_OUTPUT_BINPATH}"
|
|
|
|
--volume /etc/localtime:/etc/localtime:ro
|
|
|
|
)
|
2014-10-22 23:26:59 +00:00
|
|
|
|
2016-04-14 06:30:15 +00:00
|
|
|
# We create a Docker data container to cache incremental build artifacts.
|
2014-10-22 23:26:59 +00:00
|
|
|
readonly REMOTE_OUTPUT_GOPATH="${REMOTE_OUTPUT_SUBPATH}/go"
|
|
|
|
readonly DOCKER_DATA_MOUNT_ARGS=(
|
|
|
|
--volume "${REMOTE_OUTPUT_GOPATH}"
|
2014-09-15 18:57:13 +00:00
|
|
|
)
|
|
|
|
|
2014-06-20 22:17:14 +00:00
|
|
|
# This is where the final release artifacts are created locally
|
2014-11-19 23:48:37 +00:00
|
|
|
readonly RELEASE_STAGE="${LOCAL_OUTPUT_ROOT}/release-stage"
|
2014-09-15 18:57:13 +00:00
|
|
|
readonly RELEASE_DIR="${LOCAL_OUTPUT_ROOT}/release-tars"
|
2015-04-30 22:25:28 +00:00
|
|
|
readonly GCS_STAGE="${LOCAL_OUTPUT_ROOT}/gcs-stage"
|
2014-06-20 22:17:14 +00:00
|
|
|
|
2016-02-07 18:35:14 +00:00
|
|
|
# Get the set of master binaries that run in Docker (on Linux)
|
2015-11-13 01:02:35 +00:00
|
|
|
# Entry format is "<name-of-binary>,<base-image>".
|
|
|
|
# Binaries are placed in /usr/local/bin inside the image.
|
2016-03-16 09:59:42 +00:00
|
|
|
#
|
2016-02-07 18:35:14 +00:00
|
|
|
# $1 - server architecture
|
|
|
|
kube::build::get_docker_wrapped_binaries() {
|
|
|
|
case $1 in
|
|
|
|
"amd64")
|
|
|
|
local targets=(
|
|
|
|
kube-apiserver,busybox
|
|
|
|
kube-controller-manager,busybox
|
|
|
|
kube-scheduler,busybox
|
2016-03-05 01:01:25 +00:00
|
|
|
kube-proxy,gcr.io/google_containers/debian-iptables-amd64:v3
|
2016-05-10 21:44:45 +00:00
|
|
|
federation-apiserver,busybox
|
2016-06-01 00:40:20 +00:00
|
|
|
federation-controller-manager,busybox
|
2016-02-07 18:35:14 +00:00
|
|
|
);;
|
2016-04-04 20:33:32 +00:00
|
|
|
"arm")
|
2016-02-07 18:35:14 +00:00
|
|
|
local targets=(
|
2016-04-04 20:33:32 +00:00
|
|
|
kube-apiserver,armel/busybox
|
|
|
|
kube-controller-manager,armel/busybox
|
|
|
|
kube-scheduler,armel/busybox
|
2016-03-05 01:01:25 +00:00
|
|
|
kube-proxy,gcr.io/google_containers/debian-iptables-arm:v3
|
2016-05-10 21:44:45 +00:00
|
|
|
federation-apiserver,armel/busybox
|
2016-06-01 00:40:20 +00:00
|
|
|
federation-controller-manager,armel/busybox
|
2016-02-07 18:35:14 +00:00
|
|
|
);;
|
|
|
|
"arm64")
|
|
|
|
local targets=(
|
|
|
|
kube-apiserver,aarch64/busybox
|
|
|
|
kube-controller-manager,aarch64/busybox
|
|
|
|
kube-scheduler,aarch64/busybox
|
2016-03-05 01:01:25 +00:00
|
|
|
kube-proxy,gcr.io/google_containers/debian-iptables-arm64:v3
|
2016-05-10 21:44:45 +00:00
|
|
|
federation-apiserver,aarch64/busybox
|
2016-06-01 00:40:20 +00:00
|
|
|
federation-controller-manager,aarch64/busybox
|
2016-02-07 18:35:14 +00:00
|
|
|
);;
|
|
|
|
"ppc64le")
|
|
|
|
local targets=(
|
|
|
|
kube-apiserver,ppc64le/busybox
|
|
|
|
kube-controller-manager,ppc64le/busybox
|
|
|
|
kube-scheduler,ppc64le/busybox
|
2016-03-05 01:01:25 +00:00
|
|
|
kube-proxy,gcr.io/google_containers/debian-iptables-ppc64le:v3
|
2016-05-10 21:44:45 +00:00
|
|
|
federation-apiserver,ppc64le/busybox
|
2016-06-15 19:59:25 +00:00
|
|
|
federation-controller-manager,ppc64le/busybox
|
2016-02-07 18:35:14 +00:00
|
|
|
);;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "${targets[@]}"
|
|
|
|
}
|
2015-03-07 01:41:03 +00:00
|
|
|
|
2014-06-20 18:08:50 +00:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Basic setup functions
|
|
|
|
|
2016-02-07 18:35:14 +00:00
|
|
|
# Verify that the right utilities and such are installed for building Kube. Set
|
2014-10-09 21:08:34 +00:00
|
|
|
# up some dynamic constants.
|
|
|
|
#
|
|
|
|
# Vars set:
|
2014-10-22 23:26:59 +00:00
|
|
|
# KUBE_ROOT_HASH
|
2014-10-09 21:08:34 +00:00
|
|
|
# KUBE_BUILD_IMAGE_TAG
|
|
|
|
# KUBE_BUILD_IMAGE
|
|
|
|
# KUBE_BUILD_CONTAINER_NAME
|
2014-10-22 23:26:59 +00:00
|
|
|
# KUBE_BUILD_DATA_CONTAINER_NAME
|
|
|
|
# DOCKER_MOUNT_ARGS
|
2016-02-11 01:57:45 +00:00
|
|
|
# LOCAL_OUTPUT_BUILD_CONTEXT
|
2014-09-09 22:03:32 +00:00
|
|
|
function kube::build::verify_prereqs() {
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Verifying Prerequisites...."
|
2015-08-06 19:32:31 +00:00
|
|
|
kube::build::ensure_tar || return 1
|
2015-08-24 03:11:29 +00:00
|
|
|
kube::build::ensure_docker_in_path || return 1
|
|
|
|
if kube::build::is_osx; then
|
|
|
|
kube::build::docker_available_on_osx || return 1
|
2014-06-20 00:02:54 +00:00
|
|
|
fi
|
2015-08-24 03:11:29 +00:00
|
|
|
kube::build::ensure_docker_daemon_connectivity || return 1
|
2014-10-09 21:08:34 +00:00
|
|
|
|
2016-05-02 22:00:07 +00:00
|
|
|
KUBE_ROOT_HASH=$(kube::build::short_hash "${HOSTNAME:-}:${KUBE_ROOT}")
|
2014-10-09 21:08:34 +00:00
|
|
|
KUBE_BUILD_IMAGE_TAG="build-${KUBE_ROOT_HASH}"
|
|
|
|
KUBE_BUILD_IMAGE="${KUBE_BUILD_IMAGE_REPO}:${KUBE_BUILD_IMAGE_TAG}"
|
|
|
|
KUBE_BUILD_CONTAINER_NAME="kube-build-${KUBE_ROOT_HASH}"
|
2014-10-22 23:26:59 +00:00
|
|
|
KUBE_BUILD_DATA_CONTAINER_NAME="kube-build-data-${KUBE_ROOT_HASH}"
|
|
|
|
DOCKER_MOUNT_ARGS=("${DOCKER_MOUNT_ARGS_BASE[@]}" --volumes-from "${KUBE_BUILD_DATA_CONTAINER_NAME}")
|
2016-02-11 01:57:45 +00:00
|
|
|
LOCAL_OUTPUT_BUILD_CONTEXT="${LOCAL_OUTPUT_IMAGE_STAGING}/${KUBE_BUILD_IMAGE}"
|
2014-06-20 00:02:54 +00:00
|
|
|
}
|
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Utility functions
|
|
|
|
|
2015-08-24 03:11:29 +00:00
|
|
|
function kube::build::docker_available_on_osx() {
|
|
|
|
if [[ -z "${DOCKER_HOST}" ]]; then
|
2016-06-22 12:40:55 +00:00
|
|
|
if [[ -S "/var/run/docker.sock" ]]; then
|
|
|
|
kube::log::status "Using Docker for MacOS"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2015-08-24 03:11:29 +00:00
|
|
|
kube::log::status "No docker host is set. Checking options for setting one..."
|
|
|
|
if [[ -z "$(which docker-machine)" && -z "$(which boot2docker)" ]]; then
|
2016-06-22 12:40:55 +00:00
|
|
|
kube::log::status "It looks like you're running Mac OS X, and neither Docker for Mac, docker-machine or boot2docker are nowhere to be found."
|
2015-08-24 03:11:29 +00:00
|
|
|
kube::log::status "See: https://docs.docker.com/machine/ for installation instructions."
|
|
|
|
return 1
|
|
|
|
elif [[ -n "$(which docker-machine)" ]]; then
|
|
|
|
kube::build::prepare_docker_machine
|
|
|
|
elif [[ -n "$(which boot2docker)" ]]; then
|
|
|
|
kube::build::prepare_boot2docker
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function kube::build::prepare_docker_machine() {
|
|
|
|
kube::log::status "docker-machine was found."
|
2016-04-19 18:52:35 +00:00
|
|
|
docker-machine inspect "${DOCKER_MACHINE_NAME}" &> /dev/null || {
|
2015-08-24 03:11:29 +00:00
|
|
|
kube::log::status "Creating a machine to build Kubernetes"
|
2016-04-19 18:52:35 +00:00
|
|
|
docker-machine create --driver ${DOCKER_MACHINE_DRIVER} \
|
2016-03-03 05:03:35 +00:00
|
|
|
--engine-env HTTP_PROXY="${KUBERNETES_HTTP_PROXY:-}" \
|
|
|
|
--engine-env HTTPS_PROXY="${KUBERNETES_HTTPS_PROXY:-}" \
|
|
|
|
--engine-env NO_PROXY="${KUBERNETES_NO_PROXY:-127.0.0.1}" \
|
2016-02-04 09:38:07 +00:00
|
|
|
"${DOCKER_MACHINE_NAME}" > /dev/null || {
|
2015-08-24 03:11:29 +00:00
|
|
|
kube::log::error "Something went wrong creating a machine."
|
|
|
|
kube::log::error "Try the following: "
|
2016-01-08 18:55:31 +00:00
|
|
|
kube::log::error "docker-machine create -d ${DOCKER_MACHINE_DRIVER} ${DOCKER_MACHINE_NAME}"
|
2015-08-24 03:11:29 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
2016-04-19 18:52:35 +00:00
|
|
|
docker-machine start "${DOCKER_MACHINE_NAME}" &> /dev/null
|
2016-01-08 18:55:31 +00:00
|
|
|
# it takes `docker-machine env` a few seconds to work if the machine was just started
|
|
|
|
while ! docker-machine env ${DOCKER_MACHINE_NAME} &> /dev/null; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
eval $(docker-machine env "${DOCKER_MACHINE_NAME}")
|
|
|
|
kube::log::status "A Docker host using docker-machine named '${DOCKER_MACHINE_NAME}' is ready to go!"
|
2015-08-24 03:11:29 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function kube::build::prepare_boot2docker() {
|
|
|
|
kube::log::status "boot2docker cli has been deprecated in favor of docker-machine."
|
|
|
|
kube::log::status "See: https://github.com/boot2docker/boot2docker-cli for more details."
|
|
|
|
if [[ $(boot2docker status) != "running" ]]; then
|
|
|
|
kube::log::status "boot2docker isn't running. We'll try to start it."
|
|
|
|
boot2docker up || {
|
|
|
|
kube::log::error "Can't start boot2docker."
|
|
|
|
kube::log::error "You may need to 'boot2docker init' to create your VM."
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Reach over and set the clock. After sleep/resume the clock will skew.
|
|
|
|
kube::log::status "Setting boot2docker clock"
|
|
|
|
boot2docker ssh sudo date -u -D "%Y%m%d%H%M.%S" --set "$(date -u +%Y%m%d%H%M.%S)" >/dev/null
|
|
|
|
|
|
|
|
kube::log::status "Setting boot2docker env variables"
|
|
|
|
$(boot2docker shellinit)
|
|
|
|
kube::log::status "boot2docker-vm has been successfully started."
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
function kube::build::is_osx() {
|
2014-10-14 14:51:50 +00:00
|
|
|
[[ "$(uname)" == "Darwin" ]]
|
2014-09-15 18:57:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 09:38:07 +00:00
|
|
|
function kube::build::update_dockerfile() {
|
|
|
|
if kube::build::is_osx; then
|
2016-03-03 05:03:35 +00:00
|
|
|
sed_opts=(-i '')
|
2016-02-04 09:38:07 +00:00
|
|
|
else
|
2016-02-06 08:49:35 +00:00
|
|
|
sed_opts=(-i)
|
2016-02-04 09:38:07 +00:00
|
|
|
fi
|
2016-03-03 05:03:35 +00:00
|
|
|
sed "${sed_opts[@]}" "s/KUBE_BUILD_IMAGE_CROSS_TAG/${KUBE_BUILD_IMAGE_CROSS_TAG}/" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
2016-02-04 09:38:07 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 03:11:29 +00:00
|
|
|
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."
|
|
|
|
kube::log::error "See https://docs.docker.com/installation/#installation for installation instructions."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function kube::build::ensure_docker_daemon_connectivity {
|
|
|
|
if ! "${DOCKER[@]}" info > /dev/null 2>&1 ; then
|
|
|
|
{
|
|
|
|
echo "Can't connect to 'docker' daemon. please fix and retry."
|
|
|
|
echo
|
|
|
|
echo "Possible causes:"
|
|
|
|
echo " - On Mac OS X, DOCKER_HOST hasn't been set. You may need to: "
|
|
|
|
echo " - Create and start your VM using docker-machine or boot2docker: "
|
2016-01-08 18:55:31 +00:00
|
|
|
echo " - docker-machine create -d ${DOCKER_MACHINE_DRIVER} ${DOCKER_MACHINE_NAME}"
|
2015-08-24 03:11:29 +00:00
|
|
|
echo " - boot2docker init && boot2docker start"
|
|
|
|
echo " - Set your environment variables using: "
|
2016-01-08 18:55:31 +00:00
|
|
|
echo " - eval \$(docker-machine env ${DOCKER_MACHINE_NAME})"
|
2015-08-24 03:11:29 +00:00
|
|
|
echo " - \$(boot2docker shellinit)"
|
|
|
|
echo " - On Linux, user isn't in 'docker' group. Add and relogin."
|
|
|
|
echo " - Something like 'sudo usermod -a -G docker ${USER-user}'"
|
|
|
|
echo " - RHEL7 bug and workaround: https://bugzilla.redhat.com/show_bug.cgi?id=1119282#c8"
|
|
|
|
echo " - On Linux, Docker daemon hasn't been started or has crashed."
|
|
|
|
} >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-07-02 19:44:11 +00:00
|
|
|
function kube::build::ensure_tar() {
|
|
|
|
if [[ -n "${TAR:-}" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Find gnu tar if it is available, bomb out if not.
|
|
|
|
TAR=tar
|
|
|
|
if which gtar &>/dev/null; then
|
|
|
|
TAR=gtar
|
|
|
|
else
|
|
|
|
if which gnutar &>/dev/null; then
|
|
|
|
TAR=gnutar
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! "${TAR}" --version | grep -q GNU; then
|
|
|
|
echo " !!! Cannot find GNU tar. Build on Linux or install GNU tar"
|
|
|
|
echo " on Mac OS X (brew install gnu-tar)."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
function kube::build::clean_output() {
|
|
|
|
# Clean out the output directory if it exists.
|
2015-01-06 19:36:35 +00:00
|
|
|
if kube::build::has_docker ; then
|
|
|
|
if kube::build::build_image_built ; then
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Cleaning out _output/dockerized/bin/ via docker build image"
|
2015-01-06 19:36:35 +00:00
|
|
|
kube::build::run_build_command bash -c "rm -rf '${REMOTE_OUTPUT_BINPATH}'/*"
|
|
|
|
else
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::error "Build image not built. Cannot clean via docker build image."
|
2015-01-06 19:36:35 +00:00
|
|
|
fi
|
2014-09-15 18:57:13 +00:00
|
|
|
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Removing data container"
|
2015-01-06 19:36:35 +00:00
|
|
|
"${DOCKER[@]}" rm -v "${KUBE_BUILD_DATA_CONTAINER_NAME}" >/dev/null 2>&1 || true
|
|
|
|
fi
|
2014-10-22 23:26:59 +00:00
|
|
|
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Cleaning out local _output directory"
|
2014-09-15 18:57:13 +00:00
|
|
|
rm -rf "${LOCAL_OUTPUT_ROOT}"
|
|
|
|
}
|
|
|
|
|
2014-10-09 19:52:32 +00:00
|
|
|
# Make sure the _output directory is created and mountable by docker
|
|
|
|
function kube::build::prepare_output() {
|
2016-05-20 15:39:40 +00:00
|
|
|
# See auto-creation of host mounts: https://github.com/docker/docker/pull/21666
|
|
|
|
# if selinux is enabled, docker run -v /foo:/foo:Z will not autocreate the host dir
|
2014-10-22 23:26:59 +00:00
|
|
|
mkdir -p "${LOCAL_OUTPUT_SUBPATH}"
|
2016-05-20 15:39:40 +00:00
|
|
|
mkdir -p "${LOCAL_OUTPUT_BINPATH}"
|
2014-10-09 19:52:32 +00:00
|
|
|
# On RHEL/Fedora SELinux is enabled by default and currently breaks docker
|
|
|
|
# volume mounts. We can work around this by explicitly adding a security
|
|
|
|
# context to the _output directory.
|
2016-04-22 13:06:47 +00:00
|
|
|
# Details: http://www.projectatomic.io/blog/2015/06/using-volumes-with-docker-can-cause-problems-with-selinux/
|
2014-11-24 19:44:01 +00:00
|
|
|
if which selinuxenabled &>/dev/null && \
|
2014-10-09 19:52:32 +00:00
|
|
|
selinuxenabled && \
|
|
|
|
which chcon >/dev/null ; then
|
|
|
|
if [[ ! $(ls -Zd "${LOCAL_OUTPUT_ROOT}") =~ svirt_sandbox_file_t ]] ; then
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Applying SELinux policy to '_output' directory."
|
2014-11-12 21:52:38 +00:00
|
|
|
if ! chcon -Rt svirt_sandbox_file_t "${LOCAL_OUTPUT_ROOT}"; then
|
|
|
|
echo " ***Failed***. This may be because you have root owned files under _output."
|
|
|
|
echo " Continuing, but this build may fail later if SELinux prevents access."
|
|
|
|
fi
|
2014-10-09 19:52:32 +00:00
|
|
|
fi
|
2016-04-22 13:06:47 +00:00
|
|
|
number=${#DOCKER_MOUNT_ARGS[@]}
|
|
|
|
for (( i=0; i<number; i++ )); do
|
|
|
|
if [[ "${DOCKER_MOUNT_ARGS[i]}" =~ "${KUBE_ROOT}" ]]; then
|
2016-05-20 15:39:40 +00:00
|
|
|
## Ensure we don't label the argument multiple times
|
|
|
|
if [[ ! "${DOCKER_MOUNT_ARGS[i]}" == *:Z ]]; then
|
|
|
|
DOCKER_MOUNT_ARGS[i]="${DOCKER_MOUNT_ARGS[i]}:Z"
|
|
|
|
fi
|
2016-04-22 13:06:47 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-10-09 19:52:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-06 19:36:35 +00:00
|
|
|
function kube::build::has_docker() {
|
|
|
|
which docker &> /dev/null
|
|
|
|
}
|
|
|
|
|
2014-10-07 20:49:18 +00:00
|
|
|
# Detect if a specific image exists
|
|
|
|
#
|
|
|
|
# $1 - image repo name
|
|
|
|
# #2 - image tag
|
|
|
|
function kube::build::docker_image_exists() {
|
|
|
|
[[ -n $1 && -n $2 ]] || {
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::error "Internal error. Image not specified in docker_image_exists."
|
2014-10-07 20:49:18 +00:00
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
# We cannot just specify the IMAGE here as `docker images` doesn't behave as
|
|
|
|
# expected. See: https://github.com/docker/docker/issues/8048
|
2015-07-07 12:09:45 +00:00
|
|
|
"${DOCKER[@]}" images | grep -Eq "^(\S+/)?${1}\s+${2}\s+"
|
2014-10-07 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 21:08:34 +00:00
|
|
|
# Takes $1 and computes a short has for it. Useful for unique tag generation
|
|
|
|
function kube::build::short_hash() {
|
|
|
|
[[ $# -eq 1 ]] || {
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::error "Internal error. No data based to short_hash."
|
2014-10-09 21:08:34 +00:00
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
local short_hash
|
|
|
|
if which md5 >/dev/null 2>&1; then
|
|
|
|
short_hash=$(md5 -q -s "$1")
|
|
|
|
else
|
|
|
|
short_hash=$(echo -n "$1" | md5sum)
|
|
|
|
fi
|
2015-04-30 22:25:28 +00:00
|
|
|
echo ${short_hash:0:10}
|
2014-10-09 21:08:34 +00:00
|
|
|
}
|
|
|
|
|
2014-12-06 17:11:46 +00:00
|
|
|
# Pedantically kill, wait-on and remove a container. The -f -v options
|
|
|
|
# to rm don't actually seem to get the job done, so force kill the
|
|
|
|
# container, wait to ensure it's stopped, then try the remove. This is
|
|
|
|
# a workaround for bug https://github.com/docker/docker/issues/3968.
|
|
|
|
function kube::build::destroy_container() {
|
|
|
|
"${DOCKER[@]}" kill "$1" >/dev/null 2>&1 || true
|
|
|
|
"${DOCKER[@]}" wait "$1" >/dev/null 2>&1 || true
|
|
|
|
"${DOCKER[@]}" rm -f -v "$1" >/dev/null 2>&1 || true
|
|
|
|
}
|
|
|
|
|
2015-09-30 17:15:59 +00:00
|
|
|
# Validate a release version
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# None
|
|
|
|
# Arguments:
|
|
|
|
# version
|
|
|
|
# Returns:
|
|
|
|
# If version is a valid release version
|
2015-11-18 23:52:15 +00:00
|
|
|
# Sets: (e.g. for '1.2.3-alpha.4')
|
|
|
|
# VERSION_MAJOR (e.g. '1')
|
|
|
|
# VERSION_MINOR (e.g. '2')
|
|
|
|
# VERSION_PATCH (e.g. '3')
|
|
|
|
# VERSION_EXTRA (e.g. '-alpha.4')
|
|
|
|
# VERSION_PRERELEASE (e.g. 'alpha')
|
|
|
|
# VERSION_PRERELEASE_REV (e.g. '4')
|
2015-09-30 17:15:59 +00:00
|
|
|
function kube::release::parse_and_validate_release_version() {
|
2015-11-05 23:30:59 +00:00
|
|
|
local -r version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-(beta|alpha)\\.(0|[1-9][0-9]*))?$"
|
2015-09-30 17:15:59 +00:00
|
|
|
local -r version="${1-}"
|
|
|
|
[[ "${version}" =~ ${version_regex} ]] || {
|
2015-11-05 23:30:59 +00:00
|
|
|
kube::log::error "Invalid release version: '${version}', must match regex ${version_regex}"
|
2015-09-30 17:15:59 +00:00
|
|
|
return 1
|
|
|
|
}
|
2015-11-18 23:52:15 +00:00
|
|
|
VERSION_MAJOR="${BASH_REMATCH[1]}"
|
|
|
|
VERSION_MINOR="${BASH_REMATCH[2]}"
|
|
|
|
VERSION_PATCH="${BASH_REMATCH[3]}"
|
|
|
|
VERSION_EXTRA="${BASH_REMATCH[4]}"
|
|
|
|
VERSION_PRERELEASE="${BASH_REMATCH[5]}"
|
|
|
|
VERSION_PRERELEASE_REV="${BASH_REMATCH[6]}"
|
2015-09-30 17:15:59 +00:00
|
|
|
}
|
|
|
|
|
2015-10-09 17:59:21 +00:00
|
|
|
# Validate a ci version
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# None
|
|
|
|
# Arguments:
|
|
|
|
# version
|
|
|
|
# Returns:
|
|
|
|
# If version is a valid ci version
|
2016-04-01 20:50:56 +00:00
|
|
|
# Sets: (e.g. for '1.2.3-alpha.4.56+abcdef12345678')
|
2015-11-18 23:52:15 +00:00
|
|
|
# VERSION_MAJOR (e.g. '1')
|
|
|
|
# VERSION_MINOR (e.g. '2')
|
|
|
|
# VERSION_PATCH (e.g. '3')
|
|
|
|
# VERSION_PRERELEASE (e.g. 'alpha')
|
|
|
|
# VERSION_PRERELEASE_REV (e.g. '4')
|
2016-04-01 20:50:56 +00:00
|
|
|
# VERSION_BUILD_INFO (e.g. '.56+abcdef12345678')
|
2015-11-18 23:52:15 +00:00
|
|
|
# VERSION_COMMITS (e.g. '56')
|
2015-10-09 17:59:21 +00:00
|
|
|
function kube::release::parse_and_validate_ci_version() {
|
2016-04-01 20:50:56 +00:00
|
|
|
# Accept things like "v1.2.3-alpha.4.56+abcdef12345678" or "v1.2.3-beta.4"
|
|
|
|
local -r version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)-(beta|alpha)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*)\\+[0-9a-f]{7,40})?$"
|
2015-10-09 17:59:21 +00:00
|
|
|
local -r version="${1-}"
|
|
|
|
[[ "${version}" =~ ${version_regex} ]] || {
|
2015-11-05 23:30:59 +00:00
|
|
|
kube::log::error "Invalid ci version: '${version}', must match regex ${version_regex}"
|
2015-10-09 17:59:21 +00:00
|
|
|
return 1
|
|
|
|
}
|
2015-11-18 23:52:15 +00:00
|
|
|
VERSION_MAJOR="${BASH_REMATCH[1]}"
|
|
|
|
VERSION_MINOR="${BASH_REMATCH[2]}"
|
|
|
|
VERSION_PATCH="${BASH_REMATCH[3]}"
|
|
|
|
VERSION_PRERELEASE="${BASH_REMATCH[4]}"
|
|
|
|
VERSION_PRERELEASE_REV="${BASH_REMATCH[5]}"
|
|
|
|
VERSION_BUILD_INFO="${BASH_REMATCH[6]}"
|
|
|
|
VERSION_COMMITS="${BASH_REMATCH[7]}"
|
2015-10-09 17:59:21 +00:00
|
|
|
}
|
2014-12-06 17:11:46 +00:00
|
|
|
|
2014-06-20 18:08:50 +00:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Building
|
2014-06-17 06:16:40 +00:00
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
function kube::build::build_image_built() {
|
2014-10-07 20:49:18 +00:00
|
|
|
kube::build::docker_image_exists "${KUBE_BUILD_IMAGE_REPO}" "${KUBE_BUILD_IMAGE_TAG}"
|
|
|
|
}
|
|
|
|
|
2015-06-10 20:30:10 +00:00
|
|
|
# The set of source targets to include in the kube-build image
|
|
|
|
function kube::build::source_targets() {
|
|
|
|
local targets=(
|
2014-06-17 06:16:40 +00:00
|
|
|
api
|
|
|
|
build
|
2015-11-06 00:59:21 +00:00
|
|
|
cluster
|
2014-06-17 06:16:40 +00:00
|
|
|
cmd
|
2015-07-14 22:57:41 +00:00
|
|
|
docs
|
2014-08-14 23:28:47 +00:00
|
|
|
examples
|
2016-04-20 23:29:41 +00:00
|
|
|
federation
|
2014-10-22 23:26:59 +00:00
|
|
|
Godeps/Godeps.json
|
2014-06-17 06:16:40 +00:00
|
|
|
hack
|
2014-08-14 23:28:47 +00:00
|
|
|
LICENSE
|
2014-06-17 06:16:40 +00:00
|
|
|
pkg
|
2014-08-28 00:40:42 +00:00
|
|
|
plugin
|
2015-11-06 00:59:21 +00:00
|
|
|
DESIGN.md
|
2014-09-05 21:09:20 +00:00
|
|
|
README.md
|
2014-10-22 23:26:59 +00:00
|
|
|
test
|
2014-06-17 06:16:40 +00:00
|
|
|
third_party
|
2016-04-14 06:30:15 +00:00
|
|
|
vendor
|
2015-10-31 00:16:57 +00:00
|
|
|
contrib/mesos
|
2014-09-08 23:12:38 +00:00
|
|
|
)
|
2015-06-10 20:30:10 +00:00
|
|
|
if [ -n "${KUBERNETES_CONTRIB:-}" ]; then
|
|
|
|
for contrib in "${KUBERNETES_CONTRIB}"; do
|
|
|
|
targets+=($(eval "kube::contrib::${contrib}::source_targets"))
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
echo "${targets[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set up the context directory for the kube-build image and build it.
|
|
|
|
function kube::build::build_image() {
|
2015-07-02 19:44:11 +00:00
|
|
|
kube::build::ensure_tar
|
|
|
|
|
2016-02-11 01:57:45 +00:00
|
|
|
mkdir -p "${LOCAL_OUTPUT_BUILD_CONTEXT}"
|
|
|
|
"${TAR}" czf "${LOCAL_OUTPUT_BUILD_CONTEXT}/kube-source.tar.gz" $(kube::build::source_targets)
|
2014-10-22 23:26:59 +00:00
|
|
|
|
|
|
|
kube::version::get_version_vars
|
2016-02-11 01:57:45 +00:00
|
|
|
kube::version::save_version_vars "${LOCAL_OUTPUT_BUILD_CONTEXT}/kube-version-defs"
|
2014-10-22 23:26:59 +00:00
|
|
|
|
2016-02-11 01:57:45 +00:00
|
|
|
cp build/build-image/Dockerfile "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
2016-02-04 09:38:07 +00:00
|
|
|
kube::build::update_dockerfile
|
|
|
|
|
2016-02-11 01:57:45 +00:00
|
|
|
kube::build::docker_build "${KUBE_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false'
|
2014-06-20 00:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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.
|
2016-01-20 01:28:48 +00:00
|
|
|
# $3 is the value to set the --pull flag for docker build; true by default
|
2014-09-09 22:03:32 +00:00
|
|
|
function kube::build::docker_build() {
|
|
|
|
local -r image=$1
|
|
|
|
local -r context_dir=$2
|
2016-01-20 01:28:48 +00:00
|
|
|
local -r pull="${3:-true}"
|
|
|
|
local -ra build_cmd=("${DOCKER[@]}" build -t "${image}" "--pull=${pull}" "${context_dir}")
|
2014-06-20 00:02:54 +00:00
|
|
|
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Building Docker image ${image}."
|
2014-10-01 16:37:45 +00:00
|
|
|
local docker_output
|
2014-10-06 20:25:27 +00:00
|
|
|
docker_output=$("${build_cmd[@]}" 2>&1) || {
|
|
|
|
cat <<EOF >&2
|
|
|
|
+++ Docker build command failed for ${image}
|
|
|
|
|
|
|
|
${docker_output}
|
|
|
|
|
|
|
|
To retry manually, run:
|
|
|
|
|
|
|
|
${build_cmd[*]}
|
|
|
|
|
|
|
|
EOF
|
2014-06-17 06:16:40 +00:00
|
|
|
return 1
|
2014-10-06 20:25:27 +00:00
|
|
|
}
|
2014-06-20 00:02:54 +00:00
|
|
|
}
|
|
|
|
|
2014-09-09 22:03:32 +00:00
|
|
|
function kube::build::clean_image() {
|
|
|
|
local -r image=$1
|
2014-09-08 23:12:38 +00:00
|
|
|
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Deleting docker image ${image}"
|
2014-11-26 21:51:29 +00:00
|
|
|
"${DOCKER[@]}" rmi ${image} 2> /dev/null || true
|
2014-09-08 23:12:38 +00:00
|
|
|
}
|
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
function kube::build::clean_images() {
|
2015-01-06 19:36:35 +00:00
|
|
|
kube::build::has_docker || return 0
|
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
kube::build::clean_image "${KUBE_BUILD_IMAGE}"
|
|
|
|
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Cleaning all other untagged docker images"
|
2014-11-26 21:51:29 +00:00
|
|
|
"${DOCKER[@]}" rmi $("${DOCKER[@]}" images -q --filter 'dangling=true') 2> /dev/null || true
|
2014-09-15 18:57:13 +00:00
|
|
|
}
|
|
|
|
|
2014-10-22 23:26:59 +00:00
|
|
|
function kube::build::ensure_data_container() {
|
2016-04-14 06:30:15 +00:00
|
|
|
# This is temporary, while last remnants of _workspace are obliterated. If
|
|
|
|
# the data container exists it might be from before the change from
|
|
|
|
# Godeps/_workspace/ to vendor/, and thereby still have a Godeps/_workspace/
|
|
|
|
# directory in it, which trips up godep (yay godep!). Once we are confident
|
|
|
|
# that this has run ~everywhere we care about, we can remove this.
|
|
|
|
# TODO(thockin): remove this after v1.3 is cut.
|
|
|
|
if "${DOCKER[@]}" inspect "${KUBE_BUILD_DATA_CONTAINER_NAME}" \
|
|
|
|
| grep -q "Godeps/_workspace/pkg"; then
|
|
|
|
docker rm -f "${KUBE_BUILD_DATA_CONTAINER_NAME}"
|
|
|
|
fi
|
2014-11-26 21:51:29 +00:00
|
|
|
if ! "${DOCKER[@]}" inspect "${KUBE_BUILD_DATA_CONTAINER_NAME}" >/dev/null 2>&1; then
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Creating data container"
|
2014-10-22 23:26:59 +00:00
|
|
|
local -ra docker_cmd=(
|
2014-11-26 21:51:29 +00:00
|
|
|
"${DOCKER[@]}" run
|
2014-10-22 23:26:59 +00:00
|
|
|
"${DOCKER_DATA_MOUNT_ARGS[@]}"
|
|
|
|
--name "${KUBE_BUILD_DATA_CONTAINER_NAME}"
|
|
|
|
"${KUBE_BUILD_IMAGE}"
|
|
|
|
true
|
|
|
|
)
|
|
|
|
"${docker_cmd[@]}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-06-17 06:16:40 +00:00
|
|
|
# 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.
|
2014-09-09 22:03:32 +00:00
|
|
|
function kube::build::run_build_command() {
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Running build command...."
|
2016-05-05 20:43:14 +00:00
|
|
|
[[ $# != 0 ]] || { echo "Invalid input - please specify a command to run." >&2; return 4; }
|
2014-06-17 06:16:40 +00:00
|
|
|
|
2014-10-22 23:26:59 +00:00
|
|
|
kube::build::ensure_data_container
|
2014-10-09 19:52:32 +00:00
|
|
|
kube::build::prepare_output
|
|
|
|
|
2014-10-10 20:33:11 +00:00
|
|
|
local -a docker_run_opts=(
|
|
|
|
"--name=${KUBE_BUILD_CONTAINER_NAME}"
|
2015-06-10 20:30:10 +00:00
|
|
|
"${DOCKER_MOUNT_ARGS[@]}"
|
|
|
|
)
|
|
|
|
|
|
|
|
if [ -n "${KUBERNETES_CONTRIB:-}" ]; then
|
|
|
|
docker_run_opts+=(-e "KUBERNETES_CONTRIB=${KUBERNETES_CONTRIB}")
|
|
|
|
fi
|
2014-10-10 20:33:11 +00:00
|
|
|
|
2016-02-18 23:35:23 +00:00
|
|
|
docker_run_opts+=(
|
|
|
|
--env "KUBE_FASTBUILD=${KUBE_FASTBUILD:-false}"
|
|
|
|
--env "KUBE_BUILDER_OS=${OSTYPE:-notdetected}"
|
|
|
|
)
|
|
|
|
|
2014-10-10 20:33:11 +00:00
|
|
|
# If we have stdin we can run interactive. This allows things like 'shell.sh'
|
|
|
|
# to work. However, if we run this way and don't have stdin, then it ends up
|
|
|
|
# running in a daemon-ish mode. So if we don't have a stdin, we explicitly
|
|
|
|
# attach stderr/stdout but don't bother asking for a tty.
|
|
|
|
if [[ -t 0 ]]; then
|
|
|
|
docker_run_opts+=(--interactive --tty)
|
|
|
|
else
|
|
|
|
docker_run_opts+=(--attach=stdout --attach=stderr)
|
|
|
|
fi
|
|
|
|
|
2014-10-06 20:25:27 +00:00
|
|
|
local -ra docker_cmd=(
|
2014-11-26 21:51:29 +00:00
|
|
|
"${DOCKER[@]}" run "${docker_run_opts[@]}" "${KUBE_BUILD_IMAGE}")
|
2014-06-17 06:16:40 +00:00
|
|
|
|
2014-12-06 17:11:46 +00:00
|
|
|
# Clean up container from any previous run
|
|
|
|
kube::build::destroy_container "${KUBE_BUILD_CONTAINER_NAME}"
|
2014-10-06 20:25:27 +00:00
|
|
|
"${docker_cmd[@]}" "$@"
|
2014-12-06 17:11:46 +00:00
|
|
|
kube::build::destroy_container "${KUBE_BUILD_CONTAINER_NAME}"
|
2014-06-17 06:16:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 20:56:16 +00:00
|
|
|
# Test if the output directory is remote (and can only be accessed through
|
|
|
|
# docker) or if it is "local" and we can access the output without going through
|
|
|
|
# docker.
|
|
|
|
function kube::build::is_output_remote() {
|
2014-10-22 23:26:59 +00:00
|
|
|
rm -f "${LOCAL_OUTPUT_SUBPATH}/test_for_remote"
|
|
|
|
kube::build::run_build_command touch "${REMOTE_OUTPUT_BINPATH}/test_for_remote"
|
2014-10-17 20:56:16 +00:00
|
|
|
|
2014-10-22 23:26:59 +00:00
|
|
|
[[ ! -e "${LOCAL_OUTPUT_BINPATH}/test_for_remote" ]]
|
2014-10-17 20:56:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-17 06:16:40 +00:00
|
|
|
# If the Docker server is remote, copy the results back out.
|
2014-09-09 22:03:32 +00:00
|
|
|
function kube::build::copy_output() {
|
2014-10-17 20:56:16 +00:00
|
|
|
if kube::build::is_output_remote; then
|
2014-11-26 21:51:29 +00:00
|
|
|
# At time of this code, docker cp does not work when copying from a volume.
|
|
|
|
# As a workaround, the binaries are first copied to a local filesystem,
|
|
|
|
# /tmp, then docker cp'd to the local binaries output directory.
|
|
|
|
# The fix for the volume bug has been accepted and once it's widely
|
|
|
|
# deployed the code below should be simplified to a simple docker cp
|
|
|
|
# Bug: https://github.com/docker/docker/pull/8509
|
|
|
|
local -a docker_run_opts=(
|
|
|
|
"--name=${KUBE_BUILD_CONTAINER_NAME}"
|
|
|
|
"${DOCKER_MOUNT_ARGS[@]}"
|
|
|
|
-d
|
|
|
|
)
|
|
|
|
|
|
|
|
local -ra docker_cmd=(
|
|
|
|
"${DOCKER[@]}" run "${docker_run_opts[@]}" "${KUBE_BUILD_IMAGE}"
|
|
|
|
)
|
2014-06-17 06:16:40 +00:00
|
|
|
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Syncing back _output/dockerized/bin directory from remote Docker"
|
2014-10-22 23:26:59 +00:00
|
|
|
rm -rf "${LOCAL_OUTPUT_BINPATH}"
|
|
|
|
mkdir -p "${LOCAL_OUTPUT_BINPATH}"
|
2014-06-17 06:16:40 +00:00
|
|
|
|
2014-12-06 17:11:46 +00:00
|
|
|
kube::build::destroy_container "${KUBE_BUILD_CONTAINER_NAME}"
|
2014-11-26 21:51:29 +00:00
|
|
|
"${docker_cmd[@]}" bash -c "cp -r ${REMOTE_OUTPUT_BINPATH} /tmp/bin;touch /tmp/finished;rm /tmp/bin/test_for_remote;/bin/sleep 600" > /dev/null 2>&1
|
|
|
|
|
|
|
|
# Wait until binaries have finished coppying
|
|
|
|
count=0
|
|
|
|
while true;do
|
2016-01-19 01:43:53 +00:00
|
|
|
if "${DOCKER[@]}" cp "${KUBE_BUILD_CONTAINER_NAME}:/tmp/finished" "${LOCAL_OUTPUT_BINPATH}" > /dev/null 2>&1;then
|
|
|
|
"${DOCKER[@]}" cp "${KUBE_BUILD_CONTAINER_NAME}:/tmp/bin" "${LOCAL_OUTPUT_SUBPATH}"
|
2014-11-26 21:51:29 +00:00
|
|
|
break;
|
|
|
|
fi
|
|
|
|
|
|
|
|
let count=count+1
|
|
|
|
if [[ $count -eq 60 ]]; then
|
|
|
|
# break after 5m
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::error "Timed out waiting for binaries..."
|
2014-11-26 21:51:29 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
|
|
|
"${DOCKER[@]}" rm -f -v "${KUBE_BUILD_CONTAINER_NAME}" >/dev/null 2>&1 || true
|
2014-10-17 20:56:16 +00:00
|
|
|
else
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Output directory is local. No need to copy results out."
|
2014-06-17 06:16:40 +00:00
|
|
|
fi
|
|
|
|
}
|
2014-06-17 23:10:57 +00:00
|
|
|
|
2014-06-20 18:08:50 +00:00
|
|
|
# ---------------------------------------------------------------------------
|
2014-09-08 18:00:46 +00:00
|
|
|
# Build final release artifacts
|
2015-02-03 22:45:51 +00:00
|
|
|
function kube::release::clean_cruft() {
|
|
|
|
# Clean out cruft
|
|
|
|
find ${RELEASE_STAGE} -name '*~' -exec rm {} \;
|
|
|
|
find ${RELEASE_STAGE} -name '#*#' -exec rm {} \;
|
|
|
|
find ${RELEASE_STAGE} -name '.DS*' -exec rm {} \;
|
|
|
|
}
|
|
|
|
|
2016-02-05 13:42:33 +00:00
|
|
|
function kube::release::package_hyperkube() {
|
|
|
|
# If we have these variables set then we want to build all docker images.
|
|
|
|
if [[ -n "${KUBE_DOCKER_IMAGE_TAG-}" && -n "${KUBE_DOCKER_REGISTRY-}" ]]; then
|
2016-04-14 04:29:10 +00:00
|
|
|
for arch in "${KUBE_SERVER_PLATFORMS[@]##*/}"; do
|
2016-04-04 20:33:32 +00:00
|
|
|
|
2016-06-15 19:59:25 +00:00
|
|
|
# TODO(IBM): Enable hyperkube builds for ppc64le again
|
|
|
|
if [[ ${arch} != "ppc64le" ]]; then
|
|
|
|
kube::log::status "Building hyperkube image for arch: ${arch}"
|
|
|
|
REGISTRY="${KUBE_DOCKER_REGISTRY}" VERSION="${KUBE_DOCKER_IMAGE_TAG}" ARCH="${arch}" make -C cluster/images/hyperkube/ build
|
|
|
|
fi
|
2016-04-04 20:33:32 +00:00
|
|
|
done
|
2016-02-05 13:42:33 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
function kube::release::package_tarballs() {
|
|
|
|
# Clean out any old releases
|
|
|
|
rm -rf "${RELEASE_DIR}"
|
2014-09-08 18:00:46 +00:00
|
|
|
mkdir -p "${RELEASE_DIR}"
|
2016-02-11 01:57:45 +00:00
|
|
|
kube::release::package_build_image_tarball &
|
2015-04-02 17:52:53 +00:00
|
|
|
kube::release::package_client_tarballs &
|
|
|
|
kube::release::package_server_tarballs &
|
|
|
|
kube::release::package_salt_tarball &
|
2015-12-08 22:32:23 +00:00
|
|
|
kube::release::package_kube_manifests_tarball &
|
2015-04-06 18:09:43 +00:00
|
|
|
kube::util::wait-for-jobs || { kube::log::error "previous tarball phase failed"; return 1; }
|
2015-04-02 17:52:53 +00:00
|
|
|
|
|
|
|
kube::release::package_full_tarball & # _full depends on all the previous phases
|
|
|
|
kube::release::package_test_tarball & # _test doesn't depend on anything
|
2015-04-06 18:09:43 +00:00
|
|
|
kube::util::wait-for-jobs || { kube::log::error "previous tarball phase failed"; return 1; }
|
2014-09-15 18:57:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 01:57:45 +00:00
|
|
|
# Package the build image we used from the previous stage, for compliance/licensing/audit/yadda.
|
|
|
|
function kube::release::package_build_image_tarball() {
|
|
|
|
kube::log::status "Building tarball: src"
|
|
|
|
"${TAR}" czf "${RELEASE_DIR}/kubernetes-src.tar.gz" -C "${LOCAL_OUTPUT_BUILD_CONTEXT}" .
|
|
|
|
}
|
|
|
|
|
2016-02-07 18:35:14 +00:00
|
|
|
# Package up all of the cross compiled clients. Over time this should grow into
|
2014-09-15 18:57:13 +00:00
|
|
|
# a full SDK
|
|
|
|
function kube::release::package_client_tarballs() {
|
2015-02-10 18:25:07 +00:00
|
|
|
# Find all of the built client binaries
|
2014-09-15 18:57:13 +00:00
|
|
|
local platform platforms
|
2014-10-22 23:26:59 +00:00
|
|
|
platforms=($(cd "${LOCAL_OUTPUT_BINPATH}" ; echo */*))
|
2015-04-02 20:46:39 +00:00
|
|
|
for platform in "${platforms[@]}"; do
|
2014-09-15 18:57:13 +00:00
|
|
|
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
|
2015-04-02 20:46:39 +00:00
|
|
|
kube::log::status "Starting tarball: client $platform_tag"
|
2014-09-15 18:57:13 +00:00
|
|
|
|
2015-04-02 20:46:39 +00:00
|
|
|
(
|
|
|
|
local release_stage="${RELEASE_STAGE}/client/${platform_tag}/kubernetes"
|
|
|
|
rm -rf "${release_stage}"
|
|
|
|
mkdir -p "${release_stage}/client/bin"
|
2014-09-15 18:57:13 +00:00
|
|
|
|
2015-04-02 20:46:39 +00:00
|
|
|
local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
|
|
|
|
if [[ "${platform%/*}" == "windows" ]]; then
|
|
|
|
client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
|
|
|
|
fi
|
2014-11-24 22:10:28 +00:00
|
|
|
|
2015-04-02 20:46:39 +00:00
|
|
|
# This fancy expression will expand to prepend a path
|
|
|
|
# (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
|
|
|
|
# KUBE_CLIENT_BINARIES array.
|
|
|
|
cp "${client_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
|
|
|
|
"${release_stage}/client/bin/"
|
2014-11-26 21:51:29 +00:00
|
|
|
|
2015-04-02 20:46:39 +00:00
|
|
|
kube::release::clean_cruft
|
2014-09-15 18:57:13 +00:00
|
|
|
|
2015-04-02 20:46:39 +00:00
|
|
|
local package_name="${RELEASE_DIR}/kubernetes-client-${platform_tag}.tar.gz"
|
|
|
|
kube::release::create_tarball "${package_name}" "${release_stage}/.."
|
|
|
|
) &
|
2014-09-15 18:57:13 +00:00
|
|
|
done
|
2015-04-02 20:46:39 +00:00
|
|
|
|
|
|
|
kube::log::status "Waiting on tarballs"
|
2015-04-06 18:09:43 +00:00
|
|
|
kube::util::wait-for-jobs || { kube::log::error "client tarball creation failed"; exit 1; }
|
2014-09-15 18:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Package up all of the server binaries
|
2014-09-23 22:54:27 +00:00
|
|
|
function kube::release::package_server_tarballs() {
|
2014-09-08 18:00:46 +00:00
|
|
|
local platform
|
2016-04-04 20:33:32 +00:00
|
|
|
for platform in "${KUBE_SERVER_PLATFORMS[@]}"; do
|
2014-09-15 18:57:13 +00:00
|
|
|
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
|
2015-12-23 14:07:35 +00:00
|
|
|
local arch=$(basename ${platform})
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Building tarball: server $platform_tag"
|
2014-09-08 18:00:46 +00:00
|
|
|
|
2014-11-19 23:48:37 +00:00
|
|
|
local release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
|
2014-09-15 18:57:13 +00:00
|
|
|
rm -rf "${release_stage}"
|
2014-09-23 22:54:27 +00:00
|
|
|
mkdir -p "${release_stage}/server/bin"
|
2015-07-27 18:50:31 +00:00
|
|
|
mkdir -p "${release_stage}/addons"
|
2014-09-08 18:00:46 +00:00
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
# This fancy expression will expand to prepend a path
|
2014-10-22 23:26:59 +00:00
|
|
|
# (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
|
2014-09-15 18:57:13 +00:00
|
|
|
# KUBE_SERVER_BINARIES array.
|
2014-10-22 23:26:59 +00:00
|
|
|
cp "${KUBE_SERVER_BINARIES[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
|
2014-09-23 22:54:27 +00:00
|
|
|
"${release_stage}/server/bin/"
|
2015-08-24 03:11:29 +00:00
|
|
|
|
2015-12-23 14:07:35 +00:00
|
|
|
kube::release::create_docker_images_for_server "${release_stage}/server/bin" "${arch}"
|
2016-02-09 03:21:44 +00:00
|
|
|
|
2014-11-08 00:49:32 +00:00
|
|
|
# Include the client binaries here too as they are useful debugging tools.
|
2014-11-24 22:10:28 +00:00
|
|
|
local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
|
|
|
|
if [[ "${platform%/*}" == "windows" ]]; then
|
|
|
|
client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
|
|
|
|
fi
|
|
|
|
cp "${client_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
|
2014-11-08 00:49:32 +00:00
|
|
|
"${release_stage}/server/bin/"
|
|
|
|
|
2016-03-02 19:23:32 +00:00
|
|
|
cp "${KUBE_ROOT}/Godeps/LICENSES" "${release_stage}/"
|
|
|
|
|
2016-06-22 01:16:29 +00:00
|
|
|
cp "${RELEASE_DIR}/kubernetes-src.tar.gz" "${release_stage}/"
|
|
|
|
|
2015-02-03 22:45:51 +00:00
|
|
|
kube::release::clean_cruft
|
|
|
|
|
2014-09-15 18:57:13 +00:00
|
|
|
local package_name="${RELEASE_DIR}/kubernetes-server-${platform_tag}.tar.gz"
|
2014-10-30 17:49:44 +00:00
|
|
|
kube::release::create_tarball "${package_name}" "${release_stage}/.."
|
2014-09-08 18:00:46 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2015-04-03 01:18:24 +00:00
|
|
|
function kube::release::md5() {
|
|
|
|
if which md5 >/dev/null 2>&1; then
|
|
|
|
md5 -q "$1"
|
|
|
|
else
|
|
|
|
md5sum "$1" | awk '{ print $1 }'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:25:28 +00:00
|
|
|
function kube::release::sha1() {
|
|
|
|
if which shasum >/dev/null 2>&1; then
|
|
|
|
shasum -a1 "$1" | awk '{ print $1 }'
|
|
|
|
else
|
|
|
|
sha1sum "$1" | awk '{ print $1 }'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-03-07 01:41:03 +00:00
|
|
|
# This will take binaries that run on master and creates Docker images
|
|
|
|
# that wrap the binary in them. (One docker image per binary)
|
2015-11-13 01:02:35 +00:00
|
|
|
# Args:
|
|
|
|
# $1 - binary_dir, the directory to save the tared images to.
|
2015-12-23 14:07:35 +00:00
|
|
|
# $2 - arch, architecture for which we are building docker images.
|
2015-03-07 01:41:03 +00:00
|
|
|
function kube::release::create_docker_images_for_server() {
|
|
|
|
# Create a sub-shell so that we don't pollute the outer environment
|
|
|
|
(
|
2015-11-13 01:02:35 +00:00
|
|
|
local binary_dir="$1"
|
2015-12-23 14:07:35 +00:00
|
|
|
local arch="$2"
|
2015-04-03 01:18:24 +00:00
|
|
|
local binary_name
|
2016-02-07 18:35:14 +00:00
|
|
|
local binaries=($(kube::build::get_docker_wrapped_binaries ${arch}))
|
|
|
|
|
|
|
|
for wrappable in "${binaries[@]}"; do
|
2015-11-13 01:02:35 +00:00
|
|
|
|
|
|
|
local oldifs=$IFS
|
|
|
|
IFS=","
|
|
|
|
set $wrappable
|
|
|
|
IFS=$oldifs
|
|
|
|
|
|
|
|
local binary_name="$1"
|
|
|
|
local base_image="$2"
|
|
|
|
|
2015-04-03 01:39:40 +00:00
|
|
|
kube::log::status "Starting Docker build for image: ${binary_name}"
|
|
|
|
|
|
|
|
(
|
2015-04-06 16:41:14 +00:00
|
|
|
local md5_sum
|
2015-11-13 01:02:35 +00:00
|
|
|
md5_sum=$(kube::release::md5 "${binary_dir}/${binary_name}")
|
2015-04-06 16:41:14 +00:00
|
|
|
|
2015-11-13 01:02:35 +00:00
|
|
|
local docker_build_path="${binary_dir}/${binary_name}.dockerbuild"
|
2015-04-06 16:41:14 +00:00
|
|
|
local docker_file_path="${docker_build_path}/Dockerfile"
|
2015-11-13 01:02:35 +00:00
|
|
|
local binary_file_path="${binary_dir}/${binary_name}"
|
2015-04-06 16:41:14 +00:00
|
|
|
|
|
|
|
rm -rf ${docker_build_path}
|
|
|
|
mkdir -p ${docker_build_path}
|
2015-11-13 01:02:35 +00:00
|
|
|
ln ${binary_dir}/${binary_name} ${docker_build_path}/${binary_name}
|
|
|
|
printf " FROM ${base_image} \n ADD ${binary_name} /usr/local/bin/${binary_name}\n" > ${docker_file_path}
|
2015-04-06 16:41:14 +00:00
|
|
|
|
2016-02-07 18:35:14 +00:00
|
|
|
if [[ ${arch} == "amd64" ]]; then
|
|
|
|
# If we are building a amd64 docker image, preserve the original image name
|
|
|
|
local docker_image_tag=gcr.io/google_containers/${binary_name}:${md5_sum}
|
|
|
|
else
|
|
|
|
# If we are building a docker image for another architecture, append the arch in the image tag
|
|
|
|
local docker_image_tag=gcr.io/google_containers/${binary_name}-${arch}:${md5_sum}
|
|
|
|
fi
|
|
|
|
|
2015-12-23 14:07:35 +00:00
|
|
|
"${DOCKER[@]}" build -q -t "${docker_image_tag}" ${docker_build_path} >/dev/null
|
|
|
|
"${DOCKER[@]}" save ${docker_image_tag} > ${binary_dir}/${binary_name}.tar
|
2015-11-13 01:02:35 +00:00
|
|
|
echo $md5_sum > ${binary_dir}/${binary_name}.docker_tag
|
2015-04-06 20:08:15 +00:00
|
|
|
|
|
|
|
rm -rf ${docker_build_path}
|
2015-05-28 21:32:38 +00:00
|
|
|
|
2015-12-23 14:07:35 +00:00
|
|
|
# If we are building an official/alpha/beta release we want to keep docker images
|
|
|
|
# and tag them appropriately.
|
|
|
|
if [[ -n "${KUBE_DOCKER_IMAGE_TAG-}" && -n "${KUBE_DOCKER_REGISTRY-}" ]]; then
|
|
|
|
local release_docker_image_tag="${KUBE_DOCKER_REGISTRY}/${binary_name}-${arch}:${KUBE_DOCKER_IMAGE_TAG}"
|
|
|
|
kube::log::status "Tagging docker image ${docker_image_tag} as ${release_docker_image_tag}"
|
|
|
|
"${DOCKER[@]}" tag -f "${docker_image_tag}" "${release_docker_image_tag}" 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
2015-05-28 21:32:38 +00:00
|
|
|
kube::log::status "Deleting docker image ${docker_image_tag}"
|
2015-05-30 16:18:31 +00:00
|
|
|
"${DOCKER[@]}" rmi ${docker_image_tag} 2>/dev/null || true
|
2015-04-03 01:39:40 +00:00
|
|
|
) &
|
2015-03-07 01:41:03 +00:00
|
|
|
done
|
2015-04-03 01:39:40 +00:00
|
|
|
|
2015-04-06 18:09:43 +00:00
|
|
|
kube::util::wait-for-jobs || { kube::log::error "previous Docker build failed"; return 1; }
|
2015-04-03 01:39:40 +00:00
|
|
|
kube::log::status "Docker builds done"
|
2015-03-07 01:41:03 +00:00
|
|
|
)
|
2015-11-13 01:02:35 +00:00
|
|
|
|
2015-03-07 01:41:03 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 22:54:27 +00:00
|
|
|
# Package up the salt configuration tree. This is an optional helper to getting
|
|
|
|
# a cluster up and running.
|
|
|
|
function kube::release::package_salt_tarball() {
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Building tarball: salt"
|
2014-09-23 22:54:27 +00:00
|
|
|
|
2014-11-19 23:48:37 +00:00
|
|
|
local release_stage="${RELEASE_STAGE}/salt/kubernetes"
|
2014-09-23 22:54:27 +00:00
|
|
|
rm -rf "${release_stage}"
|
|
|
|
mkdir -p "${release_stage}"
|
|
|
|
|
2014-10-03 21:58:49 +00:00
|
|
|
cp -R "${KUBE_ROOT}/cluster/saltbase" "${release_stage}/"
|
2014-09-23 22:54:27 +00:00
|
|
|
|
Deferred creation of SkyDNS, monitoring and logging objects
This implements phase 1 of the proposal in #3579, moving the creation
of the pods, RCs, and services to the master after the apiserver is
available.
This is such a wide commit because our existing initial config story
is special:
* Add kube-addons service and associated salt configuration:
** We configure /etc/kubernetes/addons to be a directory of objects
that are appropriately configured for the current cluster.
** "/etc/init.d/kube-addons start" slurps up everything in that dir.
(Most of the difficult is the business logic in salt around getting
that directory built at all.)
** We cheat and overlay cluster/addons into saltbase/salt/kube-addons
as config files for the kube-addons meta-service.
* Change .yaml.in files to salt templates
* Rename {setup,teardown}-{monitoring,logging} to
{setup,teardown}-{monitoring,logging}-firewall to properly reflect
their real purpose now (the purpose of these functions is now ONLY to
bring up the firewall rules, and possibly to relay the IP to the user).
* Rework GCE {setup,teardown}-{monitoring,logging}-firewall: Both
functions were improperly configuring global rules, yet used
lifecycles tied to the cluster. Use $NODE_INSTANCE_PREFIX with the
rule. The logging rule needed a $NETWORK specifier. The monitoring
rule tried gcloud describe first, but given the instancing, this feels
like a waste of time now.
* Plumb ENABLE_CLUSTER_MONITORING, ENABLE_CLUSTER_LOGGING,
ELASTICSEARCH_LOGGING_REPLICAS and DNS_REPLICAS down to the master,
since these are needed there now.
(Desperately want just a yaml or json file we can share between
providers that has all this crap. Maybe #3525 is an answer?)
Huge caveats: I've gone pretty firm testing on GCE, including
twiddling the env variables and making sure the objects I expect to
come up, come up. I've tested that it doesn't break GKE bringup
somehow. But I haven't had a chance to test the other providers.
2015-01-18 23:16:52 +00:00
|
|
|
# TODO(#3579): This is a temporary hack. It gathers up the yaml,
|
2015-05-04 23:49:28 +00:00
|
|
|
# yaml.in, json files in cluster/addons (minus any demos) and overlays
|
Deferred creation of SkyDNS, monitoring and logging objects
This implements phase 1 of the proposal in #3579, moving the creation
of the pods, RCs, and services to the master after the apiserver is
available.
This is such a wide commit because our existing initial config story
is special:
* Add kube-addons service and associated salt configuration:
** We configure /etc/kubernetes/addons to be a directory of objects
that are appropriately configured for the current cluster.
** "/etc/init.d/kube-addons start" slurps up everything in that dir.
(Most of the difficult is the business logic in salt around getting
that directory built at all.)
** We cheat and overlay cluster/addons into saltbase/salt/kube-addons
as config files for the kube-addons meta-service.
* Change .yaml.in files to salt templates
* Rename {setup,teardown}-{monitoring,logging} to
{setup,teardown}-{monitoring,logging}-firewall to properly reflect
their real purpose now (the purpose of these functions is now ONLY to
bring up the firewall rules, and possibly to relay the IP to the user).
* Rework GCE {setup,teardown}-{monitoring,logging}-firewall: Both
functions were improperly configuring global rules, yet used
lifecycles tied to the cluster. Use $NODE_INSTANCE_PREFIX with the
rule. The logging rule needed a $NETWORK specifier. The monitoring
rule tried gcloud describe first, but given the instancing, this feels
like a waste of time now.
* Plumb ENABLE_CLUSTER_MONITORING, ENABLE_CLUSTER_LOGGING,
ELASTICSEARCH_LOGGING_REPLICAS and DNS_REPLICAS down to the master,
since these are needed there now.
(Desperately want just a yaml or json file we can share between
providers that has all this crap. Maybe #3525 is an answer?)
Huge caveats: I've gone pretty firm testing on GCE, including
twiddling the env variables and making sure the objects I expect to
come up, come up. I've tested that it doesn't break GKE bringup
somehow. But I haven't had a chance to test the other providers.
2015-01-18 23:16:52 +00:00
|
|
|
# them into kube-addons, where we expect them. (This pipeline is a
|
|
|
|
# fancy copy, stripping anything but the files we don't want.)
|
|
|
|
local objects
|
2015-05-04 23:49:28 +00:00
|
|
|
objects=$(cd "${KUBE_ROOT}/cluster/addons" && find . \( -name \*.yaml -or -name \*.yaml.in -or -name \*.json \) | grep -v demo)
|
Deferred creation of SkyDNS, monitoring and logging objects
This implements phase 1 of the proposal in #3579, moving the creation
of the pods, RCs, and services to the master after the apiserver is
available.
This is such a wide commit because our existing initial config story
is special:
* Add kube-addons service and associated salt configuration:
** We configure /etc/kubernetes/addons to be a directory of objects
that are appropriately configured for the current cluster.
** "/etc/init.d/kube-addons start" slurps up everything in that dir.
(Most of the difficult is the business logic in salt around getting
that directory built at all.)
** We cheat and overlay cluster/addons into saltbase/salt/kube-addons
as config files for the kube-addons meta-service.
* Change .yaml.in files to salt templates
* Rename {setup,teardown}-{monitoring,logging} to
{setup,teardown}-{monitoring,logging}-firewall to properly reflect
their real purpose now (the purpose of these functions is now ONLY to
bring up the firewall rules, and possibly to relay the IP to the user).
* Rework GCE {setup,teardown}-{monitoring,logging}-firewall: Both
functions were improperly configuring global rules, yet used
lifecycles tied to the cluster. Use $NODE_INSTANCE_PREFIX with the
rule. The logging rule needed a $NETWORK specifier. The monitoring
rule tried gcloud describe first, but given the instancing, this feels
like a waste of time now.
* Plumb ENABLE_CLUSTER_MONITORING, ENABLE_CLUSTER_LOGGING,
ELASTICSEARCH_LOGGING_REPLICAS and DNS_REPLICAS down to the master,
since these are needed there now.
(Desperately want just a yaml or json file we can share between
providers that has all this crap. Maybe #3525 is an answer?)
Huge caveats: I've gone pretty firm testing on GCE, including
twiddling the env variables and making sure the objects I expect to
come up, come up. I've tested that it doesn't break GKE bringup
somehow. But I haven't had a chance to test the other providers.
2015-01-18 23:16:52 +00:00
|
|
|
tar c -C "${KUBE_ROOT}/cluster/addons" ${objects} | tar x -C "${release_stage}/saltbase/salt/kube-addons"
|
|
|
|
|
2015-02-03 22:45:51 +00:00
|
|
|
kube::release::clean_cruft
|
|
|
|
|
2014-09-23 22:54:27 +00:00
|
|
|
local package_name="${RELEASE_DIR}/kubernetes-salt.tar.gz"
|
2014-10-30 17:49:44 +00:00
|
|
|
kube::release::create_tarball "${package_name}" "${release_stage}/.."
|
2014-09-23 22:54:27 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 22:32:23 +00:00
|
|
|
# This will pack kube-system manifests files for distros without using salt
|
2016-04-22 18:39:45 +00:00
|
|
|
# such as GCI and Ubuntu Trusty. We directly copy manifests from
|
|
|
|
# cluster/addons and cluster/saltbase/salt. The script of cluster initialization
|
|
|
|
# will remove the salt configuration and evaluate the variables in the manifests.
|
2015-12-08 22:32:23 +00:00
|
|
|
function kube::release::package_kube_manifests_tarball() {
|
|
|
|
kube::log::status "Building tarball: manifests"
|
|
|
|
|
|
|
|
local release_stage="${RELEASE_STAGE}/manifests/kubernetes"
|
|
|
|
rm -rf "${release_stage}"
|
2016-04-22 18:39:45 +00:00
|
|
|
local dst_dir="${release_stage}/gci-trusty"
|
|
|
|
mkdir -p "${dst_dir}"
|
2015-12-08 22:32:23 +00:00
|
|
|
|
|
|
|
local salt_dir="${KUBE_ROOT}/cluster/saltbase/salt"
|
2016-05-27 10:02:20 +00:00
|
|
|
cp "${salt_dir}/cluster-autoscaler/cluster-autoscaler.manifest" "${dst_dir}/"
|
2015-12-08 22:32:23 +00:00
|
|
|
cp "${salt_dir}/fluentd-es/fluentd-es.yaml" "${release_stage}/"
|
|
|
|
cp "${salt_dir}/fluentd-gcp/fluentd-gcp.yaml" "${release_stage}/"
|
|
|
|
cp "${salt_dir}/kube-registry-proxy/kube-registry-proxy.yaml" "${release_stage}/"
|
2015-12-28 17:28:10 +00:00
|
|
|
cp "${salt_dir}/kube-proxy/kube-proxy.manifest" "${release_stage}/"
|
2016-04-22 18:39:45 +00:00
|
|
|
cp "${salt_dir}/etcd/etcd.manifest" "${dst_dir}"
|
|
|
|
cp "${salt_dir}/kube-scheduler/kube-scheduler.manifest" "${dst_dir}"
|
|
|
|
cp "${salt_dir}/kube-apiserver/kube-apiserver.manifest" "${dst_dir}"
|
2016-04-28 21:04:28 +00:00
|
|
|
cp "${salt_dir}/kube-apiserver/abac-authz-policy.jsonl" "${dst_dir}"
|
2016-04-22 18:39:45 +00:00
|
|
|
cp "${salt_dir}/kube-controller-manager/kube-controller-manager.manifest" "${dst_dir}"
|
2016-05-05 17:51:32 +00:00
|
|
|
cp "${salt_dir}/kube-addons/kube-addon-manager.yaml" "${dst_dir}"
|
2016-05-28 23:24:40 +00:00
|
|
|
cp "${salt_dir}/l7-gcp/glbc.manifest" "${dst_dir}"
|
2016-05-19 20:24:03 +00:00
|
|
|
cp "${KUBE_ROOT}/cluster/gce/trusty/configure-helper.sh" "${dst_dir}/trusty-configure-helper.sh"
|
|
|
|
cp "${KUBE_ROOT}/cluster/gce/gci/configure-helper.sh" "${dst_dir}/gci-configure-helper.sh"
|
|
|
|
cp "${KUBE_ROOT}/cluster/gce/gci/health-monitor.sh" "${dst_dir}/health-monitor.sh"
|
2016-04-22 18:39:45 +00:00
|
|
|
cp -r "${salt_dir}/kube-admission-controls/limit-range" "${dst_dir}"
|
2016-02-01 19:36:45 +00:00
|
|
|
local objects
|
|
|
|
objects=$(cd "${KUBE_ROOT}/cluster/addons" && find . \( -name \*.yaml -or -name \*.yaml.in -or -name \*.json \) | grep -v demo)
|
2016-04-22 18:39:45 +00:00
|
|
|
tar c -C "${KUBE_ROOT}/cluster/addons" ${objects} | tar x -C "${dst_dir}"
|
2016-05-27 19:05:24 +00:00
|
|
|
objects=$(cd "${KUBE_ROOT}/cluster/saltbase/salt/kube-dns" && find . \( -name \*.yaml -or -name \*.yaml.in -or -name \*.json \) | grep -v demo)
|
|
|
|
mkdir -p "${dst_dir}/dns"
|
|
|
|
tar c -C "${KUBE_ROOT}/cluster/saltbase/salt/kube-dns" ${objects} | tar x -C "${dst_dir}/dns"
|
2015-12-28 17:28:10 +00:00
|
|
|
|
2016-04-22 18:39:45 +00:00
|
|
|
# This is for coreos only. ContainerVM, GCI, or Trusty does not use it.
|
2015-12-22 23:41:38 +00:00
|
|
|
cp -r "${KUBE_ROOT}/cluster/gce/coreos/kube-manifests"/* "${release_stage}/"
|
2015-12-08 22:32:23 +00:00
|
|
|
|
|
|
|
kube::release::clean_cruft
|
|
|
|
|
|
|
|
local package_name="${RELEASE_DIR}/kubernetes-manifests.tar.gz"
|
|
|
|
kube::release::create_tarball "${package_name}" "${release_stage}/.."
|
|
|
|
}
|
|
|
|
|
2014-12-17 19:41:47 +00:00
|
|
|
# This is the stuff you need to run tests from the binary distribution.
|
|
|
|
function kube::release::package_test_tarball() {
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Building tarball: test"
|
2014-12-17 19:41:47 +00:00
|
|
|
|
|
|
|
local release_stage="${RELEASE_STAGE}/test/kubernetes"
|
|
|
|
rm -rf "${release_stage}"
|
|
|
|
mkdir -p "${release_stage}"
|
|
|
|
|
|
|
|
local platform
|
2016-02-07 18:35:14 +00:00
|
|
|
for platform in "${KUBE_TEST_PLATFORMS[@]}"; do
|
2014-12-17 19:41:47 +00:00
|
|
|
local test_bins=("${KUBE_TEST_BINARIES[@]}")
|
|
|
|
if [[ "${platform%/*}" == "windows" ]]; then
|
|
|
|
test_bins=("${KUBE_TEST_BINARIES_WIN[@]}")
|
|
|
|
fi
|
|
|
|
mkdir -p "${release_stage}/platforms/${platform}"
|
|
|
|
cp "${test_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
|
|
|
|
"${release_stage}/platforms/${platform}"
|
|
|
|
done
|
|
|
|
|
2015-09-29 15:20:49 +00:00
|
|
|
# Add the test image files
|
|
|
|
mkdir -p "${release_stage}/test/images"
|
|
|
|
cp -fR "${KUBE_ROOT}/test/images" "${release_stage}/test/"
|
2014-12-18 16:19:32 +00:00
|
|
|
tar c ${KUBE_TEST_PORTABLE[@]} | tar x -C ${release_stage}
|
2014-12-17 19:41:47 +00:00
|
|
|
|
2015-02-03 22:45:51 +00:00
|
|
|
kube::release::clean_cruft
|
|
|
|
|
2014-12-17 19:41:47 +00:00
|
|
|
local package_name="${RELEASE_DIR}/kubernetes-test.tar.gz"
|
|
|
|
kube::release::create_tarball "${package_name}" "${release_stage}/.."
|
|
|
|
}
|
|
|
|
|
2014-09-23 22:54:27 +00:00
|
|
|
# This is all the stuff you need to run/install kubernetes. This includes:
|
|
|
|
# - precompiled binaries for client
|
|
|
|
# - Cluster spin up/down scripts and configs for various cloud providers
|
|
|
|
# - tarballs for server binary and salt configs that are ready to be uploaded
|
|
|
|
# to master by whatever means appropriate.
|
|
|
|
function kube::release::package_full_tarball() {
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Building tarball: full"
|
2014-09-23 22:54:27 +00:00
|
|
|
|
2014-11-20 16:15:16 +00:00
|
|
|
local release_stage="${RELEASE_STAGE}/full/kubernetes"
|
2014-09-23 22:54:27 +00:00
|
|
|
rm -rf "${release_stage}"
|
|
|
|
mkdir -p "${release_stage}"
|
|
|
|
|
2014-11-04 00:59:17 +00:00
|
|
|
# Copy all of the client binaries in here, but not test or server binaries.
|
|
|
|
# The server binaries are included with the server binary tarball.
|
|
|
|
local platform
|
|
|
|
for platform in "${KUBE_CLIENT_PLATFORMS[@]}"; do
|
2014-11-24 22:10:28 +00:00
|
|
|
local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
|
|
|
|
if [[ "${platform%/*}" == "windows" ]]; then
|
|
|
|
client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
|
|
|
|
fi
|
2014-11-04 00:59:17 +00:00
|
|
|
mkdir -p "${release_stage}/platforms/${platform}"
|
2014-11-24 22:10:28 +00:00
|
|
|
cp "${client_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
|
2014-11-04 00:59:17 +00:00
|
|
|
"${release_stage}/platforms/${platform}"
|
|
|
|
done
|
2014-09-23 22:54:27 +00:00
|
|
|
|
|
|
|
# We want everything in /cluster except saltbase. That is only needed on the
|
|
|
|
# server.
|
2014-10-03 21:58:49 +00:00
|
|
|
cp -R "${KUBE_ROOT}/cluster" "${release_stage}/"
|
2014-09-23 22:54:27 +00:00
|
|
|
rm -rf "${release_stage}/cluster/saltbase"
|
|
|
|
|
|
|
|
mkdir -p "${release_stage}/server"
|
|
|
|
cp "${RELEASE_DIR}/kubernetes-salt.tar.gz" "${release_stage}/server/"
|
|
|
|
cp "${RELEASE_DIR}"/kubernetes-server-*.tar.gz "${release_stage}/server/"
|
2015-12-08 22:32:23 +00:00
|
|
|
cp "${RELEASE_DIR}/kubernetes-manifests.tar.gz" "${release_stage}/server/"
|
2014-09-23 22:54:27 +00:00
|
|
|
|
2014-09-29 20:37:04 +00:00
|
|
|
mkdir -p "${release_stage}/third_party"
|
2014-10-03 21:58:49 +00:00
|
|
|
cp -R "${KUBE_ROOT}/third_party/htpasswd" "${release_stage}/third_party/htpasswd"
|
2014-09-29 20:37:04 +00:00
|
|
|
|
2016-05-10 21:44:45 +00:00
|
|
|
# Include only federation/cluster and federation/manifests
|
|
|
|
mkdir "${release_stage}/federation"
|
|
|
|
cp -R "${KUBE_ROOT}/federation/cluster" "${release_stage}/federation/"
|
|
|
|
cp -R "${KUBE_ROOT}/federation/manifests" "${release_stage}/federation/"
|
|
|
|
|
2014-10-03 21:58:49 +00:00
|
|
|
cp -R "${KUBE_ROOT}/examples" "${release_stage}/"
|
2015-07-14 22:57:41 +00:00
|
|
|
cp -R "${KUBE_ROOT}/docs" "${release_stage}/"
|
2014-10-03 21:58:49 +00:00
|
|
|
cp "${KUBE_ROOT}/README.md" "${release_stage}/"
|
2016-02-27 02:33:24 +00:00
|
|
|
cp "${KUBE_ROOT}/Godeps/LICENSES" "${release_stage}/"
|
2014-10-03 21:58:49 +00:00
|
|
|
cp "${KUBE_ROOT}/Vagrantfile" "${release_stage}/"
|
2014-09-23 22:54:27 +00:00
|
|
|
|
2015-11-18 02:13:24 +00:00
|
|
|
echo "${KUBE_GIT_VERSION}" > "${release_stage}/version"
|
|
|
|
|
2015-02-03 22:45:51 +00:00
|
|
|
kube::release::clean_cruft
|
2015-02-03 20:57:34 +00:00
|
|
|
|
2014-09-23 22:54:27 +00:00
|
|
|
local package_name="${RELEASE_DIR}/kubernetes.tar.gz"
|
2014-10-30 17:49:44 +00:00
|
|
|
kube::release::create_tarball "${package_name}" "${release_stage}/.."
|
2014-09-23 22:54:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 17:49:44 +00:00
|
|
|
# Build a release tarball. $1 is the output tar name. $2 is the base directory
|
|
|
|
# of the files to be packaged. This assumes that ${2}/kubernetes is what is
|
|
|
|
# being packaged.
|
|
|
|
function kube::release::create_tarball() {
|
2015-07-02 19:44:11 +00:00
|
|
|
kube::build::ensure_tar
|
|
|
|
|
2014-10-30 17:49:44 +00:00
|
|
|
local tarfile=$1
|
|
|
|
local stagingdir=$2
|
|
|
|
|
2015-07-02 19:44:11 +00:00
|
|
|
"${TAR}" czf "${tarfile}" -C "${stagingdir}" kubernetes --owner=0 --group=0
|
2014-10-30 17:49:44 +00:00
|
|
|
}
|
2014-09-23 22:54:27 +00:00
|
|
|
|
2014-09-08 18:00:46 +00:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# GCS Release
|
|
|
|
|
|
|
|
function kube::release::gcs::release() {
|
2014-10-07 20:49:18 +00:00
|
|
|
[[ ${KUBE_GCS_UPLOAD_RELEASE} =~ ^[yY]$ ]] || return 0
|
2014-09-15 18:57:13 +00:00
|
|
|
|
2015-08-06 19:32:31 +00:00
|
|
|
kube::release::gcs::verify_prereqs || return 1
|
|
|
|
kube::release::gcs::ensure_release_bucket || return 1
|
|
|
|
kube::release::gcs::copy_release_artifacts || return 1
|
2014-09-08 18:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Verify things are set up for uploading to GCS
|
2014-09-09 22:03:32 +00:00
|
|
|
function kube::release::gcs::verify_prereqs() {
|
2014-09-08 18:00:46 +00:00
|
|
|
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: "
|
|
|
|
echo
|
|
|
|
echo " https://developers.google.com/cloud/sdk/"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "${GCLOUD_ACCOUNT-}" ]]; then
|
|
|
|
GCLOUD_ACCOUNT=$(gcloud auth list 2>/dev/null | awk '/(active)/ { print $2 }')
|
|
|
|
fi
|
2014-10-06 20:25:27 +00:00
|
|
|
if [[ -z "${GCLOUD_ACCOUNT-}" ]]; then
|
2014-09-08 18:00:46 +00:00
|
|
|
echo "No account authorized through gcloud. Please fix with:"
|
|
|
|
echo
|
|
|
|
echo " gcloud auth login"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "${GCLOUD_PROJECT-}" ]]; then
|
|
|
|
GCLOUD_PROJECT=$(gcloud config list project | awk '{project = $3} END {print project}')
|
|
|
|
fi
|
2014-10-06 20:25:27 +00:00
|
|
|
if [[ -z "${GCLOUD_PROJECT-}" ]]; then
|
2014-09-08 18:00:46 +00:00
|
|
|
echo "No account authorized through gcloud. Please fix with:"
|
|
|
|
echo
|
|
|
|
echo " gcloud config set project <project id>"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
2014-06-20 18:08:50 +00:00
|
|
|
|
|
|
|
# Create a unique bucket name for releasing Kube and make sure it exists.
|
2014-09-09 22:03:32 +00:00
|
|
|
function kube::release::gcs::ensure_release_bucket() {
|
2014-09-08 18:00:46 +00:00
|
|
|
local project_hash
|
2014-10-09 21:08:34 +00:00
|
|
|
project_hash=$(kube::build::short_hash "$GCLOUD_PROJECT")
|
2014-10-01 18:42:45 +00:00
|
|
|
KUBE_GCS_RELEASE_BUCKET=${KUBE_GCS_RELEASE_BUCKET-kubernetes-releases-${project_hash}}
|
2014-06-20 18:08:50 +00:00
|
|
|
|
2014-10-06 20:25:27 +00:00
|
|
|
if ! gsutil ls "gs://${KUBE_GCS_RELEASE_BUCKET}" >/dev/null 2>&1 ; then
|
2014-10-20 23:12:30 +00:00
|
|
|
echo "Creating Google Cloud Storage bucket: $KUBE_GCS_RELEASE_BUCKET"
|
2015-08-06 19:32:31 +00:00
|
|
|
gsutil mb -p "${GCLOUD_PROJECT}" "gs://${KUBE_GCS_RELEASE_BUCKET}" || return 1
|
2014-06-20 18:08:50 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:25:28 +00:00
|
|
|
function kube::release::gcs::stage_and_hash() {
|
2015-08-06 19:32:31 +00:00
|
|
|
kube::build::ensure_tar || return 1
|
2015-07-02 19:44:11 +00:00
|
|
|
|
2015-04-30 22:25:28 +00:00
|
|
|
# Split the args into srcs... and dst
|
|
|
|
local -r args=( "$@" )
|
|
|
|
local -r split=$((${#args[@]}-1)) # Split point for src/dst args
|
|
|
|
local -r srcs=( "${args[@]::${split}}" )
|
|
|
|
local -r dst="${args[${split}]}"
|
|
|
|
|
|
|
|
for src in ${srcs[@]}; do
|
|
|
|
srcdir=$(dirname ${src})
|
|
|
|
srcthing=$(basename ${src})
|
2015-08-06 19:32:31 +00:00
|
|
|
mkdir -p ${GCS_STAGE}/${dst} || return 1
|
|
|
|
"${TAR}" c -C ${srcdir} ${srcthing} | "${TAR}" x -C ${GCS_STAGE}/${dst} || return 1
|
2015-04-30 22:25:28 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-11-10 23:35:48 +00:00
|
|
|
function kube::release::gcs::copy_release_artifacts() {
|
2014-06-20 22:17:14 +00:00
|
|
|
# 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.
|
2014-10-01 18:42:45 +00:00
|
|
|
local -r gcs_destination="gs://${KUBE_GCS_RELEASE_BUCKET}/${KUBE_GCS_RELEASE_PREFIX}"
|
2014-10-01 16:37:45 +00:00
|
|
|
|
2015-04-30 22:25:28 +00:00
|
|
|
kube::log::status "Staging release artifacts to ${GCS_STAGE}"
|
|
|
|
|
2015-08-06 19:32:31 +00:00
|
|
|
rm -rf ${GCS_STAGE} || return 1
|
|
|
|
mkdir -p ${GCS_STAGE} || return 1
|
2015-04-30 22:25:28 +00:00
|
|
|
|
|
|
|
# Stage everything in release directory
|
2015-08-06 19:32:31 +00:00
|
|
|
kube::release::gcs::stage_and_hash "${RELEASE_DIR}"/* . || return 1
|
2015-04-30 22:25:28 +00:00
|
|
|
|
2016-05-19 20:24:03 +00:00
|
|
|
# Having the configure-vm.sh script and GCI code from the GCE cluster
|
2015-08-24 18:04:57 +00:00
|
|
|
# deploy hosted with the release is useful for GKE.
|
2015-08-06 19:32:31 +00:00
|
|
|
kube::release::gcs::stage_and_hash "${RELEASE_STAGE}/full/kubernetes/cluster/gce/configure-vm.sh" extra/gce || return 1
|
2016-05-19 20:24:03 +00:00
|
|
|
kube::release::gcs::stage_and_hash "${RELEASE_STAGE}/full/kubernetes/cluster/gce/gci/node.yaml" extra/gce || return 1
|
|
|
|
kube::release::gcs::stage_and_hash "${RELEASE_STAGE}/full/kubernetes/cluster/gce/gci/master.yaml" extra/gce || return 1
|
|
|
|
kube::release::gcs::stage_and_hash "${RELEASE_STAGE}/full/kubernetes/cluster/gce/gci/configure.sh" extra/gce || return 1
|
2015-04-30 22:25:28 +00:00
|
|
|
|
|
|
|
# Upload the "naked" binaries to GCS. This is useful for install scripts that
|
|
|
|
# download the binaries directly and don't need tars.
|
|
|
|
local platform platforms
|
|
|
|
platforms=($(cd "${RELEASE_STAGE}/client" ; echo *))
|
|
|
|
for platform in "${platforms[@]}"; do
|
|
|
|
local src="${RELEASE_STAGE}/client/${platform}/kubernetes/client/bin/*"
|
|
|
|
local dst="bin/${platform/-//}/"
|
|
|
|
# We assume here the "server package" is a superset of the "client package"
|
|
|
|
if [[ -d "${RELEASE_STAGE}/server/${platform}" ]]; then
|
|
|
|
src="${RELEASE_STAGE}/server/${platform}/kubernetes/server/bin/*"
|
|
|
|
fi
|
2015-08-06 19:32:31 +00:00
|
|
|
kube::release::gcs::stage_and_hash "$src" "$dst" || return 1
|
2015-04-30 22:25:28 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
kube::log::status "Hashing files in ${GCS_STAGE}"
|
|
|
|
find ${GCS_STAGE} -type f | while read path; do
|
2015-08-06 19:32:31 +00:00
|
|
|
kube::release::md5 ${path} > "${path}.md5" || return 1
|
|
|
|
kube::release::sha1 ${path} > "${path}.sha1" || return 1
|
2015-04-30 22:25:28 +00:00
|
|
|
done
|
2014-06-20 22:17:14 +00:00
|
|
|
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Copying release artifacts to ${gcs_destination}"
|
2014-06-20 22:17:14 +00:00
|
|
|
|
|
|
|
# First delete all objects at the destination
|
2014-11-19 23:02:26 +00:00
|
|
|
if gsutil ls "${gcs_destination}" >/dev/null 2>&1; then
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::error "${gcs_destination} not empty."
|
2015-08-04 00:01:50 +00:00
|
|
|
[[ ${KUBE_GCS_DELETE_EXISTING} =~ ^[yY]$ ]] || {
|
|
|
|
read -p "Delete everything under ${gcs_destination}? [y/n] " -r || {
|
2015-09-30 17:15:59 +00:00
|
|
|
kube::log::status "EOF on prompt. Skipping upload"
|
2015-08-04 00:01:50 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
[[ $REPLY =~ ^[yY]$ ]] || {
|
2015-09-30 17:15:59 +00:00
|
|
|
kube::log::status "Skipping upload"
|
2015-08-04 00:01:50 +00:00
|
|
|
return
|
|
|
|
}
|
2014-11-19 23:02:26 +00:00
|
|
|
}
|
2015-09-30 17:15:59 +00:00
|
|
|
kube::log::status "Deleting everything under ${gcs_destination}"
|
2015-08-06 19:32:31 +00:00
|
|
|
gsutil -q -m rm -f -R "${gcs_destination}" || return 1
|
2014-11-19 23:02:26 +00:00
|
|
|
fi
|
2014-06-20 22:17:14 +00:00
|
|
|
|
2015-04-30 22:25:28 +00:00
|
|
|
local gcs_options=()
|
|
|
|
if [[ ${KUBE_GCS_NO_CACHING} =~ ^[yY]$ ]]; then
|
|
|
|
gcs_options=("-h" "Cache-Control:private, max-age=0")
|
|
|
|
fi
|
2014-11-19 23:48:37 +00:00
|
|
|
|
2015-08-06 19:32:31 +00:00
|
|
|
gsutil -q -m "${gcs_options[@]+${gcs_options[@]}}" cp -r "${GCS_STAGE}"/* ${gcs_destination} || return 1
|
2014-11-10 23:35:48 +00:00
|
|
|
|
2014-10-20 23:12:30 +00:00
|
|
|
# TODO(jbeda): Generate an HTML page with links for this release so it is easy
|
|
|
|
# to see it. For extra credit, generate a dynamic page that builds up the
|
|
|
|
# release list using the GCS JSON API. Use Angular and Bootstrap for extra
|
|
|
|
# extra credit.
|
2014-10-01 16:37:45 +00:00
|
|
|
|
2014-10-07 20:49:18 +00:00
|
|
|
if [[ ${KUBE_GCS_MAKE_PUBLIC} =~ ^[yY]$ ]]; then
|
2015-03-25 22:57:14 +00:00
|
|
|
kube::log::status "Marking all uploaded objects public"
|
2015-08-06 19:32:31 +00:00
|
|
|
gsutil -q -m acl ch -R -g all:R "${gcs_destination}" >/dev/null 2>&1 || return 1
|
2014-10-01 16:37:45 +00:00
|
|
|
fi
|
|
|
|
|
2015-08-06 19:32:31 +00:00
|
|
|
gsutil ls -lhr "${gcs_destination}" || return 1
|
2014-06-20 22:17:14 +00:00
|
|
|
}
|
2015-01-06 02:02:46 +00:00
|
|
|
|
2015-09-30 17:15:59 +00:00
|
|
|
# Publish a new ci version, (latest,) but only if the release files actually
|
|
|
|
# exist on GCS.
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# See callees
|
|
|
|
# Arguments:
|
|
|
|
# None
|
|
|
|
# Returns:
|
|
|
|
# Success
|
|
|
|
function kube::release::gcs::publish_ci() {
|
|
|
|
kube::release::gcs::verify_release_files || return 1
|
2015-10-09 17:59:21 +00:00
|
|
|
|
|
|
|
kube::release::parse_and_validate_ci_version "${KUBE_GCS_PUBLISH_VERSION}" || return 1
|
2015-11-18 23:52:15 +00:00
|
|
|
local -r version_major="${VERSION_MAJOR}"
|
|
|
|
local -r version_minor="${VERSION_MINOR}"
|
2015-10-09 17:59:21 +00:00
|
|
|
|
|
|
|
local -r publish_files=(ci/latest.txt ci/latest-${version_major}.txt ci/latest-${version_major}.${version_minor}.txt)
|
|
|
|
|
|
|
|
for publish_file in ${publish_files[*]}; do
|
|
|
|
# If there's a version that's above the one we're trying to release, don't
|
|
|
|
# do anything, and just try the next one.
|
|
|
|
kube::release::gcs::verify_ci_ge "${publish_file}" || continue
|
|
|
|
kube::release::gcs::publish "${publish_file}" || return 1
|
|
|
|
done
|
2015-09-30 17:15:59 +00:00
|
|
|
}
|
2015-01-06 02:02:46 +00:00
|
|
|
|
2015-09-30 17:15:59 +00:00
|
|
|
# Publish a new official version, (latest or stable,) but only if the release
|
|
|
|
# files actually exist on GCS and the release we're dealing with is newer than
|
|
|
|
# the contents in GCS.
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# KUBE_GCS_PUBLISH_VERSION
|
|
|
|
# See callees
|
|
|
|
# Arguments:
|
|
|
|
# release_kind: either 'latest' or 'stable'
|
|
|
|
# Returns:
|
|
|
|
# Success
|
|
|
|
function kube::release::gcs::publish_official() {
|
|
|
|
local -r release_kind="${1-}"
|
|
|
|
|
|
|
|
kube::release::gcs::verify_release_files || return 1
|
|
|
|
|
|
|
|
kube::release::parse_and_validate_release_version "${KUBE_GCS_PUBLISH_VERSION}" || return 1
|
2015-11-18 23:52:15 +00:00
|
|
|
local -r version_major="${VERSION_MAJOR}"
|
|
|
|
local -r version_minor="${VERSION_MINOR}"
|
2015-01-06 02:02:46 +00:00
|
|
|
|
2015-09-30 17:15:59 +00:00
|
|
|
local publish_files
|
|
|
|
if [[ "${release_kind}" == 'latest' ]]; then
|
|
|
|
publish_files=(release/latest.txt release/latest-${version_major}.txt release/latest-${version_major}.${version_minor}.txt)
|
|
|
|
elif [[ "${release_kind}" == 'stable' ]]; then
|
|
|
|
publish_files=(release/stable.txt release/stable-${version_major}.txt release/stable-${version_major}.${version_minor}.txt)
|
|
|
|
else
|
|
|
|
kube::log::error "Wrong release_kind: must be 'latest' or 'stable'."
|
|
|
|
return 1
|
2015-01-06 02:02:46 +00:00
|
|
|
fi
|
|
|
|
|
2015-09-30 17:15:59 +00:00
|
|
|
for publish_file in ${publish_files[*]}; do
|
|
|
|
# If there's a version that's above the one we're trying to release, don't
|
|
|
|
# do anything, and just try the next one.
|
|
|
|
kube::release::gcs::verify_release_gt "${publish_file}" || continue
|
|
|
|
kube::release::gcs::publish "${publish_file}" || return 1
|
|
|
|
done
|
2015-01-06 02:02:46 +00:00
|
|
|
}
|
2015-03-17 19:31:43 +00:00
|
|
|
|
2015-09-30 17:15:59 +00:00
|
|
|
# Verify that the release files we expect actually exist.
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# KUBE_GCS_RELEASE_BUCKET
|
|
|
|
# KUBE_GCS_RELEASE_PREFIX
|
|
|
|
# Arguments:
|
|
|
|
# None
|
|
|
|
# Returns:
|
|
|
|
# If release files exist
|
|
|
|
function kube::release::gcs::verify_release_files() {
|
|
|
|
local -r release_dir="gs://${KUBE_GCS_RELEASE_BUCKET}/${KUBE_GCS_RELEASE_PREFIX}"
|
|
|
|
if ! gsutil ls "${release_dir}" >/dev/null 2>&1 ; then
|
|
|
|
kube::log::error "Release files don't exist at '${release_dir}'"
|
2015-03-17 19:31:43 +00:00
|
|
|
return 1
|
2015-09-30 17:15:59 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if the new version is greater than the version currently published on
|
|
|
|
# GCS.
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# KUBE_GCS_PUBLISH_VERSION
|
|
|
|
# KUBE_GCS_RELEASE_BUCKET
|
|
|
|
# Arguments:
|
|
|
|
# publish_file: the GCS location to look in
|
|
|
|
# Returns:
|
|
|
|
# If new version is greater than the GCS version
|
2015-11-05 23:30:59 +00:00
|
|
|
#
|
|
|
|
# TODO(16529): This should all be outside of build an in release, and should be
|
|
|
|
# refactored to reduce code duplication. Also consider using strictly nested
|
|
|
|
# if and explicit handling of equals case.
|
2015-09-30 17:15:59 +00:00
|
|
|
function kube::release::gcs::verify_release_gt() {
|
|
|
|
local -r publish_file="${1-}"
|
|
|
|
local -r new_version=${KUBE_GCS_PUBLISH_VERSION}
|
|
|
|
local -r publish_file_dst="gs://${KUBE_GCS_RELEASE_BUCKET}/${publish_file}"
|
|
|
|
|
|
|
|
kube::release::parse_and_validate_release_version "${new_version}" || return 1
|
2015-03-17 19:31:43 +00:00
|
|
|
|
2015-11-18 23:52:15 +00:00
|
|
|
local -r version_major="${VERSION_MAJOR}"
|
|
|
|
local -r version_minor="${VERSION_MINOR}"
|
|
|
|
local -r version_patch="${VERSION_PATCH}"
|
|
|
|
local -r version_prerelease="${VERSION_PRERELEASE}"
|
|
|
|
local -r version_prerelease_rev="${VERSION_PRERELEASE_REV}"
|
2015-03-17 19:31:43 +00:00
|
|
|
|
|
|
|
local gcs_version
|
2015-09-30 17:15:59 +00:00
|
|
|
if gcs_version="$(gsutil cat "${publish_file_dst}")"; then
|
|
|
|
kube::release::parse_and_validate_release_version "${gcs_version}" || {
|
|
|
|
kube::log::error "${publish_file_dst} contains invalid release version, can't compare: '${gcs_version}'"
|
|
|
|
return 1
|
|
|
|
}
|
2015-03-17 19:31:43 +00:00
|
|
|
|
2015-11-18 23:52:15 +00:00
|
|
|
local -r gcs_version_major="${VERSION_MAJOR}"
|
|
|
|
local -r gcs_version_minor="${VERSION_MINOR}"
|
|
|
|
local -r gcs_version_patch="${VERSION_PATCH}"
|
|
|
|
local -r gcs_version_prerelease="${VERSION_PRERELEASE}"
|
|
|
|
local -r gcs_version_prerelease_rev="${VERSION_PRERELEASE_REV}"
|
2015-09-30 17:15:59 +00:00
|
|
|
|
|
|
|
local greater=true
|
2015-10-09 17:59:21 +00:00
|
|
|
if [[ "${version_major}" -lt "${gcs_version_major}" ]]; then
|
2015-09-30 17:15:59 +00:00
|
|
|
greater=false
|
2015-10-09 17:59:21 +00:00
|
|
|
elif [[ "${version_major}" -gt "${gcs_version_major}" ]]; then
|
2015-09-30 17:15:59 +00:00
|
|
|
: # fall out
|
2015-10-09 17:59:21 +00:00
|
|
|
elif [[ "${version_minor}" -lt "${gcs_version_minor}" ]]; then
|
2015-09-30 17:15:59 +00:00
|
|
|
greater=false
|
2015-10-09 17:59:21 +00:00
|
|
|
elif [[ "${version_minor}" -gt "${gcs_version_minor}" ]]; then
|
2015-09-30 17:15:59 +00:00
|
|
|
: # fall out
|
2015-11-05 23:30:59 +00:00
|
|
|
elif [[ "${version_patch}" -lt "${gcs_version_patch}" ]]; then
|
|
|
|
greater=false
|
|
|
|
elif [[ "${version_patch}" -gt "${gcs_version_patch}" ]]; then
|
|
|
|
: # fall out
|
|
|
|
# Use lexicographic (instead of integer) comparison because
|
|
|
|
# version_prerelease is a string, ("alpha" or "beta",) but first check if
|
|
|
|
# either is an official release (i.e. empty prerelease string).
|
|
|
|
#
|
|
|
|
# We have to do this because lexicographically "beta" > "alpha" > "", but
|
|
|
|
# we want official > beta > alpha.
|
|
|
|
elif [[ -n "${version_prerelease}" && -z "${gcs_version_prerelease}" ]]; then
|
|
|
|
greater=false
|
|
|
|
elif [[ -z "${version_prerelease}" && -n "${gcs_version_prerelease}" ]]; then
|
|
|
|
: # fall out
|
|
|
|
elif [[ "${version_prerelease}" < "${gcs_version_prerelease}" ]]; then
|
|
|
|
greater=false
|
|
|
|
elif [[ "${version_prerelease}" > "${gcs_version_prerelease}" ]]; then
|
|
|
|
: # fall out
|
|
|
|
# Finally resort to -le here, since we want strictly-greater-than.
|
|
|
|
elif [[ "${version_prerelease_rev}" -le "${gcs_version_prerelease_rev}" ]]; then
|
2015-09-30 17:15:59 +00:00
|
|
|
greater=false
|
|
|
|
fi
|
2015-03-17 19:31:43 +00:00
|
|
|
|
2015-09-30 17:15:59 +00:00
|
|
|
if [[ "${greater}" != "true" ]]; then
|
|
|
|
kube::log::status "${new_version} (just uploaded) <= ${gcs_version} (latest on GCS), not updating ${publish_file_dst}"
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
kube::log::status "${new_version} (just uploaded) > ${gcs_version} (latest on GCS), updating ${publish_file_dst}"
|
|
|
|
fi
|
|
|
|
else # gsutil cat failed; file does not exist
|
|
|
|
kube::log::error "Release file '${publish_file_dst}' does not exist. Continuing."
|
2015-03-17 19:31:43 +00:00
|
|
|
return 0
|
|
|
|
fi
|
2015-09-30 17:15:59 +00:00
|
|
|
}
|
2015-03-17 19:31:43 +00:00
|
|
|
|
2015-10-09 17:59:21 +00:00
|
|
|
# Check if the new version is greater than or equal to the version currently
|
|
|
|
# published on GCS. (Ignore the build; if it's different, overwrite anyway.)
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# KUBE_GCS_PUBLISH_VERSION
|
|
|
|
# KUBE_GCS_RELEASE_BUCKET
|
|
|
|
# Arguments:
|
|
|
|
# publish_file: the GCS location to look in
|
|
|
|
# Returns:
|
|
|
|
# If new version is greater than the GCS version
|
2015-11-05 23:30:59 +00:00
|
|
|
#
|
|
|
|
# TODO(16529): This should all be outside of build an in release, and should be
|
|
|
|
# refactored to reduce code duplication. Also consider using strictly nested
|
|
|
|
# if and explicit handling of equals case.
|
2015-10-09 17:59:21 +00:00
|
|
|
function kube::release::gcs::verify_ci_ge() {
|
|
|
|
local -r publish_file="${1-}"
|
|
|
|
local -r new_version=${KUBE_GCS_PUBLISH_VERSION}
|
|
|
|
local -r publish_file_dst="gs://${KUBE_GCS_RELEASE_BUCKET}/${publish_file}"
|
|
|
|
|
|
|
|
kube::release::parse_and_validate_ci_version "${new_version}" || return 1
|
|
|
|
|
2015-11-18 23:52:15 +00:00
|
|
|
local -r version_major="${VERSION_MAJOR}"
|
|
|
|
local -r version_minor="${VERSION_MINOR}"
|
|
|
|
local -r version_patch="${VERSION_PATCH}"
|
|
|
|
local -r version_prerelease="${VERSION_PRERELEASE}"
|
|
|
|
local -r version_prerelease_rev="${VERSION_PRERELEASE_REV}"
|
|
|
|
local -r version_commits="${VERSION_COMMITS}"
|
2015-10-09 17:59:21 +00:00
|
|
|
|
|
|
|
local gcs_version
|
|
|
|
if gcs_version="$(gsutil cat "${publish_file_dst}")"; then
|
|
|
|
kube::release::parse_and_validate_ci_version "${gcs_version}" || {
|
|
|
|
kube::log::error "${publish_file_dst} contains invalid ci version, can't compare: '${gcs_version}'"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-11-18 23:52:15 +00:00
|
|
|
local -r gcs_version_major="${VERSION_MAJOR}"
|
|
|
|
local -r gcs_version_minor="${VERSION_MINOR}"
|
|
|
|
local -r gcs_version_patch="${VERSION_PATCH}"
|
|
|
|
local -r gcs_version_prerelease="${VERSION_PRERELEASE}"
|
|
|
|
local -r gcs_version_prerelease_rev="${VERSION_PRERELEASE_REV}"
|
|
|
|
local -r gcs_version_commits="${VERSION_COMMITS}"
|
2015-10-09 17:59:21 +00:00
|
|
|
|
|
|
|
local greater=true
|
|
|
|
if [[ "${version_major}" -lt "${gcs_version_major}" ]]; then
|
|
|
|
greater=false
|
|
|
|
elif [[ "${version_major}" -gt "${gcs_version_major}" ]]; then
|
|
|
|
: # fall out
|
|
|
|
elif [[ "${version_minor}" -lt "${gcs_version_minor}" ]]; then
|
|
|
|
greater=false
|
|
|
|
elif [[ "${version_minor}" -gt "${gcs_version_minor}" ]]; then
|
|
|
|
: # fall out
|
|
|
|
elif [[ "${version_patch}" -lt "${gcs_version_patch}" ]]; then
|
|
|
|
greater=false
|
|
|
|
elif [[ "${version_patch}" -gt "${gcs_version_patch}" ]]; then
|
|
|
|
: # fall out
|
2015-11-03 23:54:58 +00:00
|
|
|
# Use lexicographic (instead of integer) comparison because
|
|
|
|
# version_prerelease is a string, ("alpha" or "beta")
|
|
|
|
elif [[ "${version_prerelease}" < "${gcs_version_prerelease}" ]]; then
|
2015-10-09 17:59:21 +00:00
|
|
|
greater=false
|
2015-11-03 23:54:58 +00:00
|
|
|
elif [[ "${version_prerelease}" > "${gcs_version_prerelease}" ]]; then
|
2015-10-09 17:59:21 +00:00
|
|
|
: # fall out
|
2015-11-03 23:54:58 +00:00
|
|
|
elif [[ "${version_prerelease_rev}" -lt "${gcs_version_prerelease_rev}" ]]; then
|
2015-10-09 17:59:21 +00:00
|
|
|
greater=false
|
2015-11-03 23:54:58 +00:00
|
|
|
elif [[ "${version_prerelease_rev}" -gt "${gcs_version_prerelease_rev}" ]]; then
|
2015-10-09 17:59:21 +00:00
|
|
|
: # fall out
|
|
|
|
# If either version_commits is empty, it will be considered less-than, as
|
|
|
|
# expected, (e.g. 1.2.3-beta < 1.2.3-beta.1).
|
|
|
|
elif [[ "${version_commits}" -lt "${gcs_version_commits}" ]]; then
|
|
|
|
greater=false
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${greater}" != "true" ]]; then
|
|
|
|
kube::log::status "${new_version} (just uploaded) < ${gcs_version} (latest on GCS), not updating ${publish_file_dst}"
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
kube::log::status "${new_version} (just uploaded) >= ${gcs_version} (latest on GCS), updating ${publish_file_dst}"
|
|
|
|
fi
|
|
|
|
else # gsutil cat failed; file does not exist
|
|
|
|
kube::log::error "File '${publish_file_dst}' does not exist. Continuing."
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-09-30 17:15:59 +00:00
|
|
|
# Publish a release to GCS: upload a version file, if KUBE_GCS_MAKE_PUBLIC,
|
|
|
|
# make it public, and verify the result.
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# KUBE_GCS_RELEASE_BUCKET
|
|
|
|
# RELEASE_STAGE
|
|
|
|
# KUBE_GCS_PUBLISH_VERSION
|
|
|
|
# KUBE_GCS_MAKE_PUBLIC
|
|
|
|
# Arguments:
|
|
|
|
# publish_file: the GCS location to look in
|
|
|
|
# Returns:
|
|
|
|
# If new version is greater than the GCS version
|
|
|
|
function kube::release::gcs::publish() {
|
|
|
|
local -r publish_file="${1-}"
|
|
|
|
local -r publish_file_dst="gs://${KUBE_GCS_RELEASE_BUCKET}/${publish_file}"
|
|
|
|
|
|
|
|
mkdir -p "${RELEASE_STAGE}/upload" || return 1
|
|
|
|
echo "${KUBE_GCS_PUBLISH_VERSION}" > "${RELEASE_STAGE}/upload/latest" || return 1
|
|
|
|
|
|
|
|
gsutil -m cp "${RELEASE_STAGE}/upload/latest" "${publish_file_dst}" || return 1
|
|
|
|
|
|
|
|
local contents
|
|
|
|
if [[ ${KUBE_GCS_MAKE_PUBLIC} =~ ^[yY]$ ]]; then
|
2015-10-08 18:29:18 +00:00
|
|
|
kube::log::status "Making uploaded version file public and non-cacheable."
|
2015-09-30 17:15:59 +00:00
|
|
|
gsutil acl ch -R -g all:R "${publish_file_dst}" >/dev/null 2>&1 || return 1
|
2015-10-08 18:29:18 +00:00
|
|
|
gsutil setmeta -h "Cache-Control:private, max-age=0" "${publish_file_dst}" >/dev/null 2>&1 || return 1
|
2015-09-30 17:15:59 +00:00
|
|
|
# If public, validate public link
|
|
|
|
local -r public_link="https://storage.googleapis.com/${KUBE_GCS_RELEASE_BUCKET}/${publish_file}"
|
|
|
|
kube::log::status "Validating uploaded version file at ${public_link}"
|
|
|
|
contents="$(curl -s "${public_link}")"
|
|
|
|
else
|
|
|
|
# If not public, validate using gsutil
|
|
|
|
kube::log::status "Validating uploaded version file at ${publish_file_dst}"
|
|
|
|
contents="$(gsutil cat "${publish_file_dst}")"
|
|
|
|
fi
|
|
|
|
if [[ "${contents}" == "${KUBE_GCS_PUBLISH_VERSION}" ]]; then
|
|
|
|
kube::log::status "Contents as expected: ${contents}"
|
|
|
|
else
|
|
|
|
kube::log::error "Expected contents of file to be ${KUBE_GCS_PUBLISH_VERSION}, but got ${contents}"
|
|
|
|
return 1
|
|
|
|
fi
|
2015-03-17 19:31:43 +00:00
|
|
|
}
|
2015-12-23 14:07:35 +00:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Docker Release
|
|
|
|
|
|
|
|
# Releases all docker images to a docker registry specified by KUBE_DOCKER_REGISTRY
|
|
|
|
# using tag KUBE_DOCKER_IMAGE_TAG.
|
|
|
|
#
|
|
|
|
# Globals:
|
|
|
|
# KUBE_DOCKER_REGISTRY
|
|
|
|
# KUBE_DOCKER_IMAGE_TAG
|
2016-04-14 04:29:10 +00:00
|
|
|
# KUBE_SERVER_PLATFORMS
|
2015-12-23 14:07:35 +00:00
|
|
|
# Returns:
|
|
|
|
# If new pushing docker images was successful.
|
|
|
|
function kube::release::docker::release() {
|
|
|
|
local binaries=(
|
|
|
|
"kube-apiserver"
|
|
|
|
"kube-controller-manager"
|
|
|
|
"kube-scheduler"
|
|
|
|
"kube-proxy"
|
|
|
|
"hyperkube"
|
2016-06-14 21:30:51 +00:00
|
|
|
"federation-apiserver"
|
|
|
|
"federation-controller-manager"
|
2015-12-23 14:07:35 +00:00
|
|
|
)
|
|
|
|
|
2016-01-19 01:43:53 +00:00
|
|
|
local docker_push_cmd=("${DOCKER[@]}")
|
2015-12-23 14:07:35 +00:00
|
|
|
if [[ "${KUBE_DOCKER_REGISTRY}" == "gcr.io/"* ]]; then
|
|
|
|
docker_push_cmd=("gcloud" "docker")
|
|
|
|
fi
|
|
|
|
|
2016-02-05 14:41:04 +00:00
|
|
|
if [[ "${KUBE_DOCKER_REGISTRY}" == "gcr.io/google_containers" ]]; then
|
|
|
|
# Activate credentials for the k8s.production.user@gmail.com
|
|
|
|
gcloud config set account k8s.production.user@gmail.com
|
|
|
|
fi
|
2016-04-22 13:06:47 +00:00
|
|
|
|
2016-04-14 04:29:10 +00:00
|
|
|
for arch in "${KUBE_SERVER_PLATFORMS[@]##*/}"; do
|
2015-12-23 14:07:35 +00:00
|
|
|
for binary in "${binaries[@]}"; do
|
2016-02-07 18:35:14 +00:00
|
|
|
|
2016-06-15 19:59:25 +00:00
|
|
|
# TODO(IBM): Enable hyperkube builds for ppc64le again
|
|
|
|
if [[ ${binary} != "hyperkube" || ${arch} != "ppc64le" ]]; then
|
|
|
|
|
|
|
|
local docker_target="${KUBE_DOCKER_REGISTRY}/${binary}-${arch}:${KUBE_DOCKER_IMAGE_TAG}"
|
|
|
|
kube::log::status "Pushing ${binary} to ${docker_target}"
|
|
|
|
"${docker_push_cmd[@]}" push "${docker_target}"
|
2016-02-07 18:35:14 +00:00
|
|
|
|
2016-06-15 19:59:25 +00:00
|
|
|
# If we have a amd64 docker image. Tag it without -amd64 also and push it for compatibility with earlier versions
|
|
|
|
if [[ ${arch} == "amd64" ]]; then
|
|
|
|
local legacy_docker_target="${KUBE_DOCKER_REGISTRY}/${binary}:${KUBE_DOCKER_IMAGE_TAG}"
|
2016-02-19 16:45:14 +00:00
|
|
|
|
2016-06-15 19:59:25 +00:00
|
|
|
"${DOCKER[@]}" tag -f "${docker_target}" "${legacy_docker_target}" 2>/dev/null
|
2016-02-19 16:45:14 +00:00
|
|
|
|
2016-06-15 19:59:25 +00:00
|
|
|
kube::log::status "Pushing ${binary} to ${legacy_docker_target}"
|
|
|
|
"${docker_push_cmd[@]}" push "${legacy_docker_target}"
|
|
|
|
fi
|
2016-02-07 18:35:14 +00:00
|
|
|
fi
|
2015-12-23 14:07:35 +00:00
|
|
|
done
|
|
|
|
done
|
2016-02-05 14:41:04 +00:00
|
|
|
if [[ "${KUBE_DOCKER_REGISTRY}" == "gcr.io/google_containers" ]]; then
|
|
|
|
# Activate default account
|
|
|
|
gcloud config set account ${USER}@google.com
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-04-28 17:55:46 +00:00
|
|
|
function kube::release::gcloud_account_is_active() {
|
2016-02-05 14:41:04 +00:00
|
|
|
local -r account="${1-}"
|
2016-04-28 17:55:46 +00:00
|
|
|
if [[ -n $(gcloud auth list --filter-account $account 2>/dev/null | grep "active") ]]; then
|
2016-02-05 14:41:04 +00:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
2015-12-23 14:07:35 +00:00
|
|
|
}
|