-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve repo tooling #805
improve repo tooling #805
Changes from 2 commits
6360dd0
d8d9dc1
e2bfd03
ca3a118
245ca10
a116f7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/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 | ||
} | ||
|
||
# runs $@ in a go container with caching etc. | ||
run_in_go_container() { | ||
# run in the container | ||
BenTheElder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you move this before checking? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for consistency with the other scripts. it doesn't matter but it's easier to spot check these between the scripts (EG if we tweak the |
||
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 | ||
|
@@ -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}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when do you say recent do you want to do this smarter?
https://gist.github.com/n8henrie/1043443463a4a511acf98aaa4f8f0f69#file-get_golang-sh-L11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could use
golang:latest
but that might get a bit surprising ... probably best to periodically manually update it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(also
golang:latest
actually works currently, but it's not reproducible..., this is)