Update the scripting

Automated putting the source tree into release mode.
This commit is contained in:
Matt Keeler 2018-06-14 21:25:59 -04:00
parent d99ca00d74
commit 57aa738416
14 changed files with 862 additions and 67 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
pkg/
.git
bin/

View File

@ -28,6 +28,20 @@ GIT_DESCRIBE?=$(shell git describe --tags --always)
GIT_IMPORT=github.com/hashicorp/consul/version
GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) -X $(GIT_IMPORT).GitDescribe=$(GIT_DESCRIBE)
ifeq ($(FORCE_REBUILD),1)
NOCACHE=--no-cache
else
NOCACHE=
endif
DOCKER_BUILD_QUIET?=1
ifeq (${DOCKER_BUILD_QUIET},1)
QUIET=-q
else
QUIET=
endif
CONSUL_DEV_IMAGE?=consul-dev
GO_BUILD_TAG?=consul-build-go
UI_BUILD_TAG?=consul-build-ui
UI_LEGACY_BUILD_TAG?=consul-build-ui-legacy
@ -37,6 +51,18 @@ DIST_TAG?=1
DIST_BUILD?=1
DIST_SIGN?=1
ifdef DIST_VERSION
DIST_VERSION_ARG=-v $(DIST_VERSION)
else
DIST_VERSION_ARG=
endif
ifdef DIST_RELEASE_DATE
DIST_DATE_ARG=-d $(DIST_RELEASE_DATE)
else
DIST_DATE_ARG=
endif
export GO_BUILD_TAG
export UI_BUILD_TAG
export UI_LEGACY_BUILD_TAG
@ -57,7 +83,11 @@ bin: tools
dev: changelogfmt vendorfmt dev-build
dev-build:
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh consul-local -o '$(GOOS)' -a '$(GOARCH)'
@$(SHELL) $(CURDIR)/build-support/scripts/build-local.sh
dev-docker:
@$(SHELL)
@docker build -t '$(CONSUL_DEV_IMAGE)' --build-arg 'GIT_COMMIT=$(GIT_COMMIT)' --build-arg 'GIT_DIRTY=$(GIT_DIRTY)' --build-arg 'GIT_DESCRIBE=$(GIT_DESCRIBE)' -f $(CURDIR)/build-support/docker/Consul-Dev.dockerfile $(CURDIR)
vendorfmt:
@echo "--> Formatting vendor/vendor.json"
@ -70,14 +100,14 @@ changelogfmt:
# linux builds a linux package independent of the source platform
linux:
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh consul-local -o linux -a amd64
@$(SHELL) $(CURDIR)/build-support/scripts/build-local.sh -o linux -a amd64
# dist builds binaries for all platforms and packages them for distribution
dist:
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh release -t '$(DIST_TAG)' -b '$(DIST_BUILD)' -S '$(DIST_SIGN)'
@$(SHELL) $(CURDIR)/build-support/scripts/release.sh -t '$(DIST_TAG)' -b '$(DIST_BUILD)' -S '$(DIST_SIGN)' '$(DIST_VERSION_ARG)' '$(DIST_DATE_ARG)'
publish:
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh publish
@$(SHELL) $(CURDIR)/build-support/scripts/publish.sh -g -w
cov:
gocov test $(GOFILES) | gocov-html > /tmp/coverage.html
@ -143,37 +173,40 @@ tools:
version:
@echo -n "Version: "
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh version
@$(SHELL) $(CURDIR)/build-support/scripts/version.sh
@echo -n "Version + release: "
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh version -R
@$(SHELL) $(CURDIR)/build-support/scripts/version.sh -r
@echo -n "Version + git: "
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh version -G
@$(SHELL) $(CURDIR)/build-support/scripts/version.sh -g
@echo -n "Version + release + git: "
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh version -R -G
@$(SHELL) $(CURDIR)/build-support/scripts/version.sh -r -g
docker-images:
@$(MAKE) -C build-support/docker images
docker-images: go-build-image ui-build-image ui-legacy-build-image
go-build-image:
@$(MAKE) -C build-support/docker go-build-image
@echo "Building Golang build container"
@docker build $(NOCACHE) $(QUIET) --build-arg 'GOTOOLS=$(GOTOOLS)' -t $(GO_BUILD_TAG) - < build-support/docker/Build-Go.dockerfile
ui-build-image:
@$(MAKE) -C build-support/docker ui-build-image
@echo "Building UI build container"
@docker build $(NOCACHE) $(QUIET) -t $(UI_BUILD_TAG) - < build-support/docker/Build-UI.dockerfile
ui-legacy-build-image:
@$(MAKE) -C build-support/docker ui-legacy-build-image
@echo "Building Legacy UI build container"
@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.sh assetfs
@$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh static-assets
consul-docker: go-build-image
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh consul
@$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh consul
ui-docker: ui-build-image
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh ui
@$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh ui
ui-legacy-docker: ui-legacy-build-image
@$(SHELL) $(CURDIR)/build-support/scripts/build.sh ui-legacy
@$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh ui-legacy
.PHONY: all ci bin dev dist cov test cover format vet ui static-assets tools vendorfmt

