Skip to content

Commit

Permalink
Merge pull request #51766 from thockin/godep-scripts-cleanup
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Godep scripts cleanup

Another try at sanitizing godep scripts.  Instead of messing with containers, or assuming anything about GOPATHs, let's just work with whatever GOPATH we are given.  If you want sane godep/restore behavior you can use `./hack/run-in-gopath.sh ./hack/godep-restore.sh`.  This will restore into your _output dir.  You can update deps yourself, and then run `./hack/run-in-gopath.sh ./hack/godep-save.sh`.

xref  #44873

This also checks out godep into your working GOPATH.  Without this, we have to `go get` it every time.  We should just vendor it.
  • Loading branch information
Kubernetes Submit Queue committed Sep 30, 2017
2 parents 628df56 + ac4ffb1 commit d2bbeb6
Show file tree
Hide file tree
Showing 56 changed files with 6,318 additions and 58 deletions.
19 changes: 19 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions Godeps/LICENSES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions hack/godep-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"

kube::util::ensure_godep_version v79
kube::log::status "Restoring kubernetes godeps"

kube::log::status "Starting to download all kubernetes godeps. This takes a while"
GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep restore "$@"
kube::log::status "Download finished"
if kube::util::godep_restored >/dev/null 2>&1; then
kube::log::status "Dependencies appear to be current - skipping download"
exit 0
fi

kube::util::ensure_godep_version

kube::log::status "Downloading dependencies - this might take a while"
GOPATH="${GOPATH}:${KUBE_ROOT}/staging" godep restore "$@"
kube::log::status "Done"
77 changes: 53 additions & 24 deletions hack/godep-save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,69 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"

kube::log::status "Ensuring prereqs"
kube::util::ensure_single_dir_gopath
kube::util::ensure_godep_version v79
kube::util::ensure_no_staging_repos_in_gopath

if [ -e "${KUBE_ROOT}/vendor" -o -e "${KUBE_ROOT}/Godeps" ]; then
echo "The directory vendor/ or Godeps/ exists. Remove them before running godep-save.sh" 1>&2
exit 1
kube::util::ensure_godep_version

BACKUP=_tmp/godep-save.$RANDOM
mkdir -p "${BACKUP}"

function kube::godep_save::cleanup() {
if [[ -d "${BACKUP}/vendor" ]]; then
kube::log::error "${BACKUP}/vendor exists, restoring it"
rm -rf vendor
mv "${BACKUP}/vendor" vendor
fi
if [[ -d "${BACKUP}/Godeps" ]]; then
kube::log::error "${BACKUP}/Godeps exists, restoring it"
rm -rf Godeps
mv "${BACKUP}/Godeps" Godeps
fi
}
kube::util::trap_add kube::godep_save::cleanup EXIT

# Clear old state, but save it in case of error
if [[ -d vendor ]]; then
mv vendor "${BACKUP}/vendor"
fi
if [[ -d Godeps ]]; then
mv Godeps "${BACKUP}/Godeps"
fi

# Some things we want in godeps aren't code dependencies, so ./...
# won't pick them up.
REQUIRED_BINS=(
"github.com/onsi/ginkgo/ginkgo"
"github.com/jteeuwen/go-bindata/go-bindata"
"github.com/tools/godep"
"./..."
)

pushd "${KUBE_ROOT}" > /dev/null
echo "Running godep save. This will take around 15 minutes."
GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep save "${REQUIRED_BINS[@]}"

# create a symlink in vendor directory pointing to the staging client. This
# let other packages use the staging client as if it were vendored.
for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do
if [ ! -e "vendor/k8s.io/${repo}" ]; then
ln -s "../../staging/src/k8s.io/${repo}" "vendor/k8s.io/${repo}"
fi
done
popd > /dev/null

# Workaround broken symlink in docker repo because godep copies the link, but not the target
rm -rf ${KUBE_ROOT}/vendor/github.com/docker/docker/project/

echo
echo "Don't forget to run:"
echo "- hack/update-bazel.sh to recreate the BUILD files"
echo "- hack/update-godep-licenses.sh if you added or removed a dependency!"
kube::log::status "Running godep save - this might take a while"
# This uses $(pwd) rather than ${KUBE_ROOT} because KUBE_ROOT will be
# realpath'ed, and godep barfs ("... is not using a known version control
# system") on our staging dirs.
GOPATH="${GOPATH}:$(pwd)/staging" godep save "${REQUIRED_BINS[@]}"

# create a symlink in vendor directory pointing to the staging client. This
# let other packages use the staging client as if it were vendored.
for repo in $(ls staging/src/k8s.io); do
if [ ! -e "vendor/k8s.io/${repo}" ]; then
ln -s "../../staging/src/k8s.io/${repo}" "vendor/k8s.io/${repo}"
fi
done

# Workaround broken symlink in docker repo because godep copies the link, but
# not the target
rm -rf vendor/github.com/docker/docker/project/

kube::log::status "Updating BUILD files"
hack/update-bazel.sh >/dev/null

kube::log::status "Updating LICENSES file"
hack/update-godep-licenses.sh >/dev/null

# Clean up
rm -rf "${BACKUP}"
5 changes: 4 additions & 1 deletion hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,16 @@ kube::golang::setup_env() {

kube::golang::create_gopath_tree

export GOPATH=${KUBE_GOPATH}
export GOPATH="${KUBE_GOPATH}"

# Append KUBE_EXTRA_GOPATH to the GOPATH if it is defined.
if [[ -n ${KUBE_EXTRA_GOPATH:-} ]]; then
GOPATH="${GOPATH}:${KUBE_EXTRA_GOPATH}"
fi

# Make sure our own Go binaries are in PATH.
export PATH="${KUBE_GOPATH}/bin:${PATH}"

# Change directories so that we are within the GOPATH. Some tools get really
# upset if this is not true. We use a whole fake GOPATH here to collect the
# resultant binaries. Go will not let us use GOBIN with `go install` and
Expand Down
25 changes: 11 additions & 14 deletions hack/lib/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ kube::util::trap_add() {
if [[ -z "${existing_cmd}" ]]; then
new_cmd="${trap_add_cmd}"
else
new_cmd="${existing_cmd};${trap_add_cmd}"
new_cmd="${trap_add_cmd};${existing_cmd}"
fi

# Assign the test
Expand Down Expand Up @@ -512,25 +512,22 @@ kube::util::ensure_clean_working_dir() {
done 1>&2
}

# Ensure that the given godep version is installed and in the path
# Ensure that the given godep version is installed and in the path. Almost
# nobody should use any version but the default.
kube::util::ensure_godep_version() {
GODEP_VERSION=${1:-"v79"}
GODEP_VERSION=${1:-"v79"} # this version is known to work

if [[ "$(godep version 2>/dev/null)" == *"godep ${GODEP_VERSION}"* ]]; then
return
fi

kube::util::ensure-temp-dir
mkdir -p "${KUBE_TEMP}/go/src"

GOPATH="${KUBE_TEMP}/go" go get -d -u github.com/tools/godep
pushd "${KUBE_TEMP}/go/src/github.com/tools/godep" >/dev/null
git checkout -q "${GODEP_VERSION}"
GOPATH="${KUBE_TEMP}/go" go install .
popd >/dev/null
kube::log::status "Installing godep version ${GODEP_VERSION}"
go install ./vendor/github.com/tools/godep/

PATH="${KUBE_TEMP}/go/bin:${PATH}"
hash -r # force bash to clear PATH cache
godep version
if [[ "$(godep version 2>/dev/null)" != *"godep ${GODEP_VERSION}"* ]]; then
kube::log::error "Expected godep ${GODEP_VERSION}, got $(godep version)"
return 1
fi
}

# Ensure that none of the staging repos is checked out in the GOPATH because this
Expand Down
7 changes: 1 addition & 6 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ if ! $ALL ; then
echo "Running in short-circuit mode; run with -a to force all scripts to run."
fi

kube::util::ensure_godep_version v79

if ! kube::util::godep_restored 2>&1 | sed 's/^/ /'; then
echo "Running godep restore"
"${KUBE_ROOT}/hack/godep-restore.sh" ${V}
fi
"${KUBE_ROOT}/hack/godep-restore.sh" ${V}

BASH_TARGETS="
update-generated-protobuf
Expand Down

0 comments on commit d2bbeb6

Please sign in to comment.