2012-02-25 11:30:03 +04:00
|
|
|
#!/bin/bash
|
2018-04-09 07:42:59 +03:00
|
|
|
# shellcheck disable=SC2164
|
2012-02-25 11:30:03 +04:00
|
|
|
|
2017-05-06 02:21:12 +03:00
|
|
|
# Copyright 2017 Google Inc.
|
2018-03-22 01:28:49 +03:00
|
|
|
#
|
2017-05-06 02:21:12 +03:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2018-03-22 01:28:49 +03:00
|
|
|
#
|
2017-05-06 02:21:12 +03:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-22 01:28:49 +03:00
|
|
|
#
|
2017-05-06 02:21:12 +03:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2012-02-25 11:30:03 +04:00
|
|
|
|
2018-04-09 08:03:59 +03:00
|
|
|
|
|
|
|
# Outline of this file.
|
|
|
|
# 0. Initialization and helper methods.
|
|
|
|
# 1. Installation of dependencies.
|
|
|
|
|
2019-07-17 03:51:56 +03:00
|
|
|
BUILD_TESTS=${BUILD_TESTS:-1}
|
2019-08-13 00:53:00 +03:00
|
|
|
BUILD_PYTHON=${BUILD_PYTHON:-1}
|
2019-08-13 01:07:09 +03:00
|
|
|
BUILD_JAVA=${BUILD_JAVA:-1}
|
2018-04-09 08:03:59 +03:00
|
|
|
|
|
|
|
#
|
|
|
|
# 0. Initialization and helper methods.
|
|
|
|
#
|
|
|
|
|
2015-11-05 07:49:58 +03:00
|
|
|
function fail() {
|
|
|
|
echo "ERROR: $1"
|
|
|
|
exit 1
|
2015-11-05 06:04:49 +03:00
|
|
|
}
|
|
|
|
|
2018-04-09 08:40:58 +03:00
|
|
|
[[ "$(dirname "$0")" = "." ]] || fail "bootstrap.sh must be run from its current directory"
|
2012-02-25 11:30:03 +04:00
|
|
|
|
2018-04-09 08:40:58 +03:00
|
|
|
go version &>/dev/null || fail "Go is not installed or is not on \$PATH"
|
2018-12-24 14:07:15 +03:00
|
|
|
[[ "$(go version 2>&1)" =~ go1\.[1-9][1-9] ]] || fail "Go is not version 1.11+"
|
2015-01-28 11:04:36 +03:00
|
|
|
|
2019-08-13 00:53:00 +03:00
|
|
|
# Create main directories.
|
|
|
|
mkdir -p "$VTROOT/dist"
|
|
|
|
mkdir -p "$VTROOT/bin"
|
|
|
|
mkdir -p "$VTROOT/lib"
|
|
|
|
mkdir -p "$VTROOT/vthook"
|
|
|
|
|
2019-08-16 18:18:43 +03:00
|
|
|
# This is required for VIRTUALENV
|
|
|
|
# Used by Python below
|
|
|
|
|
2018-12-23 09:13:33 +03:00
|
|
|
if [ "$BUILD_TESTS" == 1 ] ; then
|
|
|
|
source ./dev.env
|
|
|
|
else
|
|
|
|
source ./build.env
|
|
|
|
fi
|
2016-07-14 17:43:24 +03:00
|
|
|
|
2018-12-23 09:13:33 +03:00
|
|
|
if [ "$BUILD_TESTS" == 1 ] ; then
|
|
|
|
# Set up required soft links.
|
|
|
|
# TODO(mberlin): Which of these can be deleted?
|
|
|
|
ln -snf "$VTTOP/config" "$VTROOT/config"
|
|
|
|
ln -snf "$VTTOP/data" "$VTROOT/data"
|
|
|
|
ln -snf "$VTTOP/py" "$VTROOT/py-vtdb"
|
|
|
|
ln -snf "$VTTOP/go/vt/zkctl/zksrv.sh" "$VTROOT/bin/zksrv.sh"
|
|
|
|
ln -snf "$VTTOP/test/vthook-test.sh" "$VTROOT/vthook/test.sh"
|
|
|
|
ln -snf "$VTTOP/test/vthook-test_backup_error" "$VTROOT/vthook/test_backup_error"
|
|
|
|
ln -snf "$VTTOP/test/vthook-test_backup_transform" "$VTROOT/vthook/test_backup_transform"
|
|
|
|
else
|
|
|
|
ln -snf "$VTTOP/config" "$VTROOT/config"
|
|
|
|
ln -snf "$VTTOP/data" "$VTROOT/data"
|
|
|
|
ln -snf "$VTTOP/go/vt/zkctl/zksrv.sh" "$VTROOT/bin/zksrv.sh"
|
|
|
|
fi
|
2018-04-09 07:42:59 +03:00
|
|
|
|
2019-08-17 22:21:48 +03:00
|
|
|
# git hooks are only required if someone intends to contribute.
|
|
|
|
|
|
|
|
echo "creating git hooks"
|
|
|
|
mkdir -p "$VTTOP/.git/hooks"
|
|
|
|
ln -sf "$VTTOP/misc/git/pre-commit" "$VTTOP/.git/hooks/pre-commit"
|
|
|
|
ln -sf "$VTTOP/misc/git/commit-msg" "$VTTOP/.git/hooks/commit-msg"
|
|
|
|
(cd "$VTTOP" && git config core.hooksPath "$VTTOP/.git/hooks")
|
|
|
|
|
2018-04-09 07:42:59 +03:00
|
|
|
# install_dep is a helper function to generalize the download and installation of dependencies.
|
|
|
|
#
|
|
|
|
# If the installation is successful, it puts the installed version string into
|
|
|
|
# the $dist/.installed_version file. If the version has not changed, bootstrap
|
|
|
|
# will skip future installations.
|
|
|
|
function install_dep() {
|
|
|
|
if [[ $# != 4 ]]; then
|
|
|
|
fail "install_dep function requires exactly 4 parameters (and not $#). Parameters: $*"
|
|
|
|
fi
|
|
|
|
local name="$1"
|
|
|
|
local version="$2"
|
|
|
|
local dist="$3"
|
|
|
|
local install_func="$4"
|
|
|
|
|
|
|
|
version_file="$dist/.installed_version"
|
|
|
|
if [[ -f "$version_file" && "$(cat "$version_file")" == "$version" ]]; then
|
|
|
|
echo "skipping $name install. remove $dist to force re-install."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "installing $name $version"
|
|
|
|
|
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "fail '$name build failed'; exit 1" ERR
|
|
|
|
|
|
|
|
# Cleanup any existing data and re-create the directory.
|
|
|
|
rm -rf "$dist"
|
|
|
|
mkdir -p "$dist"
|
|
|
|
|
|
|
|
# Change $CWD to $dist before calling "install_func".
|
|
|
|
pushd "$dist" >/dev/null
|
|
|
|
# -E (same as "set -o errtrace") makes sure that "install_func" inherits the
|
|
|
|
# trap. If here's an error, the trap will be called which will exit this
|
|
|
|
# script.
|
|
|
|
set -E
|
|
|
|
$install_func "$version" "$dist"
|
|
|
|
set +E
|
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
trap - ERR
|
|
|
|
|
|
|
|
echo "$version" > "$version_file"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-09 08:03:59 +03:00
|
|
|
#
|
|
|
|
# 1. Installation of dependencies.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
# Install the gRPC Python library (grpcio) and the protobuf gRPC Python plugin (grpcio-tools) from PyPI.
|
|
|
|
# Dependencies like the Python protobuf package will be installed automatically.
|
|
|
|
function install_grpc() {
|
|
|
|
local version="$1"
|
|
|
|
local dist="$2"
|
|
|
|
|
|
|
|
# Python requires a very recent version of virtualenv.
|
|
|
|
# We also require a recent version of pip, as we use it to
|
|
|
|
# upgrade the other tools.
|
|
|
|
# For instance, setuptools doesn't work with pip 6.0:
|
|
|
|
# https://github.com/pypa/setuptools/issues/945
|
|
|
|
# (and setuptools is used by grpc install).
|
|
|
|
grpc_virtualenv="$dist/usr/local"
|
|
|
|
$VIRTUALENV -v "$grpc_virtualenv"
|
|
|
|
PIP=$grpc_virtualenv/bin/pip
|
|
|
|
$PIP install --upgrade pip
|
|
|
|
$PIP install --upgrade --ignore-installed virtualenv
|
2019-07-24 01:50:46 +03:00
|
|
|
$PIP install mysql-connector-python
|
2018-04-09 08:03:59 +03:00
|
|
|
|
|
|
|
grpcio_ver=$version
|
2018-04-09 08:40:58 +03:00
|
|
|
$PIP install --upgrade grpcio=="$grpcio_ver" grpcio-tools=="$grpcio_ver"
|
2018-04-09 08:03:59 +03:00
|
|
|
}
|
|
|
|
|
2019-08-13 00:53:00 +03:00
|
|
|
if [ "$BUILD_PYTHON" == 1 ] ; then
|
2018-12-23 09:13:33 +03:00
|
|
|
install_dep "gRPC" "1.16.0" "$VTROOT/dist/grpc" install_grpc
|
|
|
|
fi
|
2018-04-09 08:03:59 +03:00
|
|
|
|
2018-06-08 06:00:15 +03:00
|
|
|
# Install protoc.
|
|
|
|
function install_protoc() {
|
|
|
|
local version="$1"
|
|
|
|
local dist="$2"
|
|
|
|
|
|
|
|
case $(uname) in
|
|
|
|
Linux) local platform=linux;;
|
|
|
|
Darwin) local platform=osx;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
wget "https://github.com/google/protobuf/releases/download/v$version/protoc-$version-$platform-x86_64.zip"
|
|
|
|
unzip "protoc-$version-$platform-x86_64.zip"
|
|
|
|
ln -snf "$dist/bin/protoc" "$VTROOT/bin/protoc"
|
|
|
|
}
|
2018-11-26 21:06:47 +03:00
|
|
|
protoc_ver=3.6.1
|
2018-06-08 06:00:15 +03:00
|
|
|
install_dep "protoc" "$protoc_ver" "$VTROOT/dist/vt-protoc-$protoc_ver" install_protoc
|
|
|
|
|
|
|
|
|
2018-04-09 07:42:59 +03:00
|
|
|
# Install Zookeeper.
|
|
|
|
function install_zookeeper() {
|
|
|
|
local version="$1"
|
|
|
|
local dist="$2"
|
|
|
|
|
|
|
|
zk="zookeeper-$version"
|
2019-04-02 17:40:53 +03:00
|
|
|
wget "https://apache.org/dist/zookeeper/$zk/$zk.tar.gz"
|
2018-04-09 07:42:59 +03:00
|
|
|
tar -xzf "$zk.tar.gz"
|
2019-03-25 19:07:29 +03:00
|
|
|
ant -f "$zk/build.xml" package
|
2019-04-02 21:54:37 +03:00
|
|
|
ant -f "$zk/zookeeper-contrib/zookeeper-contrib-fatjar/build.xml" jar
|
2018-04-09 07:42:59 +03:00
|
|
|
mkdir -p lib
|
2019-04-02 21:54:37 +03:00
|
|
|
cp "$zk/build/zookeeper-contrib/zookeeper-contrib-fatjar/zookeeper-dev-fatjar.jar" "lib/$zk-fatjar.jar"
|
2019-03-25 19:07:29 +03:00
|
|
|
zip -d "lib/$zk-fatjar.jar" 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*SF' || true # needed for >=3.4.10 <3.5
|
2018-04-09 07:42:59 +03:00
|
|
|
rm -rf "$zk" "$zk.tar.gz"
|
|
|
|
}
|
|
|
|
|
2019-08-13 01:07:09 +03:00
|
|
|
zk_ver=${ZK_VERSION:-3.4.14}
|
|
|
|
if [ "$BUILD_JAVA" == 1 ] ; then
|
|
|
|
install_dep "Zookeeper" "$zk_ver" "$VTROOT/dist/vt-zookeeper-$zk_ver" install_zookeeper
|
|
|
|
fi
|
2013-07-18 01:07:28 +04:00
|
|
|
|
New etcd 'etcd2' topology client implementation.
The new etcd2 topology service is the new more consistent version of the
etcd topology. It has the following improvements:
- Uses the same file structure as zk2topo. It then also uses the generic
vtctld.Explorer as well.
- Uses the new etcd clientv3 library, with new key-value API and leases.
It is not backwards compatible with the old etcd topology.
- Uses a configurable toplevel directory for topology data in global and
local cells.
Vitess 2.1 will still include the old etcd topology client, but it will
be deprecated, and removed from Vitess 2.2. Use topo2topo binary to
upgrade, see documentation.
Implementation details:
- bootstrap.sh now downloads etcd.
- etcd is used in unit tests of the library, instead of using a mock.
- Fixing wrangler.InitTablet error return.
And adding -allow_update to test calls, so they work anyway.
- Running tabletmanager.py for zookeeper, zk2, etcd, etcd2 flavors.
- Ignoring the 'test' tag for vendored libraries. See:
https://github.com/kardianos/govendor#ignoring-build-tags-and-excluding-packages
- in end-to-end tests, restarting etcd to wipe it.
- publish web site.
2016-12-20 03:41:26 +03:00
|
|
|
# Download and install etcd, link etcd binary into our root.
|
2018-04-09 07:42:59 +03:00
|
|
|
function install_etcd() {
|
|
|
|
local version="$1"
|
|
|
|
local dist="$2"
|
|
|
|
|
2019-02-19 03:12:00 +03:00
|
|
|
case $(uname) in
|
|
|
|
Linux) local platform=linux; local ext=tar.gz;;
|
|
|
|
Darwin) local platform=darwin; local ext=zip;;
|
|
|
|
esac
|
|
|
|
|
New etcd 'etcd2' topology client implementation.
The new etcd2 topology service is the new more consistent version of the
etcd topology. It has the following improvements:
- Uses the same file structure as zk2topo. It then also uses the generic
vtctld.Explorer as well.
- Uses the new etcd clientv3 library, with new key-value API and leases.
It is not backwards compatible with the old etcd topology.
- Uses a configurable toplevel directory for topology data in global and
local cells.
Vitess 2.1 will still include the old etcd topology client, but it will
be deprecated, and removed from Vitess 2.2. Use topo2topo binary to
upgrade, see documentation.
Implementation details:
- bootstrap.sh now downloads etcd.
- etcd is used in unit tests of the library, instead of using a mock.
- Fixing wrangler.InitTablet error return.
And adding -allow_update to test calls, so they work anyway.
- Running tabletmanager.py for zookeeper, zk2, etcd, etcd2 flavors.
- Ignoring the 'test' tag for vendored libraries. See:
https://github.com/kardianos/govendor#ignoring-build-tags-and-excluding-packages
- in end-to-end tests, restarting etcd to wipe it.
- publish web site.
2016-12-20 03:41:26 +03:00
|
|
|
download_url=https://github.com/coreos/etcd/releases/download
|
2019-02-19 03:12:00 +03:00
|
|
|
file="etcd-${version}-${platform}-amd64.${ext}"
|
2018-04-09 07:42:59 +03:00
|
|
|
|
2019-02-19 03:12:00 +03:00
|
|
|
wget "$download_url/$version/$file"
|
|
|
|
if [ "$ext" = "tar.gz" ]; then
|
|
|
|
tar xzf "$file"
|
|
|
|
else
|
|
|
|
unzip "$file"
|
|
|
|
fi
|
|
|
|
rm "$file"
|
|
|
|
ln -snf "$dist/etcd-${version}-${platform}-amd64/etcd" "$VTROOT/bin/etcd"
|
2018-04-09 07:42:59 +03:00
|
|
|
}
|
2018-11-26 21:06:47 +03:00
|
|
|
install_dep "etcd" "v3.3.10" "$VTROOT/dist/etcd" install_etcd
|
2018-04-09 07:42:59 +03:00
|
|
|
|
New etcd 'etcd2' topology client implementation.
The new etcd2 topology service is the new more consistent version of the
etcd topology. It has the following improvements:
- Uses the same file structure as zk2topo. It then also uses the generic
vtctld.Explorer as well.
- Uses the new etcd clientv3 library, with new key-value API and leases.
It is not backwards compatible with the old etcd topology.
- Uses a configurable toplevel directory for topology data in global and
local cells.
Vitess 2.1 will still include the old etcd topology client, but it will
be deprecated, and removed from Vitess 2.2. Use topo2topo binary to
upgrade, see documentation.
Implementation details:
- bootstrap.sh now downloads etcd.
- etcd is used in unit tests of the library, instead of using a mock.
- Fixing wrangler.InitTablet error return.
And adding -allow_update to test calls, so they work anyway.
- Running tabletmanager.py for zookeeper, zk2, etcd, etcd2 flavors.
- Ignoring the 'test' tag for vendored libraries. See:
https://github.com/kardianos/govendor#ignoring-build-tags-and-excluding-packages
- in end-to-end tests, restarting etcd to wipe it.
- publish web site.
2016-12-20 03:41:26 +03:00
|
|
|
|
2017-01-04 00:46:35 +03:00
|
|
|
# Download and install consul, link consul binary into our root.
|
2018-04-09 07:42:59 +03:00
|
|
|
function install_consul() {
|
|
|
|
local version="$1"
|
|
|
|
local dist="$2"
|
|
|
|
|
2019-02-19 03:12:00 +03:00
|
|
|
case $(uname) in
|
|
|
|
Linux) local platform=linux;;
|
|
|
|
Darwin) local platform=darwin;;
|
|
|
|
esac
|
|
|
|
|
2017-01-04 00:46:35 +03:00
|
|
|
download_url=https://releases.hashicorp.com/consul
|
2019-02-19 03:12:00 +03:00
|
|
|
wget "${download_url}/${version}/consul_${version}_${platform}_amd64.zip"
|
|
|
|
unzip "consul_${version}_${platform}_amd64.zip"
|
2018-04-09 07:42:59 +03:00
|
|
|
ln -snf "$dist/consul" "$VTROOT/bin/consul"
|
|
|
|
}
|
2018-11-26 21:06:47 +03:00
|
|
|
install_dep "Consul" "1.4.0" "$VTROOT/dist/consul" install_consul
|
2018-04-09 07:42:59 +03:00
|
|
|
|
2017-01-04 00:46:35 +03:00
|
|
|
|
2018-04-09 08:03:59 +03:00
|
|
|
# Install py-mock.
|
|
|
|
function install_pymock() {
|
2018-04-09 07:42:59 +03:00
|
|
|
local version="$1"
|
|
|
|
local dist="$2"
|
2016-03-02 09:02:26 +03:00
|
|
|
|
2018-04-09 08:03:59 +03:00
|
|
|
# For some reason, it seems like setuptools won't create directories even with the --prefix argument
|
|
|
|
mkdir -p lib/python2.7/site-packages
|
|
|
|
PYTHONPATH=$(prepend_path "$PYTHONPATH" "$dist/lib/python2.7/site-packages")
|
|
|
|
export PYTHONPATH
|
2018-04-08 05:41:16 +03:00
|
|
|
|
2018-04-09 08:03:59 +03:00
|
|
|
pushd "$VTTOP/third_party/py" >/dev/null
|
|
|
|
tar -xzf "mock-$version.tar.gz"
|
|
|
|
cd "mock-$version"
|
|
|
|
$PYTHON ./setup.py install --prefix="$dist"
|
|
|
|
cd ..
|
|
|
|
rm -r "mock-$version"
|
|
|
|
popd >/dev/null
|
|
|
|
}
|
|
|
|
pymock_version=1.0.1
|
2019-08-13 00:53:00 +03:00
|
|
|
if [ "$BUILD_PYTHON" == 1 ] ; then
|
2018-12-23 09:13:33 +03:00
|
|
|
install_dep "py-mock" "$pymock_version" "$VTROOT/dist/py-mock-$pymock_version" install_pymock
|
|
|
|
fi
|
2018-04-09 08:03:59 +03:00
|
|
|
|
|
|
|
# Download Selenium (necessary to run test/vtctld_web_test.py).
|
|
|
|
function install_selenium() {
|
|
|
|
local version="$1"
|
|
|
|
local dist="$2"
|
|
|
|
|
|
|
|
$VIRTUALENV "$dist"
|
|
|
|
PIP="$dist/bin/pip"
|
|
|
|
# PYTHONPATH is removed for `pip install` because otherwise it can pick up go/dist/grpc/usr/local/lib/python2.7/site-packages
|
|
|
|
# instead of go/dist/selenium/lib/python3.5/site-packages and then can't find module 'pip._vendor.requests'
|
|
|
|
PYTHONPATH='' $PIP install selenium
|
2018-04-09 07:42:59 +03:00
|
|
|
}
|
2019-08-13 00:53:00 +03:00
|
|
|
if [ "$BUILD_PYTHON" == 1 ] ; then
|
2018-12-23 09:13:33 +03:00
|
|
|
install_dep "Selenium" "latest" "$VTROOT/dist/selenium" install_selenium
|
|
|
|
fi
|
2018-04-09 08:03:59 +03:00
|
|
|
|
|
|
|
# Download chromedriver (necessary to run test/vtctld_web_test.py).
|
|
|
|
function install_chromedriver() {
|
|
|
|
local version="$1"
|
|
|
|
local dist="$2"
|
|
|
|
|
2019-02-01 11:10:01 +03:00
|
|
|
curl -sL "https://chromedriver.storage.googleapis.com/$version/chromedriver_linux64.zip" > chromedriver_linux64.zip
|
2018-04-09 08:03:59 +03:00
|
|
|
unzip -o -q chromedriver_linux64.zip -d "$dist"
|
|
|
|
rm chromedriver_linux64.zip
|
|
|
|
}
|
2019-08-13 00:53:00 +03:00
|
|
|
if [ "$BUILD_PYTHON" == 1 ] ; then
|
2019-03-05 02:35:32 +03:00
|
|
|
install_dep "chromedriver" "73.0.3683.20" "$VTROOT/dist/chromedriver" install_chromedriver
|
2018-12-23 09:13:33 +03:00
|
|
|
fi
|
2018-04-09 08:03:59 +03:00
|
|
|
|
2019-08-13 00:53:00 +03:00
|
|
|
if [ "$BUILD_PYTHON" == 1 ] ; then
|
|
|
|
PYTHONPATH='' $PIP install mysql-connector-python
|
|
|
|
fi
|
2019-08-09 08:05:45 +03:00
|
|
|
|
2019-08-13 22:46:21 +03:00
|
|
|
echo
|
2019-08-13 22:53:25 +03:00
|
|
|
echo "bootstrap finished - run 'source dev.env' or 'source build.env' in your shell before building."
|