View File

@ -0,0 +1,13 @@
FROM golang:latest as builder
ARG GIT_COMMIT
ARG GIT_DIRTY
ARG GIT_DESCRIBE
WORKDIR /go/src/github.com/hashicorp/consul
ENV CONSUL_DEV=1
ENV COLORIZE=0
Add . /go/src/github.com/hashicorp/consul/
RUN make
FROM consul:latest
COPY --from=builder /go/src/github.com/hashicorp/consul/bin/consul /bin

View File

@ -1,28 +0,0 @@
ifeq ($(FORCE_REBUILD),1)
NOCACHE=--no-cache
else
NOCACHE=
endif
GO_BUILD_TAG?=consul-build-go
UI_BUILD_TAG?=consul-build-ui
UI_LEGACY_BUILD_TAG?=consul-build-ui-legacy
DOCKER_BUILD_QUIET?=1
ifeq (${DOCKER_BUILD_QUIET},1)
QUIET=-q
else
QUIET=
endif
images: go-build-image ui-build-image ui-legacy-build-image
go-build-image:
docker build $(NOCACHE) $(QUIET) -t $(GO_BUILD_TAG) -f Build-Go.dockerfile .
ui-build-image:
docker build $(NOCACHE) $(QUIET) -t $(UI_BUILD_TAG) -f Build-UI.dockerfile .
ui-legacy-build-image:
docker build $(NOCACHE) $(QUIET) -t $(UI_LEGACY_BUILD_TAG) -f Build-UI-Legacy.dockerfile .
.PHONY: images go-build-image ui-build-image ui-legacy-build-image

View File

@ -7,7 +7,10 @@ UI_LEGACY_BUILD_CONTAINER_DEFAULT="consul-build-ui-legacy"
GO_BUILD_CONTAINER_DEFAULT="consul-build-go"
# Whether to colorize shell output
if test -z "${COLORIZE}"
then
COLORIZE=1
fi
# determine GOPATH and the first GOPATH to use for intalling binaries
@ -37,3 +40,11 @@ if test -z "${PUBLISH_GIT_REPO}"
then
PUBLISH_GIT_REPO=hashicorp/consul.git
fi
if test "$(uname)" == "Darwin"
then
SED_EXT="-E"
else
SED_EXT=""
fi

View File

