Skip to content

Commit

Permalink
Merge pull request #805 from BenTheElder/shell-nits
Browse files Browse the repository at this point in the history
improve repo tooling
  • Loading branch information
k8s-ci-robot committed Aug 23, 2019
2 parents 88326a5 + a116f7f commit 742844e
Show file tree
Hide file tree
Showing 38 changed files with 435 additions and 475 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ all: build

# builds kind in a container, outputs to $(OUT_DIR)
kind:
hack/build/go_container.sh go build -v -o /out/$(KIND_BINARY_NAME)
hack/go_container.sh go build -v -o /out/$(KIND_BINARY_NAME)

# alias for building kind
build: kind
Expand Down
122 changes: 0 additions & 122 deletions hack/build/go_container.sh

This file was deleted.

4 changes: 1 addition & 3 deletions hack/ci/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
# simple CI script to verify kind's own sources
# TODO(bentheelder): rename / refactor. consider building kindnetd

set -o errexit
set -o nounset
set -o pipefail
set -o errexit -o nounset -o pipefail

# cd to the repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
Expand Down
4 changes: 3 additions & 1 deletion hack/ci/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

set -o errexit -o nounset -o pipefail -o xtrace

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"

# our exit handler (trap)
cleanup() {
# always attempt to dump logs
Expand All @@ -39,7 +41,7 @@ cleanup() {
# install kind to a tempdir GOPATH from this script's kind checkout
install_kind() {
mkdir -p "${TMP_DIR}/bin"
make -C "$(dirname "${BASH_SOURCE[0]}")/../.." install INSTALL_PATH="${TMP_DIR}/bin"
make -C "${REPO_ROOT}" install INSTALL_PATH="${TMP_DIR}/bin"
export PATH="${TMP_DIR}/bin:${PATH}"
}

Expand Down
92 changes: 92 additions & 0 deletions hack/go_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Simple posix sh reproducible go build container script with caching.
#
# Usage:
# hack/go_container.sh go version
# hack/go_container.sh go build -o /out/kind .
set -o nounset -o errexit

# ============================ SCRIPT SETTINGS =================================
# get the repo root for defaulting OUT_DIR and SOURCE_DIR
REPO_ROOT="${REPO_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}"
# 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 current directory
SOURCE_DIR="${SOURCE_DIR:-$(pwd -P)}"
# default to disabling CGO for easier reproducible builds and cross compilation
export CGO_ENABLED="${CGO_ENABLED:-0}"
# the container image, by default a recent official golang image
GOIMAGE="${GOIMAGE:-golang:1.13rc1}"
# docker volume name, used as a go module / build cache
CACHE_VOLUME="${CACHE_VOLUME:-kind-build-cache}"
# ========================== END SCRIPT SETTINGS ===============================

# autodetects host GOOS and GOARCH and exports them if not set
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)
fi

# detect GOOS equivalent if unset
if [ -z "${GOOS:-}" ]; then
case "$(uname -s)" in
Darwin) export GOOS="darwin" ;;
Linux) export GOOS="linux" ;;
*) echo "Unknown host OS! '$(uname -s)'" exit 2 ;;
esac
fi

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

export GOOS GOARCH
}

# run $@ in a golang container with caching etc.
run_in_go_container() {
docker run \
`# docker options: remove container on exit, run as the host user / group` \
--rm --user "$(id -u):$(id -g)" \
`# golang caching: mount and use the cache volume` \
-v "${CACHE_VOLUME}:/go" -e GOCACHE=/go/cache \
`# mount the output & source dir, set working directory to the source dir` \
-v "${OUT_DIR}:/out" -v "${SOURCE_DIR}:/src" -w "/src" \
`# pass through go settings: modules, proxy, cgo, OS / Arch` \
-e GO111MODULE -e GOPROXY -e CGO_ENABLED -e GOOS -e GOARCH \
`# pass through proxy settings` \
-e HTTP_PROXY -e HTTPS_PROXY -e NO_PROXY \
`# run the image with the args passed to this script` \
"${GOIMAGE}" "$@"
}

mkdir -p "${OUT_DIR}"
docker volume create "${CACHE_VOLUME}" >/dev/null
detect_and_set_goos_goarch
run_in_go_container "$@"
3 changes: 1 addition & 2 deletions hack/release/build/cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
# limitations under the License.

# simple script to build binaries for release

set -o errexit -o nounset -o pipefail

# cd to the repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
cd "${REPO_ROOT}"

# controls the number of concurrent builds
Expand Down
7 changes: 2 additions & 5 deletions hack/release/build/ctr/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
# NOTE: this is temporary, we only need to build ctr until our (tiny!)
# --no-unpack patch is available in the standard package

set -o errexit
set -o nounset
set -o pipefail
set -o xtrace
set -o errexit -o nounset -o pipefail

# cd to the repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../.." && pwd -P)"
cd "${REPO_ROOT}"

# options
Expand Down
6 changes: 2 additions & 4 deletions hack/release/build/push-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail
set -o errexit -o nounset -o pipefail

# cd to the repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
cd "${REPO_ROOT}"

# ensure we have up to date kind
Expand Down
6 changes: 2 additions & 4 deletions hack/release/build/push-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail
set -o errexit -o nounset -o pipefail

# cd to the repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
cd "${REPO_ROOT}"

# ensure we have up to date kind
Expand Down
15 changes: 7 additions & 8 deletions hack/release/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
# builds binaries between the commits
# Use like: create.sh <release-version> <next-prerelease-version>
# EG: create.sh v0.3.0 v0.4.0-alpha
set -o nounset
set -o errexit
set -o pipefail
set -o errexit -o nounset -o pipefail

# cd to the repo root
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
cd "${REPO_ROOT}"

# check for arguments
if [ "$#" -ne 2 ]; then
echo "Usage: create.sh release-version next-prerelease-version"
exit 1
fi

REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

# darwin is great
SED="sed"
if which gsed &>/dev/null; then
Expand Down Expand Up @@ -65,8 +65,7 @@ set_version "${1}"
make_commit "${1}"
add_tag "${1}"
echo "Building ..."
make clean
./hack/release/build/cross.sh
make clean && ./hack/release/build/cross.sh

# update to the second version
set_version "${2}"
Expand Down
File renamed without changes.
25 changes: 22 additions & 3 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,31 @@ module sigs.k8s.io/kind/hack/tools
go 1.12

require (
github.com/client9/misspell v0.3.4
github.com/golangci/golangci-lint v1.17.2-0.20190714145355-d2b1eea2c617
github.com/spf13/pflag v1.0.3 // indirect
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529 // indirect
golang.org/x/tools v0.0.0-20190606174628-0139d5756a7d // indirect
honnef.co/go/tools v0.0.0-20190605142022-0a11fc526260
k8s.io/code-generator v0.0.0-20190311093542-50b561225d70
k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a // indirect
k8s.io/klog v0.3.0 // indirect
)

// deal with golangci-lint being broken

replace github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6 => github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6

replace github.com/golangci/go-tools v0.0.0-20180109140146-af6baa5dc196 => github.com/golangci/go-tools v0.0.0-20190318060251-af6baa5dc196

replace github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 => github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98

replace github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 => github.com/golangci/gosec v0.0.0-20190211064107-66fb7fc33547

replace github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 => github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217

replace github.com/go-critic/go-critic v0.0.0-20181204210945-1df300866540 => github.com/go-critic/go-critic v0.0.0-20190526074819-1df300866540

replace mvdan.cc/unparam v0.0.0-20190124213536-fbb59629db34 => mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34

replace github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc => github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc

replace github.com/timakin/bodyclose => github.com/golangci/bodyclose v0.0.0-20190714144026-65da19158fa2

0 comments on commit 742844e

Please sign in to comment.