mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Namespace bash functions under build
This commit is contained in:
parent
c588207639
commit
233765967b
@ -51,7 +51,7 @@ readonly RELEASE_DIR="${KUBE_REPO_ROOT}/_output/release"
|
|||||||
# Basic setup functions
|
# Basic setup functions
|
||||||
|
|
||||||
# Verify that the right utilities and such are installed for building Kube.
|
# Verify that the right utilities and such are installed for building Kube.
|
||||||
function verify-prereqs() {
|
function kube::build::verify-prereqs() {
|
||||||
if [[ -z "$(which docker)" ]]; then
|
if [[ -z "$(which docker)" ]]; then
|
||||||
echo "Can't find 'docker' in PATH, please fix and retry." >&2
|
echo "Can't find 'docker' in PATH, please fix and retry." >&2
|
||||||
echo "See https://docs.docker.com/installation/#installation for installation instructions." >&2
|
echo "See https://docs.docker.com/installation/#installation for installation instructions." >&2
|
||||||
@ -83,7 +83,7 @@ function verify-prereqs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Verify things are set up for uploading to GCS
|
# Verify things are set up for uploading to GCS
|
||||||
function verify-gcs-prereqs() {
|
function kube::build::verify-gcs-prereqs() {
|
||||||
if [[ -z "$(which gsutil)" || -z "$(which gcloud)" ]]; then
|
if [[ -z "$(which gsutil)" || -z "$(which gcloud)" ]]; then
|
||||||
echo "Releasing Kubernetes requires gsutil and gcloud. Please download,"
|
echo "Releasing Kubernetes requires gsutil and gcloud. Please download,"
|
||||||
echo "install and authorize through the Google Cloud SDK: "
|
echo "install and authorize through the Google Cloud SDK: "
|
||||||
@ -115,7 +115,7 @@ function verify-gcs-prereqs() {
|
|||||||
# Building
|
# Building
|
||||||
|
|
||||||
# Set up the context directory for the kube-build image and build it.
|
# Set up the context directory for the kube-build image and build it.
|
||||||
function build-image() {
|
function kube::build::build-image() {
|
||||||
local -r BUILD_CONTEXT_DIR="${KUBE_REPO_ROOT}/_output/images/${KUBE_BUILD_IMAGE}"
|
local -r BUILD_CONTEXT_DIR="${KUBE_REPO_ROOT}/_output/images/${KUBE_BUILD_IMAGE}"
|
||||||
local -r SOURCE="
|
local -r SOURCE="
|
||||||
api
|
api
|
||||||
@ -125,20 +125,20 @@ function build-image() {
|
|||||||
Godeps
|
Godeps
|
||||||
hack
|
hack
|
||||||
LICENSE
|
LICENSE
|
||||||
README.md
|
|
||||||
pkg
|
pkg
|
||||||
plugin
|
plugin
|
||||||
|
README.md
|
||||||
third_party
|
third_party
|
||||||
"
|
"
|
||||||
mkdir -p ${BUILD_CONTEXT_DIR}
|
mkdir -p ${BUILD_CONTEXT_DIR}
|
||||||
tar czf ${BUILD_CONTEXT_DIR}/kube-source.tar.gz ${SOURCE}
|
tar czf ${BUILD_CONTEXT_DIR}/kube-source.tar.gz ${SOURCE}
|
||||||
cp build/build-image/Dockerfile ${BUILD_CONTEXT_DIR}/Dockerfile
|
cp build/build-image/Dockerfile ${BUILD_CONTEXT_DIR}/Dockerfile
|
||||||
docker-build "${KUBE_BUILD_IMAGE}" "${BUILD_CONTEXT_DIR}"
|
kube::build::docker-build "${KUBE_BUILD_IMAGE}" "${BUILD_CONTEXT_DIR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Builds the runtime image. Assumes that the appropriate binaries are already
|
# Builds the runtime image. Assumes that the appropriate binaries are already
|
||||||
# built and in _output/build/.
|
# built and in _output/build/.
|
||||||
function run-image() {
|
function kube::build::run-image() {
|
||||||
local -r BUILD_CONTEXT_BASE="${KUBE_REPO_ROOT}/_output/images/${KUBE_RUN_IMAGE_BASE}"
|
local -r BUILD_CONTEXT_BASE="${KUBE_REPO_ROOT}/_output/images/${KUBE_RUN_IMAGE_BASE}"
|
||||||
|
|
||||||
# First build the base image. This one brings in all of the binaries.
|
# First build the base image. This one brings in all of the binaries.
|
||||||
@ -147,20 +147,20 @@ function run-image() {
|
|||||||
-C "_output/build/linux/amd64" \
|
-C "_output/build/linux/amd64" \
|
||||||
${KUBE_RUN_BINARIES}
|
${KUBE_RUN_BINARIES}
|
||||||
cp -R build/run-images/base/* "${BUILD_CONTEXT_BASE}/"
|
cp -R build/run-images/base/* "${BUILD_CONTEXT_BASE}/"
|
||||||
docker-build "${KUBE_RUN_IMAGE_BASE}" "${BUILD_CONTEXT_BASE}"
|
kube::build::docker-build "${KUBE_RUN_IMAGE_BASE}" "${BUILD_CONTEXT_BASE}"
|
||||||
|
|
||||||
for b in $KUBE_RUN_BINARIES ; do
|
for b in $KUBE_RUN_BINARIES ; do
|
||||||
local SUB_CONTEXT_DIR="${BUILD_CONTEXT_BASE}-$b"
|
local SUB_CONTEXT_DIR="${BUILD_CONTEXT_BASE}-$b"
|
||||||
mkdir -p "${SUB_CONTEXT_DIR}"
|
mkdir -p "${SUB_CONTEXT_DIR}"
|
||||||
cp -R build/run-images/$b/* "${SUB_CONTEXT_DIR}/"
|
cp -R build/run-images/$b/* "${SUB_CONTEXT_DIR}/"
|
||||||
docker-build "${KUBE_RUN_IMAGE_BASE}-$b" "${SUB_CONTEXT_DIR}"
|
kube::build::docker-build "${KUBE_RUN_IMAGE_BASE}-$b" "${SUB_CONTEXT_DIR}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build a docker image from a Dockerfile.
|
# Build a docker image from a Dockerfile.
|
||||||
# $1 is the name of the image to build
|
# $1 is the name of the image to build
|
||||||
# $2 is the location of the "context" directory, with the Dockerfile at the root.
|
# $2 is the location of the "context" directory, with the Dockerfile at the root.
|
||||||
function docker-build() {
|
function kube::build::docker-build() {
|
||||||
local -r IMAGE=$1
|
local -r IMAGE=$1
|
||||||
local -r CONTEXT_DIR=$2
|
local -r CONTEXT_DIR=$2
|
||||||
local -r BUILD_CMD="docker build -t ${IMAGE} ${CONTEXT_DIR}"
|
local -r BUILD_CMD="docker build -t ${IMAGE} ${CONTEXT_DIR}"
|
||||||
@ -185,7 +185,7 @@ function docker-build() {
|
|||||||
|
|
||||||
# Run a command in the kube-build image. This assumes that the image has
|
# 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.
|
# already been built. This will sync out all output data from the build.
|
||||||
function run-build-command() {
|
function kube::build::run-build-command() {
|
||||||
[[ -n "$@" ]] || { echo "Invalid input." >&2; return 4; }
|
[[ -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}"
|
||||||
@ -196,7 +196,7 @@ function run-build-command() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# If the Docker server is remote, copy the results back out.
|
# If the Docker server is remote, copy the results back out.
|
||||||
function copy-output() {
|
function kube::build::copy-output() {
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
# When we are on the Mac with boot2docker we need to copy the results back
|
# 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
|
# out. Ideally we would leave the container around and use 'docker cp' to
|
||||||
@ -232,7 +232,7 @@ function copy-output() {
|
|||||||
# Release
|
# Release
|
||||||
|
|
||||||
# Create a unique bucket name for releasing Kube and make sure it exists.
|
# Create a unique bucket name for releasing Kube and make sure it exists.
|
||||||
function ensure-gcs-release-bucket() {
|
function kube::build::ensure-gcs-release-bucket() {
|
||||||
if which md5 > /dev/null 2>&1; then
|
if which md5 > /dev/null 2>&1; then
|
||||||
HASH=$(md5 -q -s "$GCLOUD_PROJECT")
|
HASH=$(md5 -q -s "$GCLOUD_PROJECT")
|
||||||
else
|
else
|
||||||
@ -249,7 +249,7 @@ function ensure-gcs-release-bucket() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensure-gcs-docker-registry() {
|
function kube::build::ensure-gcs-docker-registry() {
|
||||||
local -r REG_CONTAINER_NAME="gcs-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 \
|
||||||
@ -283,8 +283,8 @@ function ensure-gcs-docker-registry() {
|
|||||||
sleep 5
|
sleep 5
|
||||||
}
|
}
|
||||||
|
|
||||||
function push-images-to-gcs() {
|
function kube::build::push-images-to-gcs() {
|
||||||
ensure-gcs-docker-registry
|
kube::build::ensure-gcs-docker-registry
|
||||||
|
|
||||||
# Tag each of our run binaries with the right registry and push
|
# Tag each of our run binaries with the right registry and push
|
||||||
for b in ${KUBE_RUN_BINARIES} ; do
|
for b in ${KUBE_RUN_BINARIES} ; do
|
||||||
@ -296,7 +296,7 @@ function push-images-to-gcs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Package up all of the cross compiled clients
|
# Package up all of the cross compiled clients
|
||||||
function package-tarballs() {
|
function kube::build::package-tarballs() {
|
||||||
mkdir -p "${RELEASE_DIR}"
|
mkdir -p "${RELEASE_DIR}"
|
||||||
|
|
||||||
# Find all of the built kubecfg binaries
|
# Find all of the built kubecfg binaries
|
||||||
@ -318,7 +318,7 @@ function package-tarballs() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy-release-to-gcs() {
|
function kube::build::copy-release-to-gcs() {
|
||||||
# TODO: This isn't atomic. There will be points in time where there will be
|
# 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-
|
# 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
|
# copied. The real way to do this would perhaps to have some sort of release
|
||||||
|
@ -23,5 +23,5 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
copy-output
|
kube::build::copy-output
|
||||||
|
@ -23,6 +23,6 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
build-image
|
kube::build::build-image
|
||||||
run-build-command build/build-image/make-binaries.sh "$@"
|
kube::build::run-build-command build/build-image/make-binaries.sh "$@"
|
||||||
|
@ -25,5 +25,5 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
build-image
|
kube::build::build-image
|
||||||
|
@ -20,6 +20,6 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
build-image
|
kube::build::build-image
|
||||||
run-build-command rm -rf _output/build/*
|
kube::build::run-build-command rm -rf _output/build/*
|
||||||
|
@ -23,6 +23,6 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
build-image
|
kube::build::build-image
|
||||||
run-build-command build/build-image/make-cross.sh
|
kube::build::run-build-command build/build-image/make-cross.sh
|
||||||
|
@ -23,8 +23,8 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
build-image
|
kube::build::build-image
|
||||||
run-build-command build/build-image/make-binaries.sh "$@"
|
kube::build::run-build-command build/build-image/make-binaries.sh "$@"
|
||||||
copy-output
|
kube::build::copy-output
|
||||||
run-image
|
kube::build::run-image
|
||||||
|
@ -22,16 +22,16 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
verify-gcs-prereqs
|
kube::build::verify-gcs-prereqs
|
||||||
ensure-gcs-release-bucket
|
kube::build::ensure-gcs-release-bucket
|
||||||
build-image
|
kube::build::build-image
|
||||||
run-build-command build/build-image/make-binaries.sh
|
kube::build::run-build-command build/build-image/make-binaries.sh
|
||||||
run-build-command build/build-image/make-cross.sh
|
kube::build::run-build-command build/build-image/make-cross.sh
|
||||||
run-build-command build/build-image/run-tests.sh
|
kube::build::run-build-command build/build-image/run-tests.sh
|
||||||
run-build-command build/build-image/run-integration.sh
|
kube::build::run-build-command build/build-image/run-integration.sh
|
||||||
copy-output
|
kube::build::copy-output
|
||||||
run-image
|
kube::build::run-image
|
||||||
package-tarballs
|
kube::build::package-tarballs
|
||||||
push-images-to-gcs
|
kube::build::push-images-to-gcs
|
||||||
copy-release-to-gcs
|
kube::build::copy-release-to-gcs
|
||||||
|
@ -20,7 +20,7 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
build-image
|
kube::build::build-image
|
||||||
run-build-command build/build-image/make-binaries.sh "integration"
|
kube::build::run-build-command build/build-image/make-binaries.sh "integration"
|
||||||
run-build-command build/build-image/run-integration.sh
|
kube::build::run-build-command build/build-image/run-integration.sh
|
||||||
|
@ -20,6 +20,6 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
build-image
|
kube::build::build-image
|
||||||
run-build-command build/build-image/run-tests.sh "$@"
|
kube::build::run-build-command build/build-image/run-tests.sh "$@"
|
||||||
|
@ -22,6 +22,6 @@ set -e
|
|||||||
|
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
verify-prereqs
|
kube::build::verify-prereqs
|
||||||
build-image
|
kube::build::build-image
|
||||||
run-build-command bash
|
kube::build::run-build-command bash
|
||||||
|
Loading…
Reference in New Issue
Block a user