@ -313,7 +313,7 @@ function normalize_git_url {
url="${1#https://}"
url="${url#git@}"
url="${url%.git}"
url="$(sed -e 's/\([^\/:]*\)[:\/]\(.*\)/\1:\2/' <<< "${url}")"
url="$(sed ${SED_EXT} -e 's/\([^\/:]*\)[:\/]\(.*\)/\1:\2/' <<< "${url}")"
echo "$url"
return 0
}
@ -389,3 +389,192 @@ function is_git_clean {
popd > /dev/null
return ${ret}
}
function update_version {
# Arguments:
# $1 - Path to the version file
# $2 - Version string
# $3 - PreRelease version (if unset will become an empty string)
#
# Returns:
# 0 - success
# * - error
if ! test -f "$1"
then
err "ERROR: '$1' is not a regular file. update_version must be called with the path to a go version file"
return 1
fi
if test -z "$2"
then
err "ERROR: The version specified was empty"
return 1
fi
local vfile="$1"
local version="$2"
local prerelease="$3"
sed ${SED_EXT} -i "" -e "s/(Version[[:space:]]*=[[:space:]]*)\"[^\"]*\"/\1\"${version}\"/g" -e "s/(VersionPrerelease[[:space:]]*=[[:space:]]*)\"[^\"]*\"/\1\"${prerelease}\"/g" "${vfile}"
return $?
}
function set_changelog_version {
# Arguments:
# $1 - Path to top level Consul source
# $2 - Version to put into the Changelog
# $3 - Release Date
#
# Returns:
# 0 - success
# * - error
local changelog="${1}/CHANGELOG.md"
local version="$2"
local rel_date="$3"
if ! test -f "${changelog}"
then
err "ERROR: File not found: ${changelog}"
return 1
fi
if test -z "${version}"
then
err "ERROR: Must specify a version to put into the changelog"
return 1
fi
if test -z "${rel_date}"
then
rel_date=$(date +"%B %d, %Y")
fi
sed ${SED_EXT} -i "" -e "s/## UNRELEASED/## ${version} (${rel_date})/" "${changelog}"
return $?
}
function unset_changelog_version {
# Arguments:
# $1 - Path to top level Consul source
#
# Returns:
# 0 - success
# * - error
local changelog="${1}/CHANGELOG.md"
if ! test -f "${changelog}"
then
err "ERROR: File not found: ${changelog}"
return 1
fi
sed ${SED_EXT} -i "" -e "1 s/^## [0-9]+\.[0-9]+\.[0-9]+ \([^)]*\)/## UNRELEASED/" "${changelog}"
return $?
}
function add_unreleased_to_changelog {
# Arguments:
# $1 - Path to top level Consul source
#
# Returns:
# 0 - success
# * - error
local changelog="${1}/CHANGELOG.md"
if ! test -f "${changelog}"
then
err "ERROR: File not found: ${changelog}"
return 1
fi
# Check if we are already in unreleased mode
if head -n 1 "${changelog}" | grep -q -c UNRELEASED
then
return 0
fi
local tfile="$(mktemp) -t "CHANGELOG.md_")"
(
echo -e "## UNRELEASED\n" > "${tfile}" &&
cat "${changelog}" >> "${tfile}" &&
cp "${tfile}" "${changelog}"
)
local ret=$?
rm "${tfile}"
return $ret
}
function set_release_mode {
# Arguments:
# $1 - Path to top level Consul source
# $2 - The version of the release
# $3 - The release date
#
#
# Returns:
# 0 - success
# * - error
if ! test -d "$1"
then
err "ERROR: '$1' is not a directory. set_release_mode must be called with the path to a git repo as the first argument"
return 1
fi
if test -z "$2"
then
err "ERROR: The version specified was empty"
return 1
fi
local sdir="$1"
local vers="$2"
local rel_date="$(date +"%B %d, %Y")"
if test -n "$3"
then
rel_date="$3"
fi
status_stage "==> Updating CHANGELOG.md with release info: ${vers} (${rel_date})"
set_changelog_version "${sdir}" "${vers}" "${rel_date}" || return 1
status_stage "==> Updating version/version.go"
if ! update_version "${sdir}/version/version.go" "${vers}"
then
unset_changelog_version "${sdir}"
return 1
fi
return 0
}
function set_dev_mode {
# Arguments:
# $1 - Path to top level Consul source
#
# Returns:
# 0 - success
# * - error
if ! test -d "$1"
then
err "ERROR: '$1' is not a directory. set_dev_mode must be called with the path to a git repo as the first argument'"
return 1
fi
local sdir="$1"
local vers="$(parse_version "${sdir}" false false)"
status_stage "==> Setting VersionPreRelease back to 'dev'"
update_version "${sdir}/version/version.go" "${vers}" dev || return 1
status_stage "==> Adding new UNRELEASED label in CHANGELOG.md"
add_unreleased_to_changelog "${sdir}" || return 1
return 0
}

View File

