From f3b9fa62d6a3aacaa5fede2930a452a782f2876a Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Mon, 8 Feb 2016 19:21:44 -0800 Subject: [PATCH] push kube-cross to gcr.io And do as much of the build setup work in it as possible. --- build/build-image/Dockerfile | 38 +++----------------------- build/build-image/cross/Dockerfile | 26 +++++++++++++++--- build/build-image/cross/Makefile | 26 ++++++++++++++++++ build/build-image/cross/VERSION | 1 + build/common.sh | 43 ++++-------------------------- 5 files changed, 58 insertions(+), 76 deletions(-) create mode 100644 build/build-image/cross/Makefile create mode 100644 build/build-image/cross/VERSION diff --git a/build/build-image/Dockerfile b/build/build-image/Dockerfile index 4ad4b48520d..91cc721149e 100644 --- a/build/build-image/Dockerfile +++ b/build/build-image/Dockerfile @@ -13,41 +13,11 @@ # limitations under the License. # This file creates a standard build environment for building Kubernetes +FROM gcr.io/google_containers/kube-cross:KUBE_BUILD_IMAGE_CROSS_TAG -# We replace KUBE_BUILD_IMAGE_CROSS in build/common.sh with the actual -# cross-build image tag. -FROM KUBE_BUILD_IMAGE_CROSS - -MAINTAINER Joe Beda - -ENV GOOS linux -ENV GOARCH amd64 -ENV http_proxy KUBE_BUILD_HTTP_PROXY -ENV https_proxy KUBE_BUILD_HTTPS_PROXY -ENV no_proxy KUBE_BUILD_NO_PROXY - - -# work around 64MB tmpfs size in Docker 1.6 -ENV TMPDIR /tmp.k8s - -# Get the code coverage tool and godep -RUN mkdir $TMPDIR && \ - go get golang.org/x/tools/cmd/cover github.com/tools/godep - -# We use rsync to copy some binaries around. It is faster (0.3s vs. 1.1s) on my -# machine vs. `install` -RUN rm -rf /var/lib/apt/lists/ \ - && apt-get -o Acquire::Check-Valid-Until=false update \ - && apt-get install -y rsync \ - && rm -rf /var/lib/apt/lists/ - -# Download and symlink etcd. We need this for our integration tests. -RUN export ETCD_VERSION=v2.2.1; \ - mkdir -p /usr/local/src/etcd &&\ - cd /usr/local/src/etcd &&\ - curl -fsSLO https://github.com/coreos/etcd/releases/download/$ETCD_VERSION/etcd-$ETCD_VERSION-linux-amd64.tar.gz &&\ - tar xzf etcd-$ETCD_VERSION-linux-amd64.tar.gz &&\ - ln -s ../src/etcd/etcd-$ETCD_VERSION-linux-amd64/etcd /usr/local/bin/ +ENV http_proxy=KUBE_BUILD_HTTP_PROXY \ + https_proxy=KUBE_BUILD_HTTPS_PROXY \ + no_proxy=KUBE_BUILD_NO_PROXY # Mark this as a kube-build container RUN touch /kube-build-image diff --git a/build/build-image/cross/Dockerfile b/build/build-image/cross/Dockerfile index e5d70a9c8c9..333a6e30703 100644 --- a/build/build-image/cross/Dockerfile +++ b/build/build-image/cross/Dockerfile @@ -16,7 +16,6 @@ # platform go binary for the architecture kubernetes cares about. FROM golang:1.4.2 -MAINTAINER Joe Beda ENV GOARM 6 ENV KUBE_DYNAMIC_CROSSPLATFORMS \ @@ -28,11 +27,15 @@ ENV KUBE_CROSSPLATFORMS \ darwin/amd64 darwin/386 \ windows/amd64 windows/386 -RUN cd /usr/src/go/src && for platform in ${KUBE_CROSSPLATFORMS}; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean; done +RUN cd /usr/src/go/src \ + && for platform in ${KUBE_CROSSPLATFORMS}; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean; done # Install g++, then download and install protoc for generating protobuf output -RUN apt-get install -y g++ && apt-get clean && rm -rf /var/lib/apt/lists/* &&\ - mkdir -p /usr/local/src/protobuf && cd /usr/local/src/protobuf &&\ +RUN apt-get update \ + && apt-get install -y g++ rsync \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /usr/local/src/protobuf && cd /usr/local/src/protobuf &&\ wget -q https://github.com/google/protobuf/releases/download/v3.0.0-beta-2/protobuf-cpp-3.0.0-beta-2.tar.gz &&\ tar xzvf protobuf-cpp-3.0.0-beta-2.tar.gz &&\ cd protobuf-3.0.0-beta-2 &&\ @@ -52,3 +55,18 @@ RUN echo "deb http://emdebian.org/tools/debian/ jessie main" > /etc/apt/sources. && apt-get install -y build-essential \ && for platform in ${KUBE_DYNAMIC_CROSSPLATFORMS}; do apt-get install -y crossbuild-essential-${platform}; done \ && apt-get clean && rm -rf /var/lib/apt/lists/* + +# work around 64MB tmpfs size in Docker 1.6 +ENV TMPDIR /tmp.k8s + +# Get the code coverage tool and godep +RUN mkdir $TMPDIR && \ + go get golang.org/x/tools/cmd/cover github.com/tools/godep + +# Download and symlink etcd. We need this for our integration tests. +RUN export ETCD_VERSION=v2.2.1; \ + mkdir -p /usr/local/src/etcd &&\ + cd /usr/local/src/etcd &&\ + curl -fsSLO https://github.com/coreos/etcd/releases/download/$ETCD_VERSION/etcd-$ETCD_VERSION-linux-amd64.tar.gz &&\ + tar xzf etcd-$ETCD_VERSION-linux-amd64.tar.gz &&\ + ln -s ../src/etcd/etcd-$ETCD_VERSION-linux-amd64/etcd /usr/local/bin/ diff --git a/build/build-image/cross/Makefile b/build/build-image/cross/Makefile new file mode 100644 index 00000000000..c019bdef0fc --- /dev/null +++ b/build/build-image/cross/Makefile @@ -0,0 +1,26 @@ +# Copyright 2016 The Kubernetes Authors All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.PHONY: build push + +IMAGE = kube-cross +TAG = $(shell cat VERSION) + +build: + docker build -t gcr.io/google_containers/$(IMAGE):$(TAG) . + +push: build + gcloud docker --server=gcr.io push gcr.io/google_containers/$(IMAGE):$(TAG) + +all: push diff --git a/build/build-image/cross/VERSION b/build/build-image/cross/VERSION new file mode 100644 index 00000000000..b7ebb10f40d --- /dev/null +++ b/build/build-image/cross/VERSION @@ -0,0 +1 @@ +v1.4.2-1 diff --git a/build/common.sh b/build/common.sh index 7fd671834f5..2d8af352020 100755 --- a/build/common.sh +++ b/build/common.sh @@ -48,10 +48,8 @@ readonly KUBE_GCS_DELETE_EXISTING="${KUBE_GCS_DELETE_EXISTING:-n}" # Constants readonly KUBE_BUILD_IMAGE_REPO=kube-build -readonly KUBE_BUILD_GOLANG_VERSION=1.4.2 -readonly KUBE_BUILD_IMAGE_CROSS_TAG="cross-${KUBE_BUILD_GOLANG_VERSION}-2" -readonly KUBE_BUILD_IMAGE_CROSS="${KUBE_BUILD_IMAGE_REPO}:${KUBE_BUILD_IMAGE_CROSS_TAG}" -# KUBE_BUILD_DATA_CONTAINER_NAME=kube-build-data- +readonly KUBE_BUILD_IMAGE_CROSS_TAG="v1.4.2-1" +# KUBE_BUILD_DATA_CONTAINER_NAME=kube-build-data-" # Here we map the output directories across both the local and remote _output # directories: @@ -248,7 +246,7 @@ function kube::build::update_dockerfile() { else sed_opts=(-i) fi - sed ${sed_opts[@]} "s/KUBE_BUILD_IMAGE_CROSS/${KUBE_BUILD_IMAGE_CROSS}/" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile" + sed ${sed_opts[@]} "s/KUBE_BUILD_IMAGE_CROSS_TAG/${KUBE_BUILD_IMAGE_CROSS_TAG}/" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile" sed ${sed_opts[@]} "s#KUBE_BUILD_HTTP_PROXY#${KUBE_BUILD_HTTP_PROXY:-\"\"}#" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile" sed ${sed_opts[@]} "s#KUBE_BUILD_HTTPS_PROXY#${KUBE_BUILD_HTTPS_PROXY:-\"\"}#" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile" sed ${sed_opts[@]} "s#KUBE_BUILD_NO_PROXY#${KUBE_BUILD_NO_PROXY:-127.0.0.1}#" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile" @@ -460,23 +458,6 @@ function kube::build::build_image_built() { kube::build::docker_image_exists "${KUBE_BUILD_IMAGE_REPO}" "${KUBE_BUILD_IMAGE_TAG}" } -function kube::build::ensure_golang() { - kube::build::docker_image_exists golang "${KUBE_BUILD_GOLANG_VERSION}" || { - [[ ${KUBE_SKIP_CONFIRMATIONS} =~ ^[yY]$ ]] || { - echo "You don't have a local copy of the golang:${KUBE_BUILD_GOLANG_VERSION} docker image. This image is 450MB." - read -p "Download it now? [y/n] " -r - echo - [[ $REPLY =~ ^[yY]$ ]] || { - echo "Aborting." >&2 - exit 1 - } - } - - kube::log::status "Pulling docker image: golang:${KUBE_BUILD_GOLANG_VERSION}" - "${DOCKER[@]}" pull golang:${KUBE_BUILD_GOLANG_VERSION} - } -} - # The set of source targets to include in the kube-build image function kube::build::source_targets() { local targets=( @@ -512,8 +493,6 @@ function kube::build::source_targets() { function kube::build::build_image() { kube::build::ensure_tar - kube::build::build_image_cross - mkdir -p "${LOCAL_OUTPUT_BUILD_CONTEXT}" "${TAR}" czf "${LOCAL_OUTPUT_BUILD_CONTEXT}/kube-source.tar.gz" $(kube::build::source_targets) @@ -523,21 +502,9 @@ function kube::build::build_image() { cp build/build-image/Dockerfile "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile" kube::build::update_dockerfile - # We don't want to force-pull this image because it's based on a local image - # (see kube::build::build_image_cross), not upstream. kube::build::docker_build "${KUBE_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false' } -# Build the kubernetes golang cross base image. -function kube::build::build_image_cross() { - kube::build::ensure_golang - - local -r build_context_dir="${LOCAL_OUTPUT_ROOT}/images/${KUBE_BUILD_IMAGE}/cross" - mkdir -p "${build_context_dir}" - cp build/build-image/cross/Dockerfile ${build_context_dir}/Dockerfile - kube::build::docker_build "${KUBE_BUILD_IMAGE_CROSS}" "${build_context_dir}" -} - # 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. @@ -779,7 +746,7 @@ function kube::release::package_server_tarballs() { "${release_stage}/server/bin/" kube::release::create_docker_images_for_server "${release_stage}/server/bin" "${arch}" - + # Only release addon images for linux/amd64. These addon images aren't necessary for other architectures if [[ ${platform} == "linux/amd64" ]]; then kube::release::write_addon_docker_images_for_server "${release_stage}/addons" @@ -906,7 +873,7 @@ function kube::release::write_addon_docker_images_for_server() { if [[ ! -z "${BUILD_PYTHON_IMAGE:-}" ]]; then ( kube::log::status "Building Docker python image" - + local img_name=python:2.7-slim-pyyaml "${DOCKER[@]}" build -t "${img_name}" "${KUBE_ROOT}/cluster/addons/python-image" "${DOCKER[@]}" save "${img_name}" > "${1}/${img_name}.tar"