From e706926bee3ebc6c1e7c54463ac3f381d6fd70e3 Mon Sep 17 00:00:00 2001 From: jharshman Date: Fri, 4 Jan 2019 19:57:42 -0800 Subject: [PATCH 1/2] support-script-refactor - perform some refactoring * ref https://google.github.io/styleguide/shell.xml --- GNUmakefile | 32 ++--- build-support/functions/20-build.sh | 194 +++++++++++++------------- build-support/scripts/build-docker | 1 + build-support/scripts/build-docker.sh | 79 +++++------ build-support/scripts/build-local | 1 + build-support/scripts/build-local.sh | 122 ++++++++-------- build-support/scripts/dev | 1 + build-support/scripts/dev.sh | 46 +++--- build-support/scripts/functions | 1 + build-support/scripts/functions.sh | 5 +- build-support/scripts/publish | 1 + build-support/scripts/publish.sh | 30 ++-- build-support/scripts/release | 1 + build-support/scripts/release.sh | 49 +++---- build-support/scripts/test-flake | 1 + build-support/scripts/test-flake.sh | 52 +++---- build-support/scripts/verify | 1 + build-support/scripts/verify.sh | 38 ++--- build-support/scripts/version | 1 + build-support/scripts/version.sh | 33 ++--- 20 files changed, 319 insertions(+), 370 deletions(-) create mode 120000 build-support/scripts/build-docker create mode 120000 build-support/scripts/build-local create mode 120000 build-support/scripts/dev create mode 120000 build-support/scripts/functions create mode 120000 build-support/scripts/publish create mode 120000 build-support/scripts/release create mode 120000 build-support/scripts/test-flake create mode 120000 build-support/scripts/verify create mode 120000 build-support/scripts/version diff --git a/GNUmakefile b/GNUmakefile index fbc56b6082e9..45d387c3e9fd 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -109,13 +109,13 @@ endif all: bin bin: tools - @$(SHELL) $(CURDIR)/build-support/scripts/build-local.sh + @$(SHELL) $(CURDIR)/build-support/scripts/build-local # dev creates binaries for testing locally - these are put into ./bin and $GOPATH dev: changelogfmt vendorfmt dev-build dev-build: - @$(SHELL) $(CURDIR)/build-support/scripts/build-local.sh -o $(GOOS) -a $(GOARCH) + @$(SHELL) $(CURDIR)/build-support/scripts/build-local -o $(GOOS) -a $(GOARCH) dev-docker: go-build-image @docker build -t '$(CONSUL_DEV_IMAGE)' --build-arg 'GIT_COMMIT=$(GIT_COMMIT)' --build-arg 'GIT_DIRTY=$(GIT_DIRTY)' --build-arg 'GIT_DESCRIBE=$(GIT_DESCRIBE)' --build-arg 'CONSUL_BUILD_IMAGE=$(GO_BUILD_TAG)' -f $(CURDIR)/build-support/docker/Consul-Dev.dockerfile '$(CURDIR)' @@ -131,20 +131,20 @@ changelogfmt: # linux builds a linux package independent of the source platform linux: - @$(SHELL) $(CURDIR)/build-support/scripts/build-local.sh -o linux -a amd64 + @$(SHELL) $(CURDIR)/build-support/scripts/build-local -o linux -a amd64 # dist builds binaries for all platforms and packages them for distribution dist: - @$(SHELL) $(CURDIR)/build-support/scripts/release.sh -t '$(DIST_TAG)' -b '$(DIST_BUILD)' -S '$(DIST_SIGN)' $(DIST_VERSION_ARG) $(DIST_DATE_ARG) $(DIST_REL_ARG) + @$(SHELL) $(CURDIR)/build-support/scripts/release -t '$(DIST_TAG)' -b '$(DIST_BUILD)' -S '$(DIST_SIGN)' $(DIST_VERSION_ARG) $(DIST_DATE_ARG) $(DIST_REL_ARG) verify: - @$(SHELL) $(CURDIR)/build-support/scripts/verify.sh + @$(SHELL) $(CURDIR)/build-support/scripts/verify publish: - @$(SHELL) $(CURDIR)/build-support/scripts/publish.sh $(PUB_GIT_ARG) $(PUB_WEBSITE_ARG) + @$(SHELL) $(CURDIR)/build-support/scripts/publish $(PUB_GIT_ARG) $(PUB_WEBSITE_ARG) dev-tree: - @$(SHELL) $(CURDIR)/build-support/scripts/dev.sh $(DEV_PUSH_ARG) + @$(SHELL) $(CURDIR)/build-support/scripts/dev $(DEV_PUSH_ARG) cov: gocov test $(GOFILES) | gocov-html > /tmp/coverage.html @@ -195,7 +195,7 @@ test-ci: other-consul dev-build vet test-install-deps fi test-flake: other-consul vet test-install-deps - @$(SHELL) $(CURDIR)/build-support/scripts/test-flake.sh --pkg "$(FLAKE_PKG)" --test "$(FLAKE_TEST)" --cpus "$(FLAKE_CPUS)" --n "$(FLAKE_N)" + @$(SHELL) $(CURDIR)/build-support/scripts/test-flake --pkg "$(FLAKE_PKG)" --test "$(FLAKE_TEST)" --cpus "$(FLAKE_CPUS)" --n "$(FLAKE_N)" other-consul: @echo "--> Checking for other consul instances" @@ -236,13 +236,13 @@ tools: version: @echo -n "Version: " - @$(SHELL) $(CURDIR)/build-support/scripts/version.sh + @$(SHELL) $(CURDIR)/build-support/scripts/version @echo -n "Version + release: " - @$(SHELL) $(CURDIR)/build-support/scripts/version.sh -r + @$(SHELL) $(CURDIR)/build-support/scripts/version -r @echo -n "Version + git: " - @$(SHELL) $(CURDIR)/build-support/scripts/version.sh -g + @$(SHELL) $(CURDIR)/build-support/scripts/version -g @echo -n "Version + release + git: " - @$(SHELL) $(CURDIR)/build-support/scripts/version.sh -r -g + @$(SHELL) $(CURDIR)/build-support/scripts/version -r -g docker-images: go-build-image ui-build-image ui-legacy-build-image @@ -260,16 +260,16 @@ ui-legacy-build-image: @docker build $(NOCACHE) $(QUIET) -t $(UI_LEGACY_BUILD_TAG) - < build-support/docker/Build-UI-Legacy.dockerfile static-assets-docker: go-build-image - @$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh static-assets + @$(SHELL) $(CURDIR)/build-support/scripts/build-docker static-assets consul-docker: go-build-image - @$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh consul + @$(SHELL) $(CURDIR)/build-support/scripts/build-docker consul ui-docker: ui-build-image - @$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh ui + @$(SHELL) $(CURDIR)/build-support/scripts/build-docker ui ui-legacy-docker: ui-legacy-build-image - @$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh ui-legacy + @$(SHELL) $(CURDIR)/build-support/scripts/build-docker ui-legacy .PHONY: all ci bin dev dist cov test test-ci test-internal test-install-deps cover format vet ui static-assets tools vendorfmt diff --git a/build-support/functions/20-build.sh b/build-support/functions/20-build.sh index 9dd02bf36ca5..205393bee9ff 100644 --- a/build-support/functions/20-build.sh +++ b/build-support/functions/20-build.sh @@ -227,35 +227,32 @@ function build_consul_post { # pkg.bin.new is where the just built binaries are located # bin is where to place the local systems versions - if ! test -d "$1" - then + if ! [[ -d "$1" ]]; then err "ERROR: '$1' is not a directory. build_consul_post must be called with the path to the top level source as the first argument'" return 1 fi - local sdir="$1" + local _sdir="$1" - local extra_dir_name="$2" - local extra_dir="" + local _extra_dir_name="$2" + local _extra_dir="" - if test -n "${extra_dir_name}" - then - extra_dir="${extra_dir_name}/" + if [[ -n "${_extra_dir_name}" ]]; then + _extra_dir="${_extra_dir_name}/" fi - pushd "${sdir}" > /dev/null + pushd "${_sdir}" > /dev/null # recreate the pkg dir - rm -r pkg/bin/${extra_dir}* 2> /dev/null - mkdir -p pkg/bin/${extra_dir} 2> /dev/null + rm -r pkg/bin/${_extra_dir}* 2> /dev/null + mkdir -p pkg/bin/${_extra_dir} 2> /dev/null # move all files in pkg.new into pkg - cp -r pkg.bin.new/${extra_dir}* pkg/bin/${extra_dir} + cp -r pkg.bin.new/${_extra_dir}* pkg/bin/${_extra_dir} rm -r pkg.bin.new - DEV_PLATFORM="./pkg/bin/${extra_dir}$(go env GOOS)_$(go env GOARCH)" - for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f 2>/dev/null) - do + DEV_PLATFORM="./pkg/bin/${_extra_dir}$(go env GOOS)_$(go env GOARCH)" + for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f 2>/dev/null); do # recreate the bin dir rm -r bin/* 2> /dev/null mkdir -p bin 2> /dev/null @@ -285,62 +282,67 @@ function build_consul { # If the XC_OS or the XC_ARCH environment vars are present then only those platforms/architectures # will be built. Otherwise all supported platform/architectures are built - if ! test -d "$1" - then + if ! [[ -d "$1" ]]; then err "ERROR: '$1' is not a directory. build_consul must be called with the path to the top level source as the first argument'" return 1 fi - local sdir="$1" - local extra_dir_name="$2" - local extra_dir="" - local image_name=${GO_BUILD_CONTAINER_DEFAULT} - if test -n "$3" - then - image_name="$3" + local _sdir="$1" + local _extra_dir_name="$2" + local _extra_dir="" + local _image_name=${GO_BUILD_CONTAINER_DEFAULT} + + if [[ -n "$3" ]]; then + _image_name="$3" fi - pushd ${sdir} > /dev/null - status "Creating the Go Build Container with image: ${image_name}" - if is_set "${CONSUL_DEV}" - then - if test -z "${XC_OS}" - then + pushd ${_sdir} > /dev/null + status "Creating the Go Build Container with image: ${_image_name}" + if is_set "${CONSUL_DEV}"; then + if [[ -z "${XC_OS}" ]]; then XC_OS=$(go env GOOS) fi - if test -z "${XC_ARCH}" - then + if [[ -z "${XC_ARCH}" ]]; then XC_ARCH=$(go env GOARCH) fi fi XC_OS=${XC_OS:-"solaris darwin freebsd linux windows"} XC_ARCH=${XC_ARCH:-"386 amd64 arm arm64"} - if test -n "${extra_dir_name}" - then - extra_dir="${extra_dir_name}/" + if [[ -n "${_extra_dir_name}" ]]; then + _extra_dir="${_extra_dir_name}/" fi - local container_id=$(docker create -it -e CGO_ENABLED=0 ${image_name} gox -os="${XC_OS}" -arch="${XC_ARCH}" -osarch="!darwin/arm !freebsd/arm !darwin/arm64" -ldflags "${GOLDFLAGS}" -output "pkg/bin/${extra_dir}{{.OS}}_{{.Arch}}/consul" -tags="${GOTAGS}") + local _container_id=$( + docker create \ + -it \ + -e CGO_ENABLED=0 \ + ${_image_name} \ + gox -os="${XC_OS}" \ + -arch="${XC_ARCH}" \ + -osarch="!darwin/arm !freebsd/arm !darwin/arm64" \ + -ldflags "${GOLDFLAGS}" \ + -output "pkg/bin/${_extra_dir}{{.OS}}_{{.Arch}}/consul" \ + -tags="${GOTAGS}" + ) ret=$? - if test $ret -eq 0 - then - status "Copying the source from '${sdir}' to /go/src/github.com/hashicorp/consul" + if [[ $ret -eq 0 ]]; then + status "Copying the source from '${_sdir}' to /go/src/github.com/hashicorp/consul" ( - tar -c $(ls | grep -v "^(ui\|ui-v2\|website\|bin\|pkg\|.git)") | docker cp - ${container_id}:/go/src/github.com/hashicorp/consul && - status "Running build in container" && - docker start -i ${container_id} && - status "Copying back artifacts" && - docker cp ${container_id}:/go/src/github.com/hashicorp/consul/pkg/bin pkg.bin.new + tar -c $(ls | grep -v "^(ui\|ui-v2\|website\|bin\|pkg\|.git)") \ + | docker cp - ${_container_id}:/go/src/github.com/hashicorp/consul \ + && status "Running build in container" \ + && docker start -i ${_container_id} \ + && status "Copying back artifacts" \ + && docker cp ${_container_id}:/go/src/github.com/hashicorp/consul/pkg/bin pkg.bin.new ) ret=$? - docker rm ${container_id} > /dev/null + docker rm ${_container_id} > /dev/null - if test $ret -eq 0 - then - build_consul_post "${sdir}" "${extra_dir_name}" + if [[ $ret -eq 0 ]]; then + build_consul_post "${_sdir}" "${_extra_dir_name}" ret=$? else rm -r pkg.bin.new 2> /dev/null @@ -369,89 +371,81 @@ function build_consul_local { # The NOGOX environment variable will be used if present. This will prevent using gox and instead # build with go install - if ! test -d "$1" - then + if ! [[ -d "$1" ]]; then err "ERROR: '$1' is not a directory. build_consul must be called with the path to the top level source as the first argument'" return 1 fi - local sdir="$1" - local build_os="$2" - local build_arch="$3" - local extra_dir_name="$4" - local extra_dir="" + local _sdir="$1" + local _build_os="$2" + local _build_arch="$3" + local _extra_dir_name="$4" + local _extra_dir="" - if test -n "${extra_dir_name}" - then - extra_dir="${extra_dir_name}/" + if [[ -n "${_extra_dir_name}" ]]; then + _extra_dir="${_extra_dir_name}/" fi - pushd ${sdir} > /dev/null - if is_set "${CONSUL_DEV}" - then - if test -z "${XC_OS}" - then + pushd ${_sdir} > /dev/null + if [[ $(is_set "${CONSUL_DEV}") == 0 ]]; then + if [[ -z "${XC_OS}" ]]; then XC_OS=$(go env GOOS) fi - if test -z "${XC_ARCH}" - then + if [[ -z "${XC_ARCH}" ]]; then XC_ARCH=$(go env GOARCH) fi fi XC_OS=${XC_OS:-"solaris darwin freebsd linux windows"} XC_ARCH=${XC_ARCH:-"386 amd64 arm arm64"} - if test -z "${build_os}" - then - build_os="${XC_OS}" + if [[ -z "${_build_os}" ]]; then + _build_os="${XC_OS}" fi - if test -z "${build_arch}" - then - build_arch="${XC_ARCH}" + if [[ -z "${_build_arch}" ]]; then + _build_arch="${XC_ARCH}" fi - local use_gox=1 - is_set "${NOGOX}" && use_gox=0 - which gox > /dev/null || use_gox=0 + local _use_gox=1 + is_set "${NOGOX}" && _use_gox=0 + which gox > /dev/null || _use_gox=0 - status_stage "==> Building Consul - OSes: ${build_os}, Architectures: ${build_arch}" + status_stage "==> Building Consul - OSes: ${_build_os}, Architectures: ${_build_arch}" mkdir pkg.bin.new 2> /dev/null - if is_set "${use_gox}" - then + if [[ $(is_set "${_use_gox}") == 0 ]]; then status "Using gox for concurrent compilation" CGO_ENABLED=0 gox \ - -os="${build_os}" \ - -arch="${build_arch}" \ + -os="${_build_os}" \ + -arch="${_build_arch}" \ -osarch="!darwin/arm !darwin/arm64 !freebsd/arm" \ -ldflags="${GOLDFLAGS}" \ - -output "pkg.bin.new/${extra_dir}{{.OS}}_{{.Arch}}/consul" \ + -output "pkg.bin.new/${_extra_dir}{{.OS}}_{{.Arch}}/consul" \ -tags="${GOTAGS}" \ . - if test $? -ne 0 - then + if [[ $? != 0 ]]; then err "ERROR: Failed to build Consul" rm -r pkg.bin.new return 1 fi else status "Building sequentially with go install" - for os in ${build_os} + for os in ${_build_os} do - for arch in ${build_arch} + for arch in ${_build_arch} do - outdir="pkg.bin.new/${extra_dir}${os}_${arch}" + outdir="pkg.bin.new/${_extra_dir}${os}_${arch}" osarch="${os}/${arch}" - if test "${osarch}" == "darwin/arm" -o "${osarch}" == "darwin/arm64" -o "${osarch}" == "freebsd/arm64" -o "${osarch}" == "windows/arm" -o "${osarch}" == "windows/arm64" -o "${osarch}" == "freebsd/arm" - then - continue + + if [[ "${osarch}" == "darwin/arm" ]] || [[ ${osarch}} == "darwin/arm64" ]] \ + || [[ ${osarch} == "freebsd/arm" ]] || [[ ${osarch}} == "freebsd/arm64" ]] \ + || [[ ${osarch} == "windows/arm" ]] || [[ ${osarch}} == "windows/arm64" ]]; then + continue fi - if test "${os}" == "solaris" -a "${arch}" != "amd64" - then + if [[ "${os}" == "solaris" ]] && [[ "${arch}" != "amd64" ]]; then continue fi @@ -460,17 +454,20 @@ function build_consul_local { mkdir -p "${outdir}" GOBIN_EXTRA="" - if test "${os}" != "$(go env GOHOSTOS)" -o "${arch}" != "$(go env GOHOSTARCH)" - then + if [[ "${os}" != "$(go env GOHOSTOS)" ]] || [[ "${arch}" != "$(go env GOHOSTARCH)" ]]; then GOBIN_EXTRA="${os}_${arch}/" fi binname="consul" - if [ $os == "windows" ];then + if [[ "${os}" == "windows" ]]; then binname="consul.exe" fi - CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go install -ldflags "${GOLDFLAGS}" -tags "${GOTAGS}" && cp "${MAIN_GOPATH}/bin/${GOBIN_EXTRA}${binname}" "${outdir}/${binname}" - if test $? -ne 0 - then + + CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go install \ + -ldflags "${GOLDFLAGS}" \ + -tags "${GOTAGS}" \ + && cp "${MAIN_GOPATH}/bin/${GOBIN_EXTRA}${binname}" "${outdir}/${binname}" + + if [[ $? -ne 0 ]]; then err "ERROR: Failed to build Consul for ${osarch}" rm -r pkg.bin.new return 1 @@ -479,9 +476,8 @@ function build_consul_local { done fi - build_consul_post "${sdir}" "${extra_dir_name}" - if test $? -ne 0 - then + build_consul_post "${_sdir}" "${_extra_dir_name}" + if [[ $? != 0 ]]; then err "ERROR: Failed postprocessing Consul binaries" return 1 fi diff --git a/build-support/scripts/build-docker b/build-support/scripts/build-docker new file mode 120000 index 000000000000..ad623393f88c --- /dev/null +++ b/build-support/scripts/build-docker @@ -0,0 +1 @@ +build-docker.sh \ No newline at end of file diff --git a/build-support/scripts/build-docker.sh b/build-support/scripts/build-docker.sh index 7fef578265ef..ac0270a2ce5f 100755 --- a/build-support/scripts/build-docker.sh +++ b/build-support/scripts/build-docker.sh @@ -12,7 +12,7 @@ popd > /dev/null source "${SCRIPT_DIR}/functions.sh" -function usage { +usage() { cat <<-EOF Usage: ${SCRIPT_NAME} (consul|ui|ui-legacy|static-assets) [] @@ -32,57 +32,53 @@ Options: EOF } -function err_usage { +err_usage() { err "$1" err "" err "$(usage)" } -function main { - declare image= - declare sdir="${SOURCE_DIR}" - declare -i refresh=0 - declare command="" +main() { + local _image= + local _sdir="${SOURCE_DIR}" + local _refresh=0 + local _command="" - while test $# -gt 0 - do + while (( $# )); do case "$1" in -h | --help ) usage return 0 ;; -i | --image ) - if test -z "$2" - then + if [[ -z "$2" ]]; then err_usage "ERROR: option -i/--image requires an argument" return 1 fi - image="$2" + _image="$2" shift 2 ;; -s | --source ) - if test -z "$2" - then + if [[ -z "$2" ]]; then err_usage "ERROR: option -s/--source requires an argument" return 1 fi - if ! test -d "$2" - then + if ! [[ -d "$2" ]]; then err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" return 1 fi - sdir="$2" + _sdir="$2" shift 2 ;; -r | --refresh ) - refresh=1 + _refresh=1 shift ;; consul | ui | ui-legacy | static-assets ) - command="$1" + _command="$1" shift ;; * ) @@ -92,56 +88,51 @@ function main { esac done - if test -z "${command}" - then + if [[ -z "${_command}" ]]; then err_usage "ERROR: No command specified" return 1 fi - case "${command}" in + case "${_command}" in consul ) - if is_set "${refresh}" - then + if [[ $(is_set "${_refresh}") == 0 ]]; then status_stage "==> Refreshing Consul build container image" - export GO_BUILD_TAG="${image:-${GO_BUILD_CONTAINER_DEFAULT}}" - refresh_docker_images "${sdir}" go-build-image || return 1 + export GO_BUILD_TAG="${_image:-${GO_BUILD_CONTAINER_DEFAULT}}" + refresh_docker_images "${_sdir}" go-build-image || return 1 fi status_stage "==> Building Consul" - build_consul "${sdir}" "" "${image}" || return 1 + build_consul "${_sdir}" "" "${_image}" || return 1 ;; static-assets ) - if is_set "${refresh}" - then + if [[ $(is_set "${_refresh}") == 0 ]]; then status_stage "==> Refreshing Consul build container image" - export GO_BUILD_TAG="${image:-${GO_BUILD_CONTAINER_DEFAULT}}" - refresh_docker_images "${sdir}" go-build-image || return 1 + export GO_BUILD_TAG="${_image:-${GO_BUILD_CONTAINER_DEFAULT}}" + refresh_docker_images "${_sdir}" go-build-image || return 1 fi status_stage "==> Building Static Assets" - build_assetfs "${sdir}" "${image}" || return 1 + build_assetfs "${_sdir}" "${_image}" || return 1 ;; ui ) - if is_set "${refresh}" - then + if [[ $(is_set "${_refresh}") == 0 ]]; then status_stage "==> Refreshing UI build container image" - export UI_BUILD_TAG="${image:-${UI_BUILD_CONTAINER_DEFAULT}}" - refresh_docker_images "${sdir}" ui-build-image || return 1 + export UI_BUILD_TAG="${_image:-${UI_BUILD_CONTAINER_DEFAULT}}" + refresh_docker_images "${_sdir}" ui-build-image || return 1 fi status_stage "==> Building UI" - build_ui "${sdir}" "${image}" || return 1 - status "==> UI Built with Version: $(ui_version ${sdir}/pkg/web_ui/v2/index.html), Logo: $(ui_logo_type ${sdir}/pkg/web_ui/v2/index.html)" + build_ui "${_sdir}" "${_image}" || return 1 + status "==> UI Built with Version: $(ui_version ${_sdir}/pkg/web_ui/v2/index.html), Logo: $(ui_logo_type ${_sdir}/pkg/web_ui/v2/index.html)" ;; ui-legacy ) - if is_set "${refresh}" - then + if [[ $(is_set "${_refresh}") == 0 ]]; then status_stage "==> Refreshing Legacy UI build container image" - export UI_LEGACY_BUILD_TAG="${image:-${UI_LEGACY_BUILD_CONTAINER_DEFAULT}}" - refresh_docker_images "${sdir}" ui-legacy-build-image || return 1 + export UI_LEGACY_BUILD_TAG="${_image:-${UI_LEGACY_BUILD_CONTAINER_DEFAULT}}" + refresh_docker_images "${_sdir}" ui-legacy-build-image || return 1 fi status_stage "==> Building UI" - build_ui_legacy "${sdir}" "${image}" || return 1 + build_ui_legacy "${_sdir}" "${_image}" || return 1 ;; * ) - err_usage "ERROR: Unknown command: '${command}'" + err_usage "ERROR: Unknown command: '${_command}'" return 1 ;; esac diff --git a/build-support/scripts/build-local b/build-support/scripts/build-local new file mode 120000 index 000000000000..be483e387f0c --- /dev/null +++ b/build-support/scripts/build-local @@ -0,0 +1 @@ +build-local.sh \ No newline at end of file diff --git a/build-support/scripts/build-local.sh b/build-support/scripts/build-local.sh index 45f33282d34e..03a38d3d0ccf 100755 --- a/build-support/scripts/build-local.sh +++ b/build-support/scripts/build-local.sh @@ -12,7 +12,7 @@ popd > /dev/null source "${SCRIPT_DIR}/functions.sh" -function usage { +usage() { cat <<-EOF Usage: ${SCRIPT_NAME} [] @@ -36,72 +36,66 @@ Options: EOF } -function err_usage { - err "$1" - err "" - err "$(usage)" +err_usage() { + err "$1" + err "" + err "$(usage)" } -function main { - declare sdir="${SOURCE_DIR}" - declare build_os="" - declare build_arch="" +main() { + local _sdir="${SOURCE_DIR}" + local _build_os="" + local _build_arch="" - - while test $# -gt 0 - do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -s | --source ) - if test -z "$2" - then - err_usage "ERROR: option -s/--source requires an argument" - return 1 - fi - - if ! test -d "$2" - then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - - sdir="$2" - shift 2 - ;; - -o | --os ) - if test -z "$2" - then - err_usage "ERROR: option -o/--os requires an argument" - return 1 - fi - - build_os="$2" - shift 2 - ;; - -a | --arch ) - if test -z "$2" - then - err_usage "ERROR: option -a/--arch requires an argument" - return 1 - fi - - build_arch="$2" - shift 2 - ;; - * ) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - build_consul_local "${sdir}" "${build_os}" "${build_arch}" || return 1 - - return 0 + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + -s | --source ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -s/--source requires an argument" + return 1 + fi + + if ! [[ -d "$2" ]]; then + err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" + return 1 + fi + + _sdir="$2" + shift 2 + ;; + -o | --os ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -o/--os requires an argument" + return 1 + fi + + _build_os="$2" + shift 2 + ;; + -a | --arch ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -a/--arch requires an argument" + return 1 + fi + + _build_arch="$2" + shift 2 + ;; + * ) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + build_consul_local "${_sdir}" "${_build_os}" "${_build_arch}" || return 1 + + return 0 } main "$@" -exit $? \ No newline at end of file +exit $? diff --git a/build-support/scripts/dev b/build-support/scripts/dev new file mode 120000 index 000000000000..d9af37ed1261 --- /dev/null +++ b/build-support/scripts/dev @@ -0,0 +1 @@ +dev.sh \ No newline at end of file diff --git a/build-support/scripts/dev.sh b/build-support/scripts/dev.sh index 12a2e884927d..28fee429d2ea 100755 --- a/build-support/scripts/dev.sh +++ b/build-support/scripts/dev.sh @@ -12,7 +12,7 @@ popd > /dev/null source "${SCRIPT_DIR}/functions.sh" -function usage { +usage() { cat <<-EOF Usage: ${SCRIPT_NAME} [] @@ -32,49 +32,43 @@ Options: EOF } -function err_usage { +err_usage() { err "$1" err "" err "$(usage)" } -function main { - declare sdir="${SOURCE_DIR}" - declare build_os="" - declare build_arch="" - declare -i do_git=1 - declare -i do_push=1 +main() { + local _sdir="${SOURCE_DIR}" + local _do_git=1 + local _do_push=1 - - while test $# -gt 0 - do + while (( $# )); do case "$1" in -h | --help ) usage return 0 ;; -s | --source ) - if test -z "$2" - then + if [[ -z "$2" ]]; then err_usage "ERROR: option -s/--source requires an argument" return 1 fi - if ! test -d "$2" - then + if ! [[ -d "$2" ]]; then err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" return 1 fi - sdir="$2" + _sdir="$2" shift 2 ;; --no-git ) - do_git=0 + _do_git=0 shift ;; --no-push ) - do_push=0 + _do_push=0 shift ;; * ) @@ -84,20 +78,18 @@ function main { esac done - set_dev_mode "${sdir}" || return 1 + set_dev_mode "${_sdir}" || return 1 - if is_set "${do_git}" - then + if [[ $(is_set "${_do_git}") == 0 ]]; then status_stage "==> Commiting Dev Mode Changes" - commit_dev_mode "${sdir}" || return 1 + commit_dev_mode "${_sdir}" || return 1 - if is_set "${do_push}" - then + if [[ $(is_set "${_do_push}") == 0 ]]; then status_stage "==> Confirming Git Changes" - confirm_git_push_changes "${sdir}" || return 1 + confirm_git_push_changes "${_sdir}" || return 1 status_stage "==> Pushing to Git" - git_push_ref "${sdir}" || return 1 + git_push_ref "${_sdir}" || return 1 fi fi @@ -105,4 +97,4 @@ function main { } main "$@" -exit $? \ No newline at end of file +exit $? diff --git a/build-support/scripts/functions b/build-support/scripts/functions new file mode 120000 index 000000000000..2cc997b9ca13 --- /dev/null +++ b/build-support/scripts/functions @@ -0,0 +1 @@ +functions.sh \ No newline at end of file diff --git a/build-support/scripts/functions.sh b/build-support/scripts/functions.sh index 2ddae96f2284..d5a96f6aeb5e 100755 --- a/build-support/scripts/functions.sh +++ b/build-support/scripts/functions.sh @@ -11,7 +11,6 @@ popd > /dev/null func_sources=$(find ${FUNC_DIR} -mindepth 1 -maxdepth 1 -name "*.sh" -type f | sort -n) -for src in $func_sources -do +for src in $func_sources; do source $src -done \ No newline at end of file +done diff --git a/build-support/scripts/publish b/build-support/scripts/publish new file mode 120000 index 000000000000..ee9014a91811 --- /dev/null +++ b/build-support/scripts/publish @@ -0,0 +1 @@ +publish.sh \ No newline at end of file diff --git a/build-support/scripts/publish.sh b/build-support/scripts/publish.sh index 3d6faf01f252..ef5ee2e2759e 100755 --- a/build-support/scripts/publish.sh +++ b/build-support/scripts/publish.sh @@ -12,7 +12,7 @@ popd > /dev/null source "${SCRIPT_DIR}/functions.sh" -function usage { +usage() { cat <<-EOF Usage: ${SCRIPT_NAME} [] @@ -35,46 +35,43 @@ Options: EOF } -function err_usage { +err_usage() { err "$1" err "" err "$(usage)" } -function main { - declare sdir="${SOURCE_DIR}" - declare -i website=0 - declare -i git_push=0 +main() { + local _sdir="${SOURCE_DIR}" + local _website=0 + local _git_push=0 - while test $# -gt 0 - do + while (( $# )); do case "$1" in -h | --help ) usage return 0 ;; -s | --source ) - if test -z "$2" - then + if [[ -z "$2" ]]; then err_usage "ERROR: option -s/--source requires an argument" return 1 fi - if ! test -d "$2" - then + if ! [[ -d "$2" ]]; then err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" return 1 fi - sdir="$2" + _sdir="$2" shift 2 ;; -w | --website ) - website=1 + _website=1 shift ;; -g | --git ) - git_push=1 + _git_push=1 shift ;; *) @@ -84,11 +81,10 @@ function main { esac done - publish_release "${sdir}" "${git_push}" "${website}" || return 1 + publish_release "${_sdir}" "${_git_push}" "${_website}" || return 1 return 0 } main "$@" exit $? - \ No newline at end of file diff --git a/build-support/scripts/release b/build-support/scripts/release new file mode 120000 index 000000000000..012c00f9fbbe --- /dev/null +++ b/build-support/scripts/release @@ -0,0 +1 @@ +release.sh \ No newline at end of file diff --git a/build-support/scripts/release.sh b/build-support/scripts/release.sh index 879fe4320e48..af5add1965f1 100755 --- a/build-support/scripts/release.sh +++ b/build-support/scripts/release.sh @@ -12,7 +12,7 @@ popd > /dev/null source "${SCRIPT_DIR}/functions.sh" -function usage { +usage() { cat <<-EOF Usage: ${SCRIPT_NAME} [] @@ -60,13 +60,13 @@ Options: EOF } -function err_usage { +err_usage() { err "$1" err "" err "$(usage)" } -function ensure_arg { +ensure_arg() { if test -z "$2" then err_usage "ERROR: option $1 requires an argument" @@ -76,18 +76,17 @@ function ensure_arg { return 0 } -function main { - declare sdir="${SOURCE_DIR}" - declare -i do_tag=1 - declare -i do_build=1 - declare -i do_sign=1 - declare gpg_key="${HASHICORP_GPG_KEY}" - declare version="" - declare release_ver="" - declare release_date=$(date +"%B %d, %Y") +main() { + local _sdir="${SOURCE_DIR}" + local _do_tag=1 + local _do_build=1 + local _do_sign=1 + local _gpg_key="${HASHICORP_GPG_KEY}" + local _version="" + local _release_ver="" + local _release_date=$(date +"%B %d, %Y") - while test $# -gt 0 - do + while (( $# )); do case "$1" in -h | --help ) usage @@ -96,48 +95,47 @@ function main { -s | --source ) ensure_arg "-s/--source" "$2" || return 1 - if ! test -d "$2" - then + if ! [[ -d "$2" ]]; then err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" return 1 fi - sdir="$2" + _sdir="$2" shift 2 ;; -t | --tag ) ensure_arg "-t/--tag" "$2" || return 1 - do_tag="$2" + _do_tag="$2" shift 2 ;; -b | --build ) ensure_arg "-b/--build" "$2" || return 1 - do_build="$2" + _do_build="$2" shift 2 ;; -S | --sign ) ensure_arg "-s/--sign" "$2" || return 1 - do_sign="$2" + _do_sign="$2" shift 2 ;; -g | --gpg-key ) ensure_arg "-g/--gpg-key" "$2" || return 1 - gpg_key="$2" + _gpg_key="$2" shift 2 ;; -v | --version ) ensure_arg "-v/--version" "$2" || return 1 - version="$2" + _version="$2" shift 2 ;; -d | --date) ensure_arg "-d/--date" "$2" || return 1 - release_date="$2" + _release_date="$2" shift 2 ;; -r | --release) ensure_arg "-r/--release" "$2" || return 1 - release_ver="$2" + _release_ver="$2" shift 2 ;; *) @@ -147,10 +145,9 @@ function main { esac done - build_release "${sdir}" "${do_tag}" "${do_build}" "${do_sign}" "${version}" "${release_date}" "${release_ver}" "${gpg_key}" + build_release "${_sdir}" "${_do_tag}" "${_do_build}" "${_do_sign}" "${_version}" "${_release_date}" "${_release_ver}" "${_gpg_key}" return $? } main "$@" exit $? - \ No newline at end of file diff --git a/build-support/scripts/test-flake b/build-support/scripts/test-flake new file mode 120000 index 000000000000..4879773be8c8 --- /dev/null +++ b/build-support/scripts/test-flake @@ -0,0 +1 @@ +test-flake.sh \ No newline at end of file diff --git a/build-support/scripts/test-flake.sh b/build-support/scripts/test-flake.sh index 38e5879eddf9..cd7b8b746b62 100755 --- a/build-support/scripts/test-flake.sh +++ b/build-support/scripts/test-flake.sh @@ -15,7 +15,7 @@ GOOS="linux" GOARCH="amd64" TEST_BINARY="flake.test" -function usage { +usage() { cat <<-EOF Usage: test-flake [] @@ -48,7 +48,7 @@ Examples: EOF } -function build_repro_env { +build_repro_env() { # Arguments: # $1 - pkg, Target package # $2 - test, Target tests @@ -94,65 +94,53 @@ function build_repro_env { $IMAGE } -function err_usage { +err_usage() { err "$1" err "" err "$(usage)" } -function main { - declare pkg="" - declare test="" - declare cpus="" - declare n="" +main() { + local _pkg="" + local _test="" + local _cpus="" + local _n="" - while test $# -gt 0 - do + while (( $# )); do case "$1" in -h | --help ) usage return 0 ;; - --pkg ) - if test -z "$2" - then + if [[ -z "$2" ]]; then err_usage "ERROR: option pkg requires an argument" return 1 fi - - pkg="$2" + _pkg="$2" shift 2 ;; - --test ) - test="$2" + _test="$2" shift 2 ;; - --cpus ) - if test -n "$2" - then - cpus="$2" + if [[ -n "$2" ]]; then + _cpus="$2" else - cpus="0.15" + _cpus="0.15" fi - shift 2 ;; - --n ) - if test -n "$2" - then - n="$2" + if [[ -n "$2" ]]; then + _n="$2" else - n="30" + _n="30" fi - shift 2 ;; - * ) err_usage "ERROR: Unknown argument: '$1'" return 1 @@ -160,10 +148,10 @@ function main { esac done - build_repro_env "${pkg}" "${test}" "${cpus}" "${n}" || return 1 + build_repro_env "${_pkg}" "${_test}" "${_cpus}" "${_n}" || return 1 return 0 } main "$@" -exit $? \ No newline at end of file +exit $? diff --git a/build-support/scripts/verify b/build-support/scripts/verify new file mode 120000 index 000000000000..97252ee9c85c --- /dev/null +++ b/build-support/scripts/verify @@ -0,0 +1 @@ +verify.sh \ No newline at end of file diff --git a/build-support/scripts/verify.sh b/build-support/scripts/verify.sh index c1678bd1a301..e7836de16fb9 100755 --- a/build-support/scripts/verify.sh +++ b/build-support/scripts/verify.sh @@ -12,7 +12,7 @@ popd > /dev/null source "${SCRIPT_DIR}/functions.sh" -function usage { +usage() { cat <<-EOF Usage: ${SCRIPT_NAME} [] @@ -30,47 +30,40 @@ Options: EOF } -function err_usage { +err_usage() { err "$1" err "" err "$(usage)" } -function main { - declare sdir="${SOURCE_DIR}" - declare vers="" +main() { + local _sdir="${SOURCE_DIR}" + local _vers="" - while test $# -gt 0 - do + while (( $# )); do case "$1" in -h | --help ) usage return 0 ;; -s | --source ) - if test -z "$2" - then + if [[ -z "$2" ]]; then err_usage "ERROR: option -s/--source requires an argument" return 1 fi - - if ! test -d "$2" - then + if ! [[ -d "$2" ]]; then err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" return 1 fi - - sdir="$2" + _sdir="$2" shift 2 ;; -v | --version ) - if test -z "$2" - then + if [[ -z "$2" ]]; then err_usage "ERROR: option -v/--version requires an argument" return 1 fi - - vers="$2" + _vers="$2" shift 2 ;; *) @@ -80,17 +73,16 @@ function main { esac done - if test -z "${vers}" - then - vers=$(parse_version "${sdir}" true false) + if [[ -z "${_vers}" ]]; then + _vers=$(parse_version "${_sdir}" true false) fi status_stage "=> Starting release verification for version: ${version}" - verify_release_build "${sdir}" "${vers}" || return 1 + verify_release_build "${_sdir}" "${_vers}" || return 1 return 0 } main "$@" exit $? - \ No newline at end of file + diff --git a/build-support/scripts/version b/build-support/scripts/version new file mode 120000 index 000000000000..b7ae2b7db3e0 --- /dev/null +++ b/build-support/scripts/version @@ -0,0 +1 @@ +version.sh \ No newline at end of file diff --git a/build-support/scripts/version.sh b/build-support/scripts/version.sh index d7c166f0f0e4..74b0aa2c221a 100755 --- a/build-support/scripts/version.sh +++ b/build-support/scripts/version.sh @@ -12,7 +12,7 @@ popd > /dev/null source "${SCRIPT_DIR}/functions.sh" -function usage { +usage() { cat <<-EOF Usage: ${SCRIPT_NAME} [] @@ -33,46 +33,41 @@ Options: EOF } -function err_usage { +err_usage() { err "$1" err "" err "$(usage)" } -function main { - declare sdir="${SOURCE_DIR}" - declare -i release=0 - declare -i git_info=0 +main() { + local _sdir="${SOURCE_DIR}" + local _release=0 + local _git_info=0 - while test $# -gt 0 - do + while (( $# )); do case "$1" in -h | --help ) usage return 0 ;; -s | --source ) - if test -z "$2" - then + if [[ -z "$2" ]]; then err_usage "ERROR: option -s/--source requires an argument" return 1 fi - - if ! test -d "$2" - then + if [[ -d "$2" ]]; then err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" return 1 fi - - sdir="$2" + _sdir="$2" shift 2 ;; -r | --release ) - release=1 + _release=1 shift ;; -g | --git ) - git_info=1 + _git_info=1 shift ;; *) @@ -82,11 +77,11 @@ function main { esac done - parse_version "${sdir}" "${release}" "${git_info}" || return 1 + parse_version "${_sdir}" "${_release}" "${_git_info}" || return 1 return 0 } main "$@" exit $? - \ No newline at end of file + From a75e22e3e9cd0d95cf92b4d14edb349f8590d8ea Mon Sep 17 00:00:00 2001 From: jharshman Date: Mon, 7 Jan 2019 22:01:05 -0800 Subject: [PATCH 2/2] support-script-refactor - remove links and rename --- build-support/scripts/build-docker | 145 ++++++++++++++++++++++- build-support/scripts/build-docker.sh | 144 ----------------------- build-support/scripts/build-local | 102 ++++++++++++++++- build-support/scripts/build-local.sh | 101 ---------------- build-support/scripts/dev | 101 +++++++++++++++- build-support/scripts/dev.sh | 100 ---------------- build-support/scripts/functions | 1 - build-support/scripts/functions.sh | 0 build-support/scripts/publish | 91 ++++++++++++++- build-support/scripts/publish.sh | 90 --------------- build-support/scripts/release | 154 ++++++++++++++++++++++++- build-support/scripts/release.sh | 153 ------------------------- build-support/scripts/test-flake | 158 +++++++++++++++++++++++++- build-support/scripts/test-flake.sh | 157 ------------------------- build-support/scripts/verify | 89 ++++++++++++++- build-support/scripts/verify.sh | 88 -------------- build-support/scripts/version | 88 +++++++++++++- build-support/scripts/version.sh | 87 -------------- 18 files changed, 920 insertions(+), 929 deletions(-) mode change 120000 => 100755 build-support/scripts/build-docker delete mode 100755 build-support/scripts/build-docker.sh mode change 120000 => 100755 build-support/scripts/build-local delete mode 100755 build-support/scripts/build-local.sh mode change 120000 => 100755 build-support/scripts/dev delete mode 100755 build-support/scripts/dev.sh delete mode 120000 build-support/scripts/functions mode change 100755 => 100644 build-support/scripts/functions.sh mode change 120000 => 100755 build-support/scripts/publish delete mode 100755 build-support/scripts/publish.sh mode change 120000 => 100755 build-support/scripts/release delete mode 100755 build-support/scripts/release.sh mode change 120000 => 100755 build-support/scripts/test-flake delete mode 100755 build-support/scripts/test-flake.sh mode change 120000 => 100755 build-support/scripts/verify delete mode 100755 build-support/scripts/verify.sh mode change 120000 => 100755 build-support/scripts/version delete mode 100755 build-support/scripts/version.sh diff --git a/build-support/scripts/build-docker b/build-support/scripts/build-docker deleted file mode 120000 index ad623393f88c..000000000000 --- a/build-support/scripts/build-docker +++ /dev/null @@ -1 +0,0 @@ -build-docker.sh \ No newline at end of file diff --git a/build-support/scripts/build-docker b/build-support/scripts/build-docker new file mode 100755 index 000000000000..ac0270a2ce5f --- /dev/null +++ b/build-support/scripts/build-docker @@ -0,0 +1,144 @@ +#!/bin/bash +SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" +pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null +SCRIPT_DIR=$(pwd) +pushd ../.. > /dev/null +SOURCE_DIR=$(pwd) +popd > /dev/null +pushd ../functions > /dev/null +FN_DIR=$(pwd) +popd > /dev/null +popd > /dev/null + +source "${SCRIPT_DIR}/functions.sh" + +usage() { +cat <<-EOF +Usage: ${SCRIPT_NAME} (consul|ui|ui-legacy|static-assets) [] + +Description: + This script will build the various Consul components within docker containers + and copy all the relevant artifacts out of the containers back to the source. + +Options: + -i | --image IMAGE Alternative Docker image to run the build within. + + -s | --source DIR Path to source to build. + Defaults to "${SOURCE_DIR}" + + -r | --refresh Enables refreshing the docker image prior to building. + + -h | --help Print this help text. +EOF +} + +err_usage() { + err "$1" + err "" + err "$(usage)" +} + +main() { + local _image= + local _sdir="${SOURCE_DIR}" + local _refresh=0 + local _command="" + + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + -i | --image ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -i/--image requires an argument" + return 1 + fi + + _image="$2" + shift 2 + ;; + -s | --source ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -s/--source requires an argument" + return 1 + fi + + if ! [[ -d "$2" ]]; then + err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" + return 1 + fi + + _sdir="$2" + shift 2 + ;; + -r | --refresh ) + _refresh=1 + shift + ;; + consul | ui | ui-legacy | static-assets ) + _command="$1" + shift + ;; + * ) + err_usage "ERROR: Unknown argument '$1'" + return 1 + ;; + esac + done + + if [[ -z "${_command}" ]]; then + err_usage "ERROR: No command specified" + return 1 + fi + + case "${_command}" in + consul ) + if [[ $(is_set "${_refresh}") == 0 ]]; then + status_stage "==> Refreshing Consul build container image" + export GO_BUILD_TAG="${_image:-${GO_BUILD_CONTAINER_DEFAULT}}" + refresh_docker_images "${_sdir}" go-build-image || return 1 + fi + status_stage "==> Building Consul" + build_consul "${_sdir}" "" "${_image}" || return 1 + ;; + static-assets ) + if [[ $(is_set "${_refresh}") == 0 ]]; then + status_stage "==> Refreshing Consul build container image" + export GO_BUILD_TAG="${_image:-${GO_BUILD_CONTAINER_DEFAULT}}" + refresh_docker_images "${_sdir}" go-build-image || return 1 + fi + status_stage "==> Building Static Assets" + build_assetfs "${_sdir}" "${_image}" || return 1 + ;; + ui ) + if [[ $(is_set "${_refresh}") == 0 ]]; then + status_stage "==> Refreshing UI build container image" + export UI_BUILD_TAG="${_image:-${UI_BUILD_CONTAINER_DEFAULT}}" + refresh_docker_images "${_sdir}" ui-build-image || return 1 + fi + status_stage "==> Building UI" + build_ui "${_sdir}" "${_image}" || return 1 + status "==> UI Built with Version: $(ui_version ${_sdir}/pkg/web_ui/v2/index.html), Logo: $(ui_logo_type ${_sdir}/pkg/web_ui/v2/index.html)" + ;; + ui-legacy ) + if [[ $(is_set "${_refresh}") == 0 ]]; then + status_stage "==> Refreshing Legacy UI build container image" + export UI_LEGACY_BUILD_TAG="${_image:-${UI_LEGACY_BUILD_CONTAINER_DEFAULT}}" + refresh_docker_images "${_sdir}" ui-legacy-build-image || return 1 + fi + status_stage "==> Building UI" + build_ui_legacy "${_sdir}" "${_image}" || return 1 + ;; + * ) + err_usage "ERROR: Unknown command: '${_command}'" + return 1 + ;; + esac + + return 0 +} + +main "$@" +exit $? diff --git a/build-support/scripts/build-docker.sh b/build-support/scripts/build-docker.sh deleted file mode 100755 index ac0270a2ce5f..000000000000 --- a/build-support/scripts/build-docker.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/bash -SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -popd > /dev/null -pushd ../functions > /dev/null -FN_DIR=$(pwd) -popd > /dev/null -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -usage() { -cat <<-EOF -Usage: ${SCRIPT_NAME} (consul|ui|ui-legacy|static-assets) [] - -Description: - This script will build the various Consul components within docker containers - and copy all the relevant artifacts out of the containers back to the source. - -Options: - -i | --image IMAGE Alternative Docker image to run the build within. - - -s | --source DIR Path to source to build. - Defaults to "${SOURCE_DIR}" - - -r | --refresh Enables refreshing the docker image prior to building. - - -h | --help Print this help text. -EOF -} - -err_usage() { - err "$1" - err "" - err "$(usage)" -} - -main() { - local _image= - local _sdir="${SOURCE_DIR}" - local _refresh=0 - local _command="" - - while (( $# )); do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -i | --image ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -i/--image requires an argument" - return 1 - fi - - _image="$2" - shift 2 - ;; - -s | --source ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -s/--source requires an argument" - return 1 - fi - - if ! [[ -d "$2" ]]; then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - - _sdir="$2" - shift 2 - ;; - -r | --refresh ) - _refresh=1 - shift - ;; - consul | ui | ui-legacy | static-assets ) - _command="$1" - shift - ;; - * ) - err_usage "ERROR: Unknown argument '$1'" - return 1 - ;; - esac - done - - if [[ -z "${_command}" ]]; then - err_usage "ERROR: No command specified" - return 1 - fi - - case "${_command}" in - consul ) - if [[ $(is_set "${_refresh}") == 0 ]]; then - status_stage "==> Refreshing Consul build container image" - export GO_BUILD_TAG="${_image:-${GO_BUILD_CONTAINER_DEFAULT}}" - refresh_docker_images "${_sdir}" go-build-image || return 1 - fi - status_stage "==> Building Consul" - build_consul "${_sdir}" "" "${_image}" || return 1 - ;; - static-assets ) - if [[ $(is_set "${_refresh}") == 0 ]]; then - status_stage "==> Refreshing Consul build container image" - export GO_BUILD_TAG="${_image:-${GO_BUILD_CONTAINER_DEFAULT}}" - refresh_docker_images "${_sdir}" go-build-image || return 1 - fi - status_stage "==> Building Static Assets" - build_assetfs "${_sdir}" "${_image}" || return 1 - ;; - ui ) - if [[ $(is_set "${_refresh}") == 0 ]]; then - status_stage "==> Refreshing UI build container image" - export UI_BUILD_TAG="${_image:-${UI_BUILD_CONTAINER_DEFAULT}}" - refresh_docker_images "${_sdir}" ui-build-image || return 1 - fi - status_stage "==> Building UI" - build_ui "${_sdir}" "${_image}" || return 1 - status "==> UI Built with Version: $(ui_version ${_sdir}/pkg/web_ui/v2/index.html), Logo: $(ui_logo_type ${_sdir}/pkg/web_ui/v2/index.html)" - ;; - ui-legacy ) - if [[ $(is_set "${_refresh}") == 0 ]]; then - status_stage "==> Refreshing Legacy UI build container image" - export UI_LEGACY_BUILD_TAG="${_image:-${UI_LEGACY_BUILD_CONTAINER_DEFAULT}}" - refresh_docker_images "${_sdir}" ui-legacy-build-image || return 1 - fi - status_stage "==> Building UI" - build_ui_legacy "${_sdir}" "${_image}" || return 1 - ;; - * ) - err_usage "ERROR: Unknown command: '${_command}'" - return 1 - ;; - esac - - return 0 -} - -main "$@" -exit $? diff --git a/build-support/scripts/build-local b/build-support/scripts/build-local deleted file mode 120000 index be483e387f0c..000000000000 --- a/build-support/scripts/build-local +++ /dev/null @@ -1 +0,0 @@ -build-local.sh \ No newline at end of file diff --git a/build-support/scripts/build-local b/build-support/scripts/build-local new file mode 100755 index 000000000000..03a38d3d0ccf --- /dev/null +++ b/build-support/scripts/build-local @@ -0,0 +1,101 @@ +#!/bin/bash +SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" +pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null +SCRIPT_DIR=$(pwd) +pushd ../.. > /dev/null +SOURCE_DIR=$(pwd) +popd > /dev/null +pushd ../functions > /dev/null +FN_DIR=$(pwd) +popd > /dev/null +popd > /dev/null + +source "${SCRIPT_DIR}/functions.sh" + +usage() { +cat <<-EOF +Usage: ${SCRIPT_NAME} [] + +Description: + This script will build the Consul binary on the local system. + All the requisite tooling must be installed for this to be + successful. + +Options: + + -s | --source DIR Path to source to build. + Defaults to "${SOURCE_DIR}" + + -o | --os OSES Space separated string of OS + platforms to build. + + -a | --arch ARCH Space separated string of + architectures to build. + + -h | --help Print this help text. +EOF +} + +err_usage() { + err "$1" + err "" + err "$(usage)" +} + +main() { + local _sdir="${SOURCE_DIR}" + local _build_os="" + local _build_arch="" + + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + -s | --source ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -s/--source requires an argument" + return 1 + fi + + if ! [[ -d "$2" ]]; then + err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" + return 1 + fi + + _sdir="$2" + shift 2 + ;; + -o | --os ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -o/--os requires an argument" + return 1 + fi + + _build_os="$2" + shift 2 + ;; + -a | --arch ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -a/--arch requires an argument" + return 1 + fi + + _build_arch="$2" + shift 2 + ;; + * ) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + build_consul_local "${_sdir}" "${_build_os}" "${_build_arch}" || return 1 + + return 0 +} + +main "$@" +exit $? diff --git a/build-support/scripts/build-local.sh b/build-support/scripts/build-local.sh deleted file mode 100755 index 03a38d3d0ccf..000000000000 --- a/build-support/scripts/build-local.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash -SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -popd > /dev/null -pushd ../functions > /dev/null -FN_DIR=$(pwd) -popd > /dev/null -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -usage() { -cat <<-EOF -Usage: ${SCRIPT_NAME} [] - -Description: - This script will build the Consul binary on the local system. - All the requisite tooling must be installed for this to be - successful. - -Options: - - -s | --source DIR Path to source to build. - Defaults to "${SOURCE_DIR}" - - -o | --os OSES Space separated string of OS - platforms to build. - - -a | --arch ARCH Space separated string of - architectures to build. - - -h | --help Print this help text. -EOF -} - -err_usage() { - err "$1" - err "" - err "$(usage)" -} - -main() { - local _sdir="${SOURCE_DIR}" - local _build_os="" - local _build_arch="" - - while (( $# )); do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -s | --source ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -s/--source requires an argument" - return 1 - fi - - if ! [[ -d "$2" ]]; then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - - _sdir="$2" - shift 2 - ;; - -o | --os ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -o/--os requires an argument" - return 1 - fi - - _build_os="$2" - shift 2 - ;; - -a | --arch ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -a/--arch requires an argument" - return 1 - fi - - _build_arch="$2" - shift 2 - ;; - * ) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - build_consul_local "${_sdir}" "${_build_os}" "${_build_arch}" || return 1 - - return 0 -} - -main "$@" -exit $? diff --git a/build-support/scripts/dev b/build-support/scripts/dev deleted file mode 120000 index d9af37ed1261..000000000000 --- a/build-support/scripts/dev +++ /dev/null @@ -1 +0,0 @@ -dev.sh \ No newline at end of file diff --git a/build-support/scripts/dev b/build-support/scripts/dev new file mode 100755 index 000000000000..28fee429d2ea --- /dev/null +++ b/build-support/scripts/dev @@ -0,0 +1,100 @@ +#!/bin/bash +SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" +pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null +SCRIPT_DIR=$(pwd) +pushd ../.. > /dev/null +SOURCE_DIR=$(pwd) +popd > /dev/null +pushd ../functions > /dev/null +FN_DIR=$(pwd) +popd > /dev/null +popd > /dev/null + +source "${SCRIPT_DIR}/functions.sh" + +usage() { +cat <<-EOF +Usage: ${SCRIPT_NAME} [] + +Description: + + This script will put the source back into dev mode after a release. + +Options: + + -s | --source DIR Path to source to build. + Defaults to "${SOURCE_DIR}" + + --no-git Do not commit or attempt to push + the changes back to the upstream. + + -h | --help Print this help text. +EOF +} + +err_usage() { + err "$1" + err "" + err "$(usage)" +} + +main() { + local _sdir="${SOURCE_DIR}" + local _do_git=1 + local _do_push=1 + + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + -s | --source ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -s/--source requires an argument" + return 1 + fi + + if ! [[ -d "$2" ]]; then + err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" + return 1 + fi + + _sdir="$2" + shift 2 + ;; + --no-git ) + _do_git=0 + shift + ;; + --no-push ) + _do_push=0 + shift + ;; + * ) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + set_dev_mode "${_sdir}" || return 1 + + if [[ $(is_set "${_do_git}") == 0 ]]; then + status_stage "==> Commiting Dev Mode Changes" + commit_dev_mode "${_sdir}" || return 1 + + if [[ $(is_set "${_do_push}") == 0 ]]; then + status_stage "==> Confirming Git Changes" + confirm_git_push_changes "${_sdir}" || return 1 + + status_stage "==> Pushing to Git" + git_push_ref "${_sdir}" || return 1 + fi + fi + + return 0 +} + +main "$@" +exit $? diff --git a/build-support/scripts/dev.sh b/build-support/scripts/dev.sh deleted file mode 100755 index 28fee429d2ea..000000000000 --- a/build-support/scripts/dev.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash -SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -popd > /dev/null -pushd ../functions > /dev/null -FN_DIR=$(pwd) -popd > /dev/null -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -usage() { -cat <<-EOF -Usage: ${SCRIPT_NAME} [] - -Description: - - This script will put the source back into dev mode after a release. - -Options: - - -s | --source DIR Path to source to build. - Defaults to "${SOURCE_DIR}" - - --no-git Do not commit or attempt to push - the changes back to the upstream. - - -h | --help Print this help text. -EOF -} - -err_usage() { - err "$1" - err "" - err "$(usage)" -} - -main() { - local _sdir="${SOURCE_DIR}" - local _do_git=1 - local _do_push=1 - - while (( $# )); do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -s | --source ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -s/--source requires an argument" - return 1 - fi - - if ! [[ -d "$2" ]]; then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - - _sdir="$2" - shift 2 - ;; - --no-git ) - _do_git=0 - shift - ;; - --no-push ) - _do_push=0 - shift - ;; - * ) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - set_dev_mode "${_sdir}" || return 1 - - if [[ $(is_set "${_do_git}") == 0 ]]; then - status_stage "==> Commiting Dev Mode Changes" - commit_dev_mode "${_sdir}" || return 1 - - if [[ $(is_set "${_do_push}") == 0 ]]; then - status_stage "==> Confirming Git Changes" - confirm_git_push_changes "${_sdir}" || return 1 - - status_stage "==> Pushing to Git" - git_push_ref "${_sdir}" || return 1 - fi - fi - - return 0 -} - -main "$@" -exit $? diff --git a/build-support/scripts/functions b/build-support/scripts/functions deleted file mode 120000 index 2cc997b9ca13..000000000000 --- a/build-support/scripts/functions +++ /dev/null @@ -1 +0,0 @@ -functions.sh \ No newline at end of file diff --git a/build-support/scripts/functions.sh b/build-support/scripts/functions.sh old mode 100755 new mode 100644 diff --git a/build-support/scripts/publish b/build-support/scripts/publish deleted file mode 120000 index ee9014a91811..000000000000 --- a/build-support/scripts/publish +++ /dev/null @@ -1 +0,0 @@ -publish.sh \ No newline at end of file diff --git a/build-support/scripts/publish b/build-support/scripts/publish new file mode 100755 index 000000000000..ef5ee2e2759e --- /dev/null +++ b/build-support/scripts/publish @@ -0,0 +1,90 @@ +#!/bin/bash +SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" +pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null +SCRIPT_DIR=$(pwd) +pushd ../.. > /dev/null +SOURCE_DIR=$(pwd) +popd > /dev/null +pushd ../functions > /dev/null +FN_DIR=$(pwd) +popd > /dev/null +popd > /dev/null + +source "${SCRIPT_DIR}/functions.sh" + +usage() { +cat <<-EOF +Usage: ${SCRIPT_NAME} [] + +Description: + + This script will "publish" a Consul release. It expects a prebuilt release in + pkg/dist matching the version in the repo and a clean git status. It will + prompt you to confirm the consul version and git changes you are going to + publish prior to pushing to git and to releases.hashicorp.com. + +Options: + -s | --source DIR Path to source to build. + Defaults to "${SOURCE_DIR}" + + -w | --website Publish to releases.hashicorp.com + + -g | --git Push release commit and tag to Git + + -h | --help Print this help text. +EOF +} + +err_usage() { + err "$1" + err "" + err "$(usage)" +} + +main() { + local _sdir="${SOURCE_DIR}" + local _website=0 + local _git_push=0 + + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + -s | --source ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -s/--source requires an argument" + return 1 + fi + + if ! [[ -d "$2" ]]; then + err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" + return 1 + fi + + _sdir="$2" + shift 2 + ;; + -w | --website ) + _website=1 + shift + ;; + -g | --git ) + _git_push=1 + shift + ;; + *) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + publish_release "${_sdir}" "${_git_push}" "${_website}" || return 1 + + return 0 +} + +main "$@" +exit $? diff --git a/build-support/scripts/publish.sh b/build-support/scripts/publish.sh deleted file mode 100755 index ef5ee2e2759e..000000000000 --- a/build-support/scripts/publish.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash -SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -popd > /dev/null -pushd ../functions > /dev/null -FN_DIR=$(pwd) -popd > /dev/null -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -usage() { -cat <<-EOF -Usage: ${SCRIPT_NAME} [] - -Description: - - This script will "publish" a Consul release. It expects a prebuilt release in - pkg/dist matching the version in the repo and a clean git status. It will - prompt you to confirm the consul version and git changes you are going to - publish prior to pushing to git and to releases.hashicorp.com. - -Options: - -s | --source DIR Path to source to build. - Defaults to "${SOURCE_DIR}" - - -w | --website Publish to releases.hashicorp.com - - -g | --git Push release commit and tag to Git - - -h | --help Print this help text. -EOF -} - -err_usage() { - err "$1" - err "" - err "$(usage)" -} - -main() { - local _sdir="${SOURCE_DIR}" - local _website=0 - local _git_push=0 - - while (( $# )); do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -s | --source ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -s/--source requires an argument" - return 1 - fi - - if ! [[ -d "$2" ]]; then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - - _sdir="$2" - shift 2 - ;; - -w | --website ) - _website=1 - shift - ;; - -g | --git ) - _git_push=1 - shift - ;; - *) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - publish_release "${_sdir}" "${_git_push}" "${_website}" || return 1 - - return 0 -} - -main "$@" -exit $? diff --git a/build-support/scripts/release b/build-support/scripts/release deleted file mode 120000 index 012c00f9fbbe..000000000000 --- a/build-support/scripts/release +++ /dev/null @@ -1 +0,0 @@ -release.sh \ No newline at end of file diff --git a/build-support/scripts/release b/build-support/scripts/release new file mode 100755 index 000000000000..af5add1965f1 --- /dev/null +++ b/build-support/scripts/release @@ -0,0 +1,153 @@ +#!/bin/bash +SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" +pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null +SCRIPT_DIR=$(pwd) +pushd ../.. > /dev/null +SOURCE_DIR=$(pwd) +popd > /dev/null +pushd ../functions > /dev/null +FN_DIR=$(pwd) +popd > /dev/null +popd > /dev/null + +source "${SCRIPT_DIR}/functions.sh" + +usage() { +cat <<-EOF +Usage: ${SCRIPT_NAME} [] + +Description: + + This script will do a full release build of Consul. Building each component + is done within a docker container. In addition to building Consul this + script will do a few more things. + + * Update version/version*.go files + * Update CHANGELOG.md to put things into release mode + * Create a release commit. It changes in the commit include the CHANGELOG.md + version files and the assetfs. + * Tag the release + * Generate the SHA256SUMS file for the binaries + * Sign the SHA256SUMS file with a GPG key + + +Options: + -s | --source DIR Path to source to build. + Defaults to "${SOURCE_DIR}" + + -t | --tag BOOL Whether to add a release commit and tag the build. + This also controls whether we put the tree into + release mode + Defaults to 1. + + -b | --build BOOL Whether to perform the build of the ui's, assetfs and + binaries. Defaults to 1. + + -S | --sign BOOL Whether to sign the generated SHA256SUMS file. + Defaults to 1. + + -g | --gpg-key KEY Alternative GPG key to use for signing operations. + Defaults to ${HASHICORP_GPG_KEY} + + -v | --version VERSION The version of Consul to be built. If not specified + the version will be parsed from the source. + + -d | --date DATE The release date. Defaults to today. + + -r | --release STRING The prerelease version. Defaults to an empty pre-release. + + -h | --help Print this help text. +EOF +} + +err_usage() { + err "$1" + err "" + err "$(usage)" +} + +ensure_arg() { + if test -z "$2" + then + err_usage "ERROR: option $1 requires an argument" + return 1 + fi + + return 0 +} + +main() { + local _sdir="${SOURCE_DIR}" + local _do_tag=1 + local _do_build=1 + local _do_sign=1 + local _gpg_key="${HASHICORP_GPG_KEY}" + local _version="" + local _release_ver="" + local _release_date=$(date +"%B %d, %Y") + + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + -s | --source ) + ensure_arg "-s/--source" "$2" || return 1 + + if ! [[ -d "$2" ]]; then + err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" + return 1 + fi + + _sdir="$2" + shift 2 + ;; + -t | --tag ) + ensure_arg "-t/--tag" "$2" || return 1 + _do_tag="$2" + shift 2 + ;; + -b | --build ) + ensure_arg "-b/--build" "$2" || return 1 + _do_build="$2" + shift 2 + ;; + -S | --sign ) + ensure_arg "-s/--sign" "$2" || return 1 + _do_sign="$2" + shift 2 + ;; + -g | --gpg-key ) + ensure_arg "-g/--gpg-key" "$2" || return 1 + _gpg_key="$2" + shift 2 + ;; + -v | --version ) + ensure_arg "-v/--version" "$2" || return 1 + _version="$2" + shift 2 + ;; + -d | --date) + ensure_arg "-d/--date" "$2" || return 1 + _release_date="$2" + shift 2 + ;; + -r | --release) + ensure_arg "-r/--release" "$2" || return 1 + _release_ver="$2" + shift 2 + ;; + *) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + build_release "${_sdir}" "${_do_tag}" "${_do_build}" "${_do_sign}" "${_version}" "${_release_date}" "${_release_ver}" "${_gpg_key}" + return $? +} + +main "$@" +exit $? diff --git a/build-support/scripts/release.sh b/build-support/scripts/release.sh deleted file mode 100755 index af5add1965f1..000000000000 --- a/build-support/scripts/release.sh +++ /dev/null @@ -1,153 +0,0 @@ -#!/bin/bash -SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -popd > /dev/null -pushd ../functions > /dev/null -FN_DIR=$(pwd) -popd > /dev/null -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -usage() { -cat <<-EOF -Usage: ${SCRIPT_NAME} [] - -Description: - - This script will do a full release build of Consul. Building each component - is done within a docker container. In addition to building Consul this - script will do a few more things. - - * Update version/version*.go files - * Update CHANGELOG.md to put things into release mode - * Create a release commit. It changes in the commit include the CHANGELOG.md - version files and the assetfs. - * Tag the release - * Generate the SHA256SUMS file for the binaries - * Sign the SHA256SUMS file with a GPG key - - -Options: - -s | --source DIR Path to source to build. - Defaults to "${SOURCE_DIR}" - - -t | --tag BOOL Whether to add a release commit and tag the build. - This also controls whether we put the tree into - release mode - Defaults to 1. - - -b | --build BOOL Whether to perform the build of the ui's, assetfs and - binaries. Defaults to 1. - - -S | --sign BOOL Whether to sign the generated SHA256SUMS file. - Defaults to 1. - - -g | --gpg-key KEY Alternative GPG key to use for signing operations. - Defaults to ${HASHICORP_GPG_KEY} - - -v | --version VERSION The version of Consul to be built. If not specified - the version will be parsed from the source. - - -d | --date DATE The release date. Defaults to today. - - -r | --release STRING The prerelease version. Defaults to an empty pre-release. - - -h | --help Print this help text. -EOF -} - -err_usage() { - err "$1" - err "" - err "$(usage)" -} - -ensure_arg() { - if test -z "$2" - then - err_usage "ERROR: option $1 requires an argument" - return 1 - fi - - return 0 -} - -main() { - local _sdir="${SOURCE_DIR}" - local _do_tag=1 - local _do_build=1 - local _do_sign=1 - local _gpg_key="${HASHICORP_GPG_KEY}" - local _version="" - local _release_ver="" - local _release_date=$(date +"%B %d, %Y") - - while (( $# )); do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -s | --source ) - ensure_arg "-s/--source" "$2" || return 1 - - if ! [[ -d "$2" ]]; then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - - _sdir="$2" - shift 2 - ;; - -t | --tag ) - ensure_arg "-t/--tag" "$2" || return 1 - _do_tag="$2" - shift 2 - ;; - -b | --build ) - ensure_arg "-b/--build" "$2" || return 1 - _do_build="$2" - shift 2 - ;; - -S | --sign ) - ensure_arg "-s/--sign" "$2" || return 1 - _do_sign="$2" - shift 2 - ;; - -g | --gpg-key ) - ensure_arg "-g/--gpg-key" "$2" || return 1 - _gpg_key="$2" - shift 2 - ;; - -v | --version ) - ensure_arg "-v/--version" "$2" || return 1 - _version="$2" - shift 2 - ;; - -d | --date) - ensure_arg "-d/--date" "$2" || return 1 - _release_date="$2" - shift 2 - ;; - -r | --release) - ensure_arg "-r/--release" "$2" || return 1 - _release_ver="$2" - shift 2 - ;; - *) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - build_release "${_sdir}" "${_do_tag}" "${_do_build}" "${_do_sign}" "${_version}" "${_release_date}" "${_release_ver}" "${_gpg_key}" - return $? -} - -main "$@" -exit $? diff --git a/build-support/scripts/test-flake b/build-support/scripts/test-flake deleted file mode 120000 index 4879773be8c8..000000000000 --- a/build-support/scripts/test-flake +++ /dev/null @@ -1 +0,0 @@ -test-flake.sh \ No newline at end of file diff --git a/build-support/scripts/test-flake b/build-support/scripts/test-flake new file mode 100755 index 000000000000..cd7b8b746b62 --- /dev/null +++ b/build-support/scripts/test-flake @@ -0,0 +1,157 @@ +#!/bin/bash +pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null +SCRIPT_DIR=$(pwd) +pushd ../.. > /dev/null +SOURCE_DIR=$(pwd) +pushd build-support/docker > /dev/null +IMG_DIR=$(pwd) +popd > /dev/null + +source "${SCRIPT_DIR}/functions.sh" + +IMAGE="travis-img-v0.13" +CONTAINER="travis-cnt" +GOOS="linux" +GOARCH="amd64" +TEST_BINARY="flake.test" + +usage() { +cat <<-EOF +Usage: test-flake [] + +Description: + + test-flake surfaces flakiness in tests by constraining CPU resources. + + Single or package-wide tests are run for multiple iterations with a configurable + amount of CPU resources. + + 0.15 CPUs and 30 iterations are configured as sane defaults. + + See Docker docs for more info on tuning 'cpus' param: + https://docs.docker.com/config/containers/resource_constraints/#cpu + +Options: + + --pkg="" Target package + --test="" Target test (requires pkg flag) + --cpus=0.15 Amount of CPU resources for container + --n=30 Number of times to run tests + +Examples: + + ./test-flake.sh --pkg connect/proxy + ./test-flake.sh --pkg connect/proxy --cpus 0.20 + ./test-flake.sh --pkg connect/proxy --test Listener + ./test-flake.sh --pkg connect/proxy --test TestUpstreamListener + ./test-flake.sh --pkg connect/proxy --test TestUpstreamListener -n 100 +EOF +} + +build_repro_env() { + # Arguments: + # $1 - pkg, Target package + # $2 - test, Target tests + # $3 - cpus, Amount of CPU resources for container + # $4 - n, Number of times to run tests + + APP=$(pwd | awk '{n=split($0, a, "/"); print a[n]}') + + status_stage -e "App:\t\t$APP" + status_stage -e "Package:\t$1" + status_stage -e "Test:\t\t$2" + status_stage -e "CPUs:\t\t$3" + status_stage -e "Iterations:\t$4" + echo + + status_stage "----> Cleaning up old containers..." + if docker ps -a | grep $CONTAINER ; then + docker rm $(docker ps -a | grep $CONTAINER | awk '{print $1;}') + fi + + status_stage '----> Rebuilding image...' + (cd $IMG_DIR && docker build -q -t $IMAGE --no-cache -f Test-Flake.dockerfile .) + + status_stage "--> Building app binary..." + env GOOS=$GOOS GOARCH=$GOARCH go build -o bin/$APP + + status_stage "-> Building test binary..." + env GOOS=$GOOS GOARCH=$GOARCH go test -c "./$1" -o $TEST_BINARY + + status_stage "> Running container..." + status_stage + + docker run \ + --rm \ + --name $CONTAINER \ + --cpus="$3" \ + -v $SOURCE_DIR:/home/travis/go/$APP \ + -e TEST_BINARY="$TEST_BINARY" \ + -e TEST_PKG="$1" \ + -e TEST="$2" \ + -e ITERATIONS="$4" \ + -e APP="$APP" \ + $IMAGE +} + +err_usage() { + err "$1" + err "" + err "$(usage)" +} + +main() { + local _pkg="" + local _test="" + local _cpus="" + local _n="" + + + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + --pkg ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option pkg requires an argument" + return 1 + fi + _pkg="$2" + shift 2 + ;; + --test ) + _test="$2" + shift 2 + ;; + --cpus ) + if [[ -n "$2" ]]; then + _cpus="$2" + else + _cpus="0.15" + fi + shift 2 + ;; + --n ) + if [[ -n "$2" ]]; then + _n="$2" + else + _n="30" + fi + shift 2 + ;; + * ) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + build_repro_env "${_pkg}" "${_test}" "${_cpus}" "${_n}" || return 1 + + return 0 +} + +main "$@" +exit $? diff --git a/build-support/scripts/test-flake.sh b/build-support/scripts/test-flake.sh deleted file mode 100755 index cd7b8b746b62..000000000000 --- a/build-support/scripts/test-flake.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/bin/bash -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -pushd build-support/docker > /dev/null -IMG_DIR=$(pwd) -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -IMAGE="travis-img-v0.13" -CONTAINER="travis-cnt" -GOOS="linux" -GOARCH="amd64" -TEST_BINARY="flake.test" - -usage() { -cat <<-EOF -Usage: test-flake [] - -Description: - - test-flake surfaces flakiness in tests by constraining CPU resources. - - Single or package-wide tests are run for multiple iterations with a configurable - amount of CPU resources. - - 0.15 CPUs and 30 iterations are configured as sane defaults. - - See Docker docs for more info on tuning 'cpus' param: - https://docs.docker.com/config/containers/resource_constraints/#cpu - -Options: - - --pkg="" Target package - --test="" Target test (requires pkg flag) - --cpus=0.15 Amount of CPU resources for container - --n=30 Number of times to run tests - -Examples: - - ./test-flake.sh --pkg connect/proxy - ./test-flake.sh --pkg connect/proxy --cpus 0.20 - ./test-flake.sh --pkg connect/proxy --test Listener - ./test-flake.sh --pkg connect/proxy --test TestUpstreamListener - ./test-flake.sh --pkg connect/proxy --test TestUpstreamListener -n 100 -EOF -} - -build_repro_env() { - # Arguments: - # $1 - pkg, Target package - # $2 - test, Target tests - # $3 - cpus, Amount of CPU resources for container - # $4 - n, Number of times to run tests - - APP=$(pwd | awk '{n=split($0, a, "/"); print a[n]}') - - status_stage -e "App:\t\t$APP" - status_stage -e "Package:\t$1" - status_stage -e "Test:\t\t$2" - status_stage -e "CPUs:\t\t$3" - status_stage -e "Iterations:\t$4" - echo - - status_stage "----> Cleaning up old containers..." - if docker ps -a | grep $CONTAINER ; then - docker rm $(docker ps -a | grep $CONTAINER | awk '{print $1;}') - fi - - status_stage '----> Rebuilding image...' - (cd $IMG_DIR && docker build -q -t $IMAGE --no-cache -f Test-Flake.dockerfile .) - - status_stage "--> Building app binary..." - env GOOS=$GOOS GOARCH=$GOARCH go build -o bin/$APP - - status_stage "-> Building test binary..." - env GOOS=$GOOS GOARCH=$GOARCH go test -c "./$1" -o $TEST_BINARY - - status_stage "> Running container..." - status_stage - - docker run \ - --rm \ - --name $CONTAINER \ - --cpus="$3" \ - -v $SOURCE_DIR:/home/travis/go/$APP \ - -e TEST_BINARY="$TEST_BINARY" \ - -e TEST_PKG="$1" \ - -e TEST="$2" \ - -e ITERATIONS="$4" \ - -e APP="$APP" \ - $IMAGE -} - -err_usage() { - err "$1" - err "" - err "$(usage)" -} - -main() { - local _pkg="" - local _test="" - local _cpus="" - local _n="" - - - while (( $# )); do - case "$1" in - -h | --help ) - usage - return 0 - ;; - --pkg ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option pkg requires an argument" - return 1 - fi - _pkg="$2" - shift 2 - ;; - --test ) - _test="$2" - shift 2 - ;; - --cpus ) - if [[ -n "$2" ]]; then - _cpus="$2" - else - _cpus="0.15" - fi - shift 2 - ;; - --n ) - if [[ -n "$2" ]]; then - _n="$2" - else - _n="30" - fi - shift 2 - ;; - * ) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - build_repro_env "${_pkg}" "${_test}" "${_cpus}" "${_n}" || return 1 - - return 0 -} - -main "$@" -exit $? diff --git a/build-support/scripts/verify b/build-support/scripts/verify deleted file mode 120000 index 97252ee9c85c..000000000000 --- a/build-support/scripts/verify +++ /dev/null @@ -1 +0,0 @@ -verify.sh \ No newline at end of file diff --git a/build-support/scripts/verify b/build-support/scripts/verify new file mode 100755 index 000000000000..e7836de16fb9 --- /dev/null +++ b/build-support/scripts/verify @@ -0,0 +1,88 @@ +#!/bin/bash +SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" +pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null +SCRIPT_DIR=$(pwd) +pushd ../.. > /dev/null +SOURCE_DIR=$(pwd) +popd > /dev/null +pushd ../functions > /dev/null +FN_DIR=$(pwd) +popd > /dev/null +popd > /dev/null + +source "${SCRIPT_DIR}/functions.sh" + +usage() { +cat <<-EOF +Usage: ${SCRIPT_NAME} [] + +Description: + + This script will verify a Consul release build. It will check for prebuilt + files, verify shasums and gpg signatures as well as run some commands + and prompt for manual verification where required. + +Options: + -s | --source DIR Path to source to build. + Defaults to "${SOURCE_DIR}" + + -h | --help Print this help text. +EOF +} + +err_usage() { + err "$1" + err "" + err "$(usage)" +} + +main() { + local _sdir="${SOURCE_DIR}" + local _vers="" + + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + -s | --source ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -s/--source requires an argument" + return 1 + fi + if ! [[ -d "$2" ]]; then + err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" + return 1 + fi + _sdir="$2" + shift 2 + ;; + -v | --version ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -v/--version requires an argument" + return 1 + fi + _vers="$2" + shift 2 + ;; + *) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + if [[ -z "${_vers}" ]]; then + _vers=$(parse_version "${_sdir}" true false) + fi + + status_stage "=> Starting release verification for version: ${version}" + verify_release_build "${_sdir}" "${_vers}" || return 1 + + return 0 +} + +main "$@" +exit $? + diff --git a/build-support/scripts/verify.sh b/build-support/scripts/verify.sh deleted file mode 100755 index e7836de16fb9..000000000000 --- a/build-support/scripts/verify.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash -SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -popd > /dev/null -pushd ../functions > /dev/null -FN_DIR=$(pwd) -popd > /dev/null -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -usage() { -cat <<-EOF -Usage: ${SCRIPT_NAME} [] - -Description: - - This script will verify a Consul release build. It will check for prebuilt - files, verify shasums and gpg signatures as well as run some commands - and prompt for manual verification where required. - -Options: - -s | --source DIR Path to source to build. - Defaults to "${SOURCE_DIR}" - - -h | --help Print this help text. -EOF -} - -err_usage() { - err "$1" - err "" - err "$(usage)" -} - -main() { - local _sdir="${SOURCE_DIR}" - local _vers="" - - while (( $# )); do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -s | --source ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -s/--source requires an argument" - return 1 - fi - if ! [[ -d "$2" ]]; then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - _sdir="$2" - shift 2 - ;; - -v | --version ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -v/--version requires an argument" - return 1 - fi - _vers="$2" - shift 2 - ;; - *) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - if [[ -z "${_vers}" ]]; then - _vers=$(parse_version "${_sdir}" true false) - fi - - status_stage "=> Starting release verification for version: ${version}" - verify_release_build "${_sdir}" "${_vers}" || return 1 - - return 0 -} - -main "$@" -exit $? - diff --git a/build-support/scripts/version b/build-support/scripts/version deleted file mode 120000 index b7ae2b7db3e0..000000000000 --- a/build-support/scripts/version +++ /dev/null @@ -1 +0,0 @@ -version.sh \ No newline at end of file diff --git a/build-support/scripts/version b/build-support/scripts/version new file mode 100755 index 000000000000..74b0aa2c221a --- /dev/null +++ b/build-support/scripts/version @@ -0,0 +1,87 @@ +#!/bin/bash +SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" +pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null +SCRIPT_DIR=$(pwd) +pushd ../.. > /dev/null +SOURCE_DIR=$(pwd) +popd > /dev/null +pushd ../functions > /dev/null +FN_DIR=$(pwd) +popd > /dev/null +popd > /dev/null + +source "${SCRIPT_DIR}/functions.sh" + +usage() { +cat <<-EOF +Usage: ${SCRIPT_NAME} [] + +Description: + + This script is just a convenience around discover what the Consul + version would be if you were to build it. + +Options: + -s | --source DIR Path to source to build. + Defaults to "${SOURCE_DIR}" + + -r | --release Include the release in the version + + -g | --git Take git variables into account + + -h | --help Print this help text. +EOF +} + +err_usage() { + err "$1" + err "" + err "$(usage)" +} + +main() { + local _sdir="${SOURCE_DIR}" + local _release=0 + local _git_info=0 + + while (( $# )); do + case "$1" in + -h | --help ) + usage + return 0 + ;; + -s | --source ) + if [[ -z "$2" ]]; then + err_usage "ERROR: option -s/--source requires an argument" + return 1 + fi + if [[ -d "$2" ]]; then + err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" + return 1 + fi + _sdir="$2" + shift 2 + ;; + -r | --release ) + _release=1 + shift + ;; + -g | --git ) + _git_info=1 + shift + ;; + *) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + parse_version "${_sdir}" "${_release}" "${_git_info}" || return 1 + + return 0 +} + +main "$@" +exit $? + diff --git a/build-support/scripts/version.sh b/build-support/scripts/version.sh deleted file mode 100755 index 74b0aa2c221a..000000000000 --- a/build-support/scripts/version.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash -SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -popd > /dev/null -pushd ../functions > /dev/null -FN_DIR=$(pwd) -popd > /dev/null -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -usage() { -cat <<-EOF -Usage: ${SCRIPT_NAME} [] - -Description: - - This script is just a convenience around discover what the Consul - version would be if you were to build it. - -Options: - -s | --source DIR Path to source to build. - Defaults to "${SOURCE_DIR}" - - -r | --release Include the release in the version - - -g | --git Take git variables into account - - -h | --help Print this help text. -EOF -} - -err_usage() { - err "$1" - err "" - err "$(usage)" -} - -main() { - local _sdir="${SOURCE_DIR}" - local _release=0 - local _git_info=0 - - while (( $# )); do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -s | --source ) - if [[ -z "$2" ]]; then - err_usage "ERROR: option -s/--source requires an argument" - return 1 - fi - if [[ -d "$2" ]]; then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - _sdir="$2" - shift 2 - ;; - -r | --release ) - _release=1 - shift - ;; - -g | --git ) - _git_info=1 - shift - ;; - *) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - parse_version "${_sdir}" "${_release}" "${_git_info}" || return 1 - - return 0 -} - -main "$@" -exit $? -