@ -16,9 +16,9 @@ function refresh_docker_images {
local sdir="$1"
local targets="$2"
test -n "${targets}" || targets="images"
test -n "${targets}" || targets="docker-images"
make -C "${sdir}/build-support/docker" $targets
make -C "${sdir}" ${targets}
return $?
}
@ -164,7 +164,7 @@ function build_assetfs {
local ret=$?
if test $ret -eq 0
then
status "Copying the sources from '${sdir}/(pkg|GNUmakefile)' to /go/src/github.com/hashicorp/consul/pkg"
status "Copying the sources from '${sdir}/(pkg/web_ui|GNUmakefile)' to /go/src/github.com/hashicorp/consul/pkg"
(
tar -c pkg/web_ui GNUmakefile | docker cp - ${container_id}:/go/src/github.com/hashicorp/consul &&
status "Running build in container" && docker start -i ${container_id} &&

View File

@ -258,18 +258,30 @@ function build_consul_release {
build_consul "$1" "" "$2"
}
function build_release {
# Arguments:
# Arguments: (yeah there are lots)
# $1 - Path to the top level Consul source
# $2 - boolean whether to tag the release yet
# $3 - boolean whether to build the binaries
# $4 - boolean whether to generate the sha256 sums
# $5 - alternative gpg key to use for signing operations (optional)
# $5 - version to set within version.go and the changelog
# $6 - release date to set within the changelog
# $7 - alternative gpg key to use for signing operations (optional)
#
# Returns:
# 0 - success
# * - error
debug "Source Dir: $1"
debug "Tag Release: $2"
debug "Build Release: $3"
debug "Sign Release: $4"
debug "Version: $5"
debug "Release Date: $6"
debug "GPG Key: $7"
if ! test -d "$1"
then
err "ERROR: '$1' is not a directory. build_release must be called with the path to the top level source as the first argument'"
@ -286,26 +298,13 @@ function build_release {
local do_tag="$2"
local do_build="$3"
local do_sha256="$4"
local gpg_key="$5"
local gpg_key="$7"
if test -z "${gpg_key}"
then
gpg_key=${HASHICORP_GPG_KEY}
fi
local vers="$(get_version ${sdir} true false)"
if test $? -ne 0
then
err "Please specify a version (couldn't find one based on build tags)."
return 1
fi
if ! is_git_clean "${sdir}" true && ! is_set "${ALLOW_DIRTY_GIT}"
then
err "ERROR: Refusing to build because Git is dirty. Set ALLOW_DIRTY_GIT=1 in the environment to proceed anyways"
return 1
fi
if ! is_set "${RELEASE_UNSIGNED}"
then
if ! have_gpg_key "${gpg_key}"
@ -315,6 +314,33 @@ function build_release {
fi
fi
if ! is_git_clean "${sdir}" true && ! is_set "${ALLOW_DIRTY_GIT}"
then
err "ERROR: Refusing to build because Git is dirty. Set ALLOW_DIRTY_GIT=1 in the environment to proceed anyways"
return 1
fi
local set_vers="$5"
local set_date="$6"
if test -z "${set_vers}"
then
set_vers=$(get_version "${sdir}" false false)
fi
if ! set_release_mode "${sdir}" "${set_vers}" "${set_date}"
then
err "ERROR: Failed to put source into release mode"
return 1
fi
local vers="$(get_version ${sdir} true false)"
if test $? -ne 0
then
err "Please specify a version (couldn't find one based on build tags)."
return 1
fi
# Make sure we arent in dev mode
unset CONSUL_DEV

View File

@ -0,0 +1,141 @@
#!/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"
function usage {
cat <<-EOF
Usage: ${SCRIPT_NAME} (consul|ui|ui-legacy|static-assets) [<options ...>]
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
}
function err_usage {
err "$1"
err ""
err "$(usage)"
}
function main {
declare image=
declare sdir="${SOURCE_DIR}"
declare -i refresh=0
declare command="$1"
# get rid of the subcommand
shift
while test $# -gt 0
do
case "$1" in
-h | --help )
usage
return 0
;;
-i | --image )
if test -z "$2"
then
err_usage "ERROR: option -i/--image requires an argument"
return 1
fi
image="$2"
shift 2
;;
-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
;;
-r | --refresh )
refresh=1
shift
;;
* )
err_usage "ERROR: Unknown argument '$1'"
return 1
;;
esac
done
case "${command}" in
consul )
if is_set "${refresh}"
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}"
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}"
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
;;
ui-legacy )
if is_set "${refresh}"
then
status_stage "==> Refreshing Legacy UI build container image"
export UI_LEAGCY_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 $?

View File

@ -0,0 +1,102 @@
#!/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"
function usage {
cat <<-EOF
Usage: ${SCRIPT_NAME} (consul|ui|ui-legacy|static-assets) [<options ...>]
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
}
function err_usage {
err "$1"
err ""
err "$(usage)"
}
function main {
declare sdir="${SOURCE_DIR}"
declare build_os=""
declare 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
}
main $@
exit $?

0
build-support/scripts/functions.sh Normal file → Executable file
View File

View File

@ -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"
function usage {
cat <<-EOF
Usage: ${SCRIPT_NAME} [<options ...>]
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
}
function err_usage {
err "$1"
err ""
err "$(usage)"
}
function main {
declare sdir="${SOURCE_DIR}"
declare -i website=0
declare -i git_push=0
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
;;
-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 $?

131
build-support/scripts/release.sh Executable file
View File

@ -0,0 +1,131 @@
#!/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"
function usage {
cat <<-EOF
Usage: ${SCRIPT_NAME} [<options ...>]
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
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.
-h | --help Print this help text.
EOF
}
function err_usage {
err "$1"
err ""
err "$(usage)"
}
function ensure_arg {
if test -z "$2"
then
err_usage "ERROR: option $1 requires an argument"
return 1
fi
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_date=$(date +"%B %d, %Y")
while test $# -gt 0
do
case "$1" in
-h | --help )
usage
return 0
;;
-s | --source )
ensure_arg "-s/--source" "$2" || return 1
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
;;
-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
;;
*)
err_usage "ERROR: Unknown argument: '$1'"
return 1
;;
esac
done
build_release "${sdir}" "${do_tag}" "${do_build}" "${do_sign}" "${version}" "${release_date}" "${gpg_key}"
return $?
}
main $@
exit $?

View File

@ -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"
function usage {
cat <<-EOF
Usage: ${SCRIPT_NAME} [<options ...>]
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
}
function err_usage {
err "$1"
err ""
err "$(usage)"
}
function main {
declare sdir="${SOURCE_DIR}"
declare -i release=0
declare -i git_info=0
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
;;
-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 $?