Skip to content

Commit

Permalink
Moved shared init code into hack/lib/init.sh
Browse files Browse the repository at this point in the history
All of our Bash scripts made a number of initialization
steps: setting Bash flags, finding and moving into the
Origin root directory. This commit moves all of those
steps into hack/lib/init.sh in order to cut down on the
amount of boilerplate in our files.

Signed-off-by: Steve Kuznetsov <[email protected]>
  • Loading branch information
stevekuznetsov committed Aug 10, 2016
1 parent 255d523 commit 3bdd33d
Show file tree
Hide file tree
Showing 100 changed files with 231 additions and 945 deletions.
16 changes: 1 addition & 15 deletions contrib/vagrant/provision-config.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#!/bin/bash

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

# Set a useful format for xtrace output
# export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'

OS_ROOT=$(
unset CDPATH
origin_root=$(dirname "${BASH_SOURCE}")/../..
cd "${origin_root}"
pwd
)
source "${OS_ROOT}/hack/lib/init.sh"
source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"
source ${OS_ROOT}/contrib/vagrant/provision-util.sh

# Passed as arguments to provisioning script
Expand Down
12 changes: 1 addition & 11 deletions hack/build-base-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@
#
# Set OS_IMAGE_PUSH=true to push images to a registry
#

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

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install

# Go to the top of the tree.
cd "${OS_ROOT}"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

oc="$(os::build::find-binary oc ${OS_ROOT})"
if [[ -z "${oc}" ]]; then
Expand Down
9 changes: 1 addition & 8 deletions hack/build-cross.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#!/bin/bash

# Build all cross compile targets and the base binaries

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

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

platforms=( "${OS_CROSS_COMPILE_PLATFORMS[@]}" )
if [[ -n "${OS_ONLY_BUILD_PLATFORMS-}" ]]; then
Expand Down
9 changes: 1 addition & 8 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#!/bin/bash

# This script sets up a go workspace locally and builds all go components.

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

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

# only works on Linux for now, all other platforms must build binaries themselves
if [[ -z "$@" ]]; then
Expand Down
12 changes: 1 addition & 11 deletions hack/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@
# NOTE: you only need to run this script if your code changes are part of
# any images OpenShift runs internally such as origin-sti-builder, origin-docker-builder,
# origin-deployer, etc.

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

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
source "${OS_ROOT}/contrib/node/install-sdn.sh"
os::log::stacktrace::install

# Go to the top of the tree.
cd "${OS_ROOT}"

if [[ "${OS_RELEASE:-}" == "n" ]]; then
# Use local binaries
Expand Down
10 changes: 2 additions & 8 deletions hack/build-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

# This script build the sources in openshift/origin-release image using
# the Fedora environment and Go compiler.

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

