Skip to content

Commit 2ee8983

Browse files
committed
Dockerize update-staging-godeps
1 parent a4d838e commit 2ee8983

File tree

5 files changed

+136
-79
lines changed

5 files changed

+136
-79
lines changed

build/common.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ function kube::build::copy_output() {
714714
--filter='- /_temp/' \
715715
--filter='+ /vendor/' \
716716
--filter='+ /Godeps/' \
717+
--filter='+ /staging/***/Godeps/**' \
717718
--filter='+ /_output/dockerized/bin/**' \
718719
--filter='+ zz_generated.*' \
719720
--filter='+ generated.proto' \

hack/lib/util.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,18 @@ function kube::util::ensure-cfssl {
824824
popd > /dev/null
825825
}
826826

827+
# kube::util::ensure_dockerized
828+
# Confirms that the script is being run inside a kube-build image
829+
#
830+
function kube::util::ensure_dockerized {
831+
if [[ -f /kube-build-image ]]; then
832+
return 0
833+
else
834+
echo "ERROR: This script is designed to be run inside a kube-build container"
835+
exit 1
836+
fi
837+
}
838+
827839
# Some useful colors.
828840
if [[ -z "${color_start-}" ]]; then
829841
declare -r color_start="\033["
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# updates the godeps.json file in the staging folders to allow clean vendoring
18+
# based on kubernetes levels.
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
25+
source "${KUBE_ROOT}/hack/lib/init.sh"
26+
27+
# Sets default values
28+
DRY_RUN=false
29+
FAIL_ON_DIFF=false
30+
GODEP_OPTS=""
31+
32+
# Controls verbosity of the script output and logging.
33+
KUBE_VERBOSE="${KUBE_VERBOSE:-5}"
34+
if (( ${KUBE_VERBOSE} >= 6 )); then
35+
GODEP_OPTS+=("-v")
36+
fi
37+
38+
while getopts ":df" opt; do
39+
case $opt in
40+
d) # do not godep-restore into a temporary directory, but use the existing GOPATH
41+
DRY_RUN=true
42+
;;
43+
f) # fail if something in the Godeps.json files changed
44+
FAIL_ON_DIFF=true
45+
;;
46+
\?)
47+
echo "Invalid option: -$OPTARG" >&2
48+
exit 1
49+
;;
50+
esac
51+
done
52+
53+
kube::util::ensure_dockerized
54+
kube::golang::setup_env
55+
kube::util::ensure_single_dir_gopath
56+
kube::util::ensure_no_staging_repos_in_gopath
57+
kube::util::ensure_godep_version v79
58+
59+
kube::log::status "Checking whether godeps are restored"
60+
if ! kube::util::godep_restored 2>&1 | sed 's/^/ /'; then
61+
${KUBE_ROOT}/hack/godep-restore.sh
62+
fi
63+
64+
kube::util::ensure-temp-dir
65+
TMP_GOPATH="${KUBE_TEMP}/go"
66+
67+
function updateGodepManifest() {
68+
pushd "${TMP_GOPATH}/src/k8s.io/${repo}" >/dev/null
69+
kube::log::status "Updating godeps for k8s.io/${repo}"
70+
rm -rf Godeps # remove the current Godeps.json so we always rebuild it
71+
GOPATH="${TMP_GOPATH}:${GOPATH}:${GOPATH}/src/k8s.io/kubernetes/staging" godep save ${GODEP_OPTS} ./... 2>&1 | sed 's/^/ /'
72+
73+
# Rewriting Godeps.json to remove commits that don't really exist because we haven't pushed the prereqs yet
74+
go run "${KUBE_ROOT}/staging/godeps-json-updater.go" --godeps-file="${TMP_GOPATH}/src/k8s.io/${repo}/Godeps/Godeps.json" --override-import-path="k8s.io/${repo}"
75+
76+
# commit so that following repos do not see this repo as dirty
77+
git add vendor >/dev/null
78+
git commit -a -m "Updated Godeps.json" >/dev/null
79+
popd >/dev/null
80+
}
81+
82+
function diffGodepManifest() {
83+
local ret=0
84+
diff --ignore-matching-lines='^\s*\"GoVersion\":' --ignore-matching-line='^\s*\"GodepVersion\":' --ignore-matching-lines='^\s*\"Comment\"' -u "${KUBE_ROOT}/staging/src/k8s.io/${repo}/Godeps/Godeps.json" "${TMP_GOPATH}/src/k8s.io/${repo}/Godeps/Godeps.json" || ret=$?
85+
if [[ "${ret}" != "0" && "${FAIL_ON_DIFF}" == true ]]; then
86+
exit ${ret}
87+
fi
88+
}
89+
90+
# move into staging and save the dependencies for everything in order
91+
mkdir -p "${TMP_GOPATH}/src/k8s.io"
92+
for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do
93+
cp -a "${KUBE_ROOT}/staging/src/k8s.io/${repo}" "${TMP_GOPATH}/src/k8s.io/"
94+
95+
pushd "${TMP_GOPATH}/src/k8s.io/${repo}" >/dev/null
96+
git init >/dev/null
97+
git config --local user.email "nobody@k8s.io"
98+
git config --local user.name "$0"
99+
git add . >/dev/null
100+
git commit -q -m "Snapshot" >/dev/null
101+
popd >/dev/null
102+
103+
updateGodepManifest
104+
diffGodepManifest
105+
106+
if [ "${DRY_RUN}" != true ]; then
107+
cp "${TMP_GOPATH}/src/k8s.io/${repo}/Godeps/Godeps.json" "${KUBE_ROOT}/staging/src/k8s.io/${repo}/Godeps/Godeps.json"
108+
# Assume Godeps.json is not updated, as the working tree needs to be clean
109+
# Without this, the script would pause after each staging repo to prompt the
110+
# user to commit all changes (difficult inside a container). It's safe to
111+
# ignore this file, as we know it's going to be changing, and we don't copy
112+
# the git tree back out from the container.
113+
git update-index --assume-unchanged "${KUBE_ROOT}/staging/src/k8s.io/${repo}/Godeps/Godeps.json"
114+
fi
115+
done

hack/update-staging-godeps.sh

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -14,91 +14,20 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# updates the godeps.json file in the staging folders to allow clean vendoring
18-
# based on kubernetes levels.
19-
# TODO this does not address client-go, since it takes a different approach to vendoring
20-
# TODO client-go should probably be made consistent
21-
2217
set -o errexit
2318
set -o nounset
2419
set -o pipefail
2520

26-
V=""
27-
DRY_RUN=false
28-
FAIL_ON_DIFF=false
29-
while getopts ":vdf" opt; do
30-
case $opt in
31-
v) # increase verbosity
32-
V="-v"
33-
;;
34-
d) # do not godep-restore into a temporary directory, but use the existing GOPATH
35-
DRY_RUN=true
36-
;;
37-
f) # fail if something in the Godeps.json files changed
38-
FAIL_ON_DIFF=true
39-
;;
40-
\?)
41-
echo "Invalid option: -$OPTARG" >&2
42-
exit 1
43-
;;
44-
esac
45-
done
46-
readonly V IN_PLACE
47-
4821
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
4922
source "${KUBE_ROOT}/hack/lib/init.sh"
50-
source "${KUBE_ROOT}/hack/lib/util.sh"
51-
52-
echo "Checking whether godeps are restored"
53-
if ! kube::util::godep_restored 2>&1 | sed 's/^/ /'; then
54-
echo -e '\nExecute script 'hack/godep-restore.sh' to download dependencies.' 1>&2
55-
exit 1
56-
fi
57-
58-
kube::util::ensure-temp-dir
59-
kube::util::ensure_single_dir_gopath
60-
kube::util::ensure_godep_version v79
61-
kube::util::ensure_no_staging_repos_in_gopath
62-
63-
TMP_GOPATH="${KUBE_TEMP}/go"
64-
65-
function updateGodepManifest() {
66-
local repo="${1}"
67-
pushd "${TMP_GOPATH}/src/k8s.io/${repo}" >/dev/null
68-
echo "Updating godeps for k8s.io/${repo}"
69-
rm -rf Godeps # remove the current Godeps.json so we always rebuild it
70-
GOPATH="${TMP_GOPATH}:${GOPATH}:${KUBE_ROOT}/staging" godep save ${V} ./... 2>&1 | sed 's/^/ /'
71-
72-
echo "Rewriting Godeps.json to remove commits that don't really exist because we haven't pushed the prereqs yet"
73-
go run "${KUBE_ROOT}/staging/godeps-json-updater.go" --godeps-file="${TMP_GOPATH}/src/k8s.io/${repo}/Godeps/Godeps.json" --override-import-path="k8s.io/${repo}"
74-
75-
# commit so that following repos do not see this repo as dirty
76-
git add vendor >/dev/null
77-
git commit -a -m "Updated Godeps.json" >/dev/null
78-
popd >/dev/null
79-
}
80-
81-
# move into staging and save the dependencies for everything in order
82-
mkdir -p "${TMP_GOPATH}/src/k8s.io"
83-
for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do
84-
kube::util::ensure_clean_working_dir
8523

86-
cp -a "${KUBE_ROOT}/staging/src/k8s.io/${repo}" "${TMP_GOPATH}/src/k8s.io/"
24+
# Ensure you have a clean working directory before starting
25+
kube::util::ensure_clean_working_dir
8726

88-
pushd "${TMP_GOPATH}/src/k8s.io/${repo}" >/dev/null
89-
git init >/dev/null
90-
git config --local user.email "nobody@k8s.io"
91-
git config --local user.name "$0"
92-
git add . >/dev/null
93-
git commit -q -m "Snapshot" >/dev/null
94-
popd >/dev/null
27+
# NOTE: All output from this script needs to be copied back to the calling
28+
# source tree. This is managed in kube::build::copy_output in build/common.sh.
29+
# If the output set is changed update that function.
9530

96-
updateGodepManifest "${repo}"
31+
${KUBE_ROOT}/build/run.sh hack/update-staging-godeps-dockerized.sh "$@"
9732

98-
if [ "${FAIL_ON_DIFF}" == true ]; then
99-
diff --ignore-matching-lines='^\s*\"GoVersion\":' --ignore-matching-line='^\s*\"GodepVersion\":' --ignore-matching-lines='^\s*\"Comment\"' -u "${KUBE_ROOT}/staging/src/k8s.io/${repo}/Godeps/Godeps.json" "${TMP_GOPATH}/src/k8s.io/${repo}/Godeps/Godeps.json"
100-
fi
101-
if [ "${DRY_RUN}" != true ]; then
102-
cp "${TMP_GOPATH}/src/k8s.io/${repo}/Godeps/Godeps.json" "${KUBE_ROOT}/staging/src/k8s.io/${repo}/Godeps/Godeps.json"
103-
fi
104-
done
33+
# ex: ts=2 sw=2 et filetype=sh

hack/verify-staging-godeps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ set -o nounset
1919
set -o pipefail
2020

2121
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
22-
${KUBE_ROOT}/hack/update-staging-godeps.sh -d -f "$@"
22+
KUBE_VERBOSE=3 KUBE_RUN_COPY_OUTPUT=N ${KUBE_ROOT}/hack/update-staging-godeps.sh -d -f "$@"

0 commit comments

Comments
 (0)