Skip to content

Commit

Permalink
Run builds as the calling user
Browse files Browse the repository at this point in the history
This means no 'sudo' is needed to copy files out.
  • Loading branch information
thockin committed Jul 3, 2016
1 parent feea382 commit ac75bd1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
9 changes: 8 additions & 1 deletion build/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ FROM gcr.io/google_containers/kube-cross:KUBE_BUILD_IMAGE_CROSS_TAG
# Mark this as a kube-build container
RUN touch /kube-build-image

WORKDIR /go/src/k8s.io/kubernetes
# TO run as non-root we sometimes need to rebuild go stdlib packages.
RUN chmod -R a+rwx /usr/local/go/pkg

# The kubernetes source is expected to be mounted here. This will be the base
# of operations.
ENV HOME /go/src/k8s.io/kubernetes
WORKDIR ${HOME}
RUN chmod -R a+rwx ${HOME}

# Propagate the git tree version into the build image
ADD kube-version-defs /kube-version-defs
Expand Down
9 changes: 6 additions & 3 deletions build/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ function kube::build::ensure_data_container() {
"${DOCKER[@]}" run
"${DOCKER_DATA_MOUNT_ARGS[@]}"
--name "${KUBE_BUILD_DATA_CONTAINER_NAME}"
--user "$(id -u):$(id -g)"
"${KUBE_BUILD_IMAGE}"
true
)
Expand All @@ -583,6 +584,7 @@ function kube::build::run_build_command() {

local -a docker_run_opts=(
"--name=${KUBE_BUILD_CONTAINER_NAME}"
"--user=$(id -u):$(id -g)"
"${DOCKER_MOUNT_ARGS[@]}"
)

Expand Down Expand Up @@ -635,9 +637,10 @@ function kube::build::copy_output() {
# Bug: https://github.com/docker/docker/pull/8509
local -a docker_run_opts=(
"--name=${KUBE_BUILD_CONTAINER_NAME}"
"${DOCKER_MOUNT_ARGS[@]}"
-d
)
"--user=$(id -u):$(id -g)"
"${DOCKER_MOUNT_ARGS[@]}"
-d
)

local -ra docker_cmd=(
"${DOCKER[@]}" run "${docker_run_opts[@]}" "${KUBE_BUILD_IMAGE}"
Expand Down
7 changes: 5 additions & 2 deletions hack/update-generated-protobuf-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

kube::golang::setup_env

hack/build-go.sh cmd/libs/go2idl/go-to-protobuf cmd/libs/go2idl/go-to-protobuf/protoc-gen-gogo
hack/build-go.sh \
cmd/libs/go2idl/go-to-protobuf \
cmd/libs/go2idl/go-to-protobuf/protoc-gen-gogo

if [[ -z "$(which protoc)" || "$(protoc --version)" != "libprotoc 3.0."* ]]; then
echo "Generating protobuf requires protoc 3.0.0-beta1 or newer. Please download and"
Expand All @@ -39,7 +41,8 @@ gotoprotobuf=$(kube::util::find-binary "go-to-protobuf")

# requires the 'proto' tag to build (will remove when ready)
# searches for the protoc-gen-gogo extension in the output directory
# satisfies import of github.com/gogo/protobuf/gogoproto/gogo.proto and the core Google protobuf types
# satisfies import of github.com/gogo/protobuf/gogoproto/gogo.proto and the
# core Google protobuf types
PATH="${KUBE_ROOT}/_output/local/go/bin:${PATH}" \
"${gotoprotobuf}" \
--proto-import="${KUBE_ROOT}/vendor" \
Expand Down
8 changes: 1 addition & 7 deletions hack/update-generated-protobuf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ function prereqs() {
KUBE_BUILD_CONTAINER_NAME="kube-build-${KUBE_ROOT_HASH}"
KUBE_BUILD_DATA_CONTAINER_NAME="kube-build-data-${KUBE_ROOT_HASH}"
DOCKER_MOUNT_ARGS=(
--volume "${REPO_DIR:-${KUBE_ROOT}}/cluster:/go/src/${KUBE_GO_PACKAGE}/cluster"
--volume "${REPO_DIR:-${KUBE_ROOT}}/cmd:/go/src/${KUBE_GO_PACKAGE}/cmd"
--volume "${REPO_DIR:-${KUBE_ROOT}}/vendor:/go/src/${KUBE_GO_PACKAGE}/vendor"
--volume "${REPO_DIR:-${KUBE_ROOT}}/hack:/go/src/${KUBE_GO_PACKAGE}/hack"
--volume "${REPO_DIR:-${KUBE_ROOT}}/pkg:/go/src/${KUBE_GO_PACKAGE}/pkg"
--volume "${REPO_DIR:-${KUBE_ROOT}}/federation:/go/src/${KUBE_GO_PACKAGE}/federation"
--volume "${REPO_DIR:-${KUBE_ROOT}}/third_party:/go/src/${KUBE_GO_PACKAGE}/third_party"
--volume "${REPO_DIR:-${KUBE_ROOT}}:/go/src/${KUBE_GO_PACKAGE}"
--volume /etc/localtime:/etc/localtime:ro
--volumes-from "${KUBE_BUILD_DATA_CONTAINER_NAME}"
)
Expand Down
9 changes: 1 addition & 8 deletions hack/verify-generated-protobuf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,13 @@ for APIROOT in ${APIROOTS}; do
cp -a "${KUBE_ROOT}/${APIROOT}" "${_tmp}/${APIROOT}"
done

# If not running as root, we need to use sudo to restore the original generated
# protobuf files.
SUDO=""
if [[ "$(id -u)" != '0' ]]; then
SUDO="sudo"
fi

"${KUBE_ROOT}/hack/update-generated-protobuf.sh"
for APIROOT in ${APIROOTS}; do
TMP_APIROOT="${_tmp}/${APIROOT}"
echo "diffing ${APIROOT} against freshly generated protobuf"
ret=0
diff -Naupr -I 'Auto generated by' "${KUBE_ROOT}/${APIROOT}" "${TMP_APIROOT}" || ret=$?
${SUDO} cp -a "${TMP_APIROOT}" "${KUBE_ROOT}/${APIROOT%/*}"
cp -a "${TMP_APIROOT}" "${KUBE_ROOT}/${APIROOT%/*}"
if [[ $ret -eq 0 ]]; then
echo "${APIROOT} up to date."
else
Expand Down

0 comments on commit ac75bd1

Please sign in to comment.