function absolute_path() {
function absolute_path() {
pushd . > /dev/null
[ -d "$1" ] && cd "$1" && dirs -l +0
popd > /dev/null
}

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
origin_path="src/github.com/openshift/origin"

# TODO: Remove this check and fix the docker command instead after the
Expand Down
12 changes: 1 addition & 11 deletions hack/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@
# image to be built prior to executing this command via hack/build-base-images.sh.

# NOTE: only committed code is built.

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

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install

# Go to the top of the tree.
cd "${OS_ROOT}"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

context="${OS_ROOT}/_output/buildenv-context"

Expand Down
12 changes: 1 addition & 11 deletions hack/cherry-pick.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
#!/bin/bash

# See HACKING.md for usage

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

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install

# Go to the top of the tree.
cd "${OS_ROOT}"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

repo="${UPSTREAM_REPO:-k8s.io/kubernetes}"
package="${UPSTREAM_PACKAGE:-pkg/api}"
Expand Down
18 changes: 0 additions & 18 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@
# This script provides common script functions for the hacks
# Requires OS_ROOT to be set

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

# The root of the build/dist directory
readonly OS_ROOT=$(
unset CDPATH
os_root=$(dirname "${BASH_SOURCE}")/..
cd "${os_root}"
os_root=`pwd`
if [ -h "${os_root}" ]; then
readlink "${os_root}"
else
pwd
fi
)

readonly OS_BUILD_ENV_GOLANG="${OS_BUILD_ENV_GOLANG:-1.6}"
readonly OS_BUILD_ENV_IMAGE="${OS_BUILD_ENV_IMAGE:-openshift/origin-release:golang-${OS_BUILD_ENV_GOLANG}}"

Expand Down
9 changes: 1 addition & 8 deletions hack/copy-kube-artifacts.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
# this will allow matching files also in subdirs with **/*.json pattern
shopt -s globstar

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"

# Go to the top of the tree.
cd "${OS_ROOT}"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

GODEP_ROOT="${OS_ROOT}/vendor"
KUBE_ROOT=${1:-""}
Expand Down
12 changes: 1 addition & 11 deletions hack/env
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
# image to be built prior to executing this command via hack/build-base-images.sh.

# NOTE: only committed code is built.

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

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install

# Go to the top of the tree.
cd "${OS_ROOT}"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

os::build::environment::run "$@"
10 changes: 1 addition & 9 deletions hack/export-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
#
# $ source hack/export-certs.sh ./openshift.local.config/master/admin
# $ curl $CURL_ARGS <a protected URL>

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

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"

set -e
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

DEF="${1:-}"
CERT_DIR="${CERT_DIR:-$DEF}"
Expand Down
11 changes: 1 addition & 10 deletions hack/extract-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

# This script extracts a valid release tar into _output/releases. It requires hack/build-release.sh
# to have been executed

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

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"

# Go to the top of the tree.
cd "${OS_ROOT}"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

# Copy the release archives release back to the local _output/local/bin/... directories.
# NOTE: On Mac and Windows you must pass WARN=1 in order to extract the output.
Expand Down
9 changes: 1 addition & 8 deletions hack/gen-bootstrap-bindata.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#!/bin/bash

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

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

EXAMPLES=examples
OUTPUT_PARENT=${OUTPUT_ROOT:-$OS_ROOT}
Expand Down
10 changes: 1 addition & 9 deletions hack/gen-swagger-docs.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
#!/bin/bash

# Script to generate docs from the latest swagger spec.

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

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${OS_ROOT}"
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

pushd "${OS_ROOT}/hack/swagger-doc" > /dev/null
gradle gendocs --info
Expand Down
7 changes: 1 addition & 6 deletions hack/godep-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

#### HACK ####
# Sometimes godep just can't handle things. This lets use manually put
Expand Down Expand Up @@ -59,8 +56,6 @@ pin-godep() {
popd > /dev/null
}

OS_ROOT=$(dirname "${BASH_SOURCE}")/..

# build the godep tool
# Again go get stinks, hence || true
go get -u github.com/tools/godep 2>/dev/null || true
Expand Down
9 changes: 1 addition & 8 deletions hack/godep-save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

pin-godep() {
pushd "${GOPATH}/src/github.com/tools/godep" > /dev/null
Expand All @@ -25,8 +22,6 @@ pin-godep() {
popd > /dev/null
}

ORIGIN_ROOT=$(dirname "${BASH_SOURCE}")/..

# build the godep tool
# Again go get stinks, hence || true
go get -u github.com/tools/godep 2>/dev/null || true
Expand All @@ -43,6 +38,4 @@ REQUIRED_BINS=(
"./..."
)

pushd "${ORIGIN_ROOT}" > /dev/null
"${GODEP}" save -t "${REQUIRED_BINS[@]}"
popd > /dev/null
11 changes: 1 addition & 10 deletions hack/install-etcd.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#!/bin/bash

set -e

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

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
os::log::stacktrace::install
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

etcd_version=$(go run ${OS_ROOT}/tools/godepversion/godepversion.go ${OS_ROOT}/Godeps/Godeps.json github.com/coreos/etcd/etcdserver)

Expand Down
6 changes: 1 addition & 5 deletions hack/install-tools.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash

set -e

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

GO_VERSION=($(go version))
echo "Detected go version: $(go version)"
Expand Down
Loading

0 comments on commit 3bdd33d

Please sign in to comment.