Skip to content

Commit

Permalink
Merge pull request #700 from BenTheElder/go1127
Browse files Browse the repository at this point in the history
upgrade to go 1.12.7, cleanup build scripts a bit
  • Loading branch information
k8s-ci-robot committed Jul 11, 2019
2 parents 148d2d8 + d923500 commit a132fa8
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 106 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -27,7 +27,7 @@ kind bootstraps each "node" with [kubeadm][kubeadm]. For more details see [the d

You can install kind with `GO111MODULE="on" go get sigs.k8s.io/kind@v0.4.0`.

**NOTE**: please use the latest go to do this, ideally go 1.12.6 or greater.
**NOTE**: please use the latest go to do this, ideally go 1.12.7 or greater.

This will put `kind` in `$(go env GOPATH)/bin`. If you encounter the error
`kind: command not found` after installation then you may need to either add that directory to your `$PATH` as
Expand Down
73 changes: 53 additions & 20 deletions hack/build/go_container.sh
Expand Up @@ -18,49 +18,81 @@
set -o nounset
set -o errexit

# get and go to the repo root
REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"
# get the repo root for defaulting OUT_DIR and SOURCE_DIR
# we assume the repo root is two levels up from this script
REPO_ROOT="${REPO_ROOT:-$(cd "$(dirname "$0")/../.." && pwd)}"

# autodetect host GOOS and GOARCH if not set, even if go is not installed
GOOS="${GOOS:-$("${REPO_ROOT}/hack/build/goos.sh")}"
GOARCH="${GOARCH:-$("${REPO_ROOT}/hack/build/goarch.sh")}"

# use the official module proxy by default
# ============================ SCRIPT SETTINGS =================================
# output directory, will be mounted to /out, defaults to /bin in REPO_ROOT
OUT_DIR="${OUT_DIR:-${REPO_ROOT}/bin}"
# source directory, will be mounted to /src, defaults to REPO_ROOT
SOURCE_DIR="${SOURCE_DIR:-${REPO_ROOT}}"
# GOPROXY is respected by go, use the official module proxy by default
# this helps make our build more reproducible and reliable
GOPROXY="${GOPROXY:-https://proxy.golang.org}"
# the container image, by default a recent official golang image
GOIMAGE="${GOIMAGE:-golang:1.12.7}"
# ========================== END SCRIPT SETTINGS ===============================

# default build image
GO_VERSION="1.12.6"
GO_IMAGE="golang:${GO_VERSION}"
# autodetects and host GOOS and GOARCH and sets them if not set
# works even if go is not installed on the host
detect_and_set_goos_goarch() {
# if we have go, just ask go! NOTE: this respects explicitly set GOARCH / GOOS
if which go >/dev/null 2>&1; then
GOARCH=$(go env GOARCH)
GOOS=$(go env GOOS)
return
fi

# docker volume name, used as a go module / build cache
CACHE_VOLUME="kind-build-cache"
# detect GOOS equivalent if unset
if [ -z "${GOOS:-}" ]; then
case "$(uname -s)" in
Darwin) GOOS="darwin" ;;
Linux) GOOS="linux" ;;
*) echo "Unknown host OS! '$(uname -s)'" exit 2 ;;
esac
fi

# output directory
OUT_DIR="${OUT_DIR:-${REPO_ROOT}/bin}"
# source directory
SOURCE_DIR="${SOURCE_DIR:-${REPO_ROOT}}"
# detect GOARCH equivalent if unset
if [ -z "${GOARCH:-}" ]; then
case "$(uname -m)" in
x86_64) GOARCH="amd64" ;;
arm*)
GOARCH="arm"
if [ "$(getconf LONG_BIT)" = "64" ]; then
GOARCH="arm64"
fi
;;
*) echo "Unknown host architecture! '$(uname -m)'" exit 2 ;;
esac
fi
}

# creates the output directory
make_out_dir() {
mkdir -p "${OUT_DIR}"
}

# docker volume name, used as a go module / build cache
__CACHE_VOLUME__="kind-build-cache"

# creates the cache volume
make_cache_volume() {
docker volume create "${CACHE_VOLUME}" >/dev/null
docker volume create "${__CACHE_VOLUME__}" >/dev/null
}

# runs $@ in a go container with caching etc. and the repo mount to /src
run_in_go_container() {
# get user id and group id so we can run the container
# get host user id and group id so we can run the container as them
# this ensures sane file ownership for build outputs
_UID=$(id -u)
_GID=$(id -g)
# run in the container
docker run \
`# ensure the container is removed on exit` \
--rm \
`# use the cache volume for go` \
-v "${CACHE_VOLUME}:/go" \
-v "${__CACHE_VOLUME__}:/go" \
-e GOCACHE=/go/cache \
`# mount the output & repo dir, set working directory to the repo` \
-v "${OUT_DIR}:/out" \
Expand All @@ -79,11 +111,12 @@ run_in_go_container() {
`# run as if the host user for consistent file permissions` \
--user "${_UID}:${_GID}" \
`# use the golang image for the container` \
"${GO_IMAGE}" \
"${GOIMAGE}" \
`# and finally, pass through args` \
"$@"
}

make_out_dir
make_cache_volume
detect_and_set_goos_goarch
run_in_go_container "$@"
44 changes: 0 additions & 44 deletions hack/build/goarch.sh

This file was deleted.

2 changes: 2 additions & 0 deletions hack/build/goinstalldir.sh
Expand Up @@ -14,6 +14,8 @@
# limitations under the License.

# this utility prints out the golang install dir, even if go is not installed
# IE it prints the directory where `go install ...` would theoretically place
# binaries

# if we have go, just ask go!
if which go >/dev/null 2>&1; then
Expand Down
39 changes: 0 additions & 39 deletions hack/build/goos.sh

This file was deleted.

2 changes: 1 addition & 1 deletion site/content/docs/contributing/getting-started.md
Expand Up @@ -51,7 +51,7 @@ You can check if Go is in your system with the following command:
go version
```

Preferably Go `1.12.6` or greater should be installed.
Preferably Go `1.12.7` or greater should be installed.

Correct automatic formatting of the source with `gofmt` requires at least
`1.11.0`.
Expand Down
2 changes: 1 addition & 1 deletion site/content/docs/user/quick-start.md
Expand Up @@ -17,7 +17,7 @@ This guide covers getting started with the `kind` command.
You can either install kind with `GO111MODULE="on" go get sigs.k8s.io/kind@v0.4.0` or clone this repo
and run `make build` from the repository.

**NOTE**: please use the latest go to do this, ideally go 1.12.6 or greater.
**NOTE**: please use the latest go to do this, ideally go 1.12.7 or greater.

This will put `kind` in `$(go env GOPATH)/bin`. You may need to add that directory to your `$PATH` as
shown [here](https://golang.org/doc/code.html#GOPATH) if you encounter the error
Expand Down

0 comments on commit a132fa8

Please sign in to comment.