Skip to content

Commit

Permalink
Merge pull request #8516 from BenTheElder/bazel-experiments
Browse files Browse the repository at this point in the history
add BAZEL_VERSION env to kubekins, check it in caching config
  • Loading branch information
k8s-ci-robot authored Jun 30, 2018
2 parents 9d4914a + b314053 commit 46fd70b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
36 changes: 25 additions & 11 deletions images/bootstrap/create_bazel_cache_rcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,41 @@ CACHE_PORT="8080"

# get the installed version of a debian package
package_to_version () {
dpkg-query --showformat='${Version}' --show $1
dpkg-query --showformat='${Version}' --show "$1"
}

# look up a binary with which and return the debian package it belongs to
command_to_package () {
local binary_path=$(readlink -f $(which $1))
local binary_path
binary_path=$(readlink -f "$(which "$1")")
# `dpkg -S $package` spits out lines with the format: "package: file"
dpkg -S $1 | grep "${binary_path}" | cut -d':' -f1
dpkg -S "$1" | grep "${binary_path}" | cut -d':' -f1
}

# get the installed package version relating to a binary
command_to_version () {
local package=$(command_to_package $1)
local package
package=$(command_to_package "$1")
package_to_version "${package}"
}

hash_toolchains () {
# if $CC is set bazel will use this to detect c/c++ toolchains, otherwise gcc
# https://blog.bazel.build/2016/03/31/autoconfiguration.html
local cc="${CC:-gcc}"
local cc_version=$(command_to_version $cc)
local cc_version
cc_version=$(command_to_version "$cc")
# NOTE: IIRC some rules call python internally, this can't hurt
local python_version=$(command_to_version python)
local python_version
python_version=$(command_to_version python)
# the rpm packaging rules use rpmbuild
local rpmbuild_version=$(command_to_version rpmbuild)
local rpmbuild_version
rpmbuild_version=$(command_to_version rpmbuild)
# combine all tool versions into a hash
# NOTE(bentheelder): if we change the set of tools considered we should
# consider prepending the hash with a """schema version""" for completeness
local tool_versions="CC:${cc_version},PY:${python_version},RPM:${rpmbuild_version}"
local tool_versions
tool_versions="CC:${cc_version},PY:${python_version},RPM:${rpmbuild_version}"
echo "${tool_versions}" | md5sum | cut -d" " -f1
}

Expand All @@ -55,7 +61,7 @@ get_workspace () {
if [[ -n "${REPO_NAME}" ]] && [[ -n "${REPO_OWNER}" ]]; then
echo "${REPO_OWNER}/${REPO_NAME}"
else
echo "$(basename $(dirname $PWD))/$(basename $PWD)"
echo "$(basename "$(dirname "$PWD")")/$(basename "$PWD")"
fi
}

Expand All @@ -70,9 +76,17 @@ make_bazel_rc () {
# point bazel at our http cache ...
# NOTE our caches are versioned by all path segments up until the last two
# IE PUT /foo/bar/baz/cas/asdf -> is in cache "/foo/bar/baz"
local cache_id="$(get_workspace),$(hash_toolchains)"
local cache_url="http://${CACHE_HOST}:${CACHE_PORT}/${cache_id}"
local cache_id
cache_id="$(get_workspace),$(hash_toolchains)"
local cache_url
cache_url="http://${CACHE_HOST}:${CACHE_PORT}/${cache_id}"
echo "build --remote_http_cache=${cache_url}"
# specifically for bazel 0.15.0 we want to set this flag
# our docker image now sets BAZEL_VERSION with the bazel version as installed
# https://github.com/bazelbuild/bazel/issues/5047#issuecomment-401295174
if [[ -n "${BAZEL_VERSION+}" && "${BAZEL_VERSION}" -eq "0.15.0" ]]; then
echo "build --remote_max_connections=200"
fi
}

# https://docs.bazel.build/versions/master/user-manual.html#bazelrc
Expand Down
3 changes: 2 additions & 1 deletion images/kubekins-e2e/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ RUN wget -q "https://storage.googleapis.com/golang/${GO_TARBALL}" && \
rm "${GO_TARBALL}"

# install bazel
ARG BAZEL_VERSION
ARG BAZEL_VERSION_ARG
ENV BAZEL_VERSION=${BAZEL_VERSION_ARG}
RUN INSTALLER="bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh"; \
wget -q "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/${INSTALLER}" && \
chmod +x "${INSTALLER}" && "./${INSTALLER}" && rm "${INSTALLER}"
Expand Down
2 changes: 1 addition & 1 deletion images/kubekins-e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ kubetest:

build: kubetest
@echo Building with go:$(GO) and bazel:$(BAZEL)
docker build --build-arg GO_VERSION=$(GO) --build-arg BAZEL_VERSION=$(BAZEL) --build-arg CFSSL_VERSION=$(CFSSL) --build-arg IMAGE_ARG=$(IMG):$(TAG)-$(K8S) -t $(IMG):$(TAG)-$(K8S) .
docker build --build-arg GO_VERSION=$(GO) --build-arg BAZEL_VERSION_ARG=$(BAZEL) --build-arg CFSSL_VERSION=$(CFSSL) --build-arg IMAGE_ARG=$(IMG):$(TAG)-$(K8S) -t $(IMG):$(TAG)-$(K8S) .
docker tag $(IMG):$(TAG)-$(K8S) $(IMG):latest-$(K8S)
rm kubetest
@echo Built $(IMG):$(TAG)-$(K8S) and tagged with latest-$(K8S)
Expand Down

0 comments on commit 46fd70b

Please sign in to comment.