Skip to content

Commit

Permalink
Fixing the scripts to build grpc and protobuf better.
Browse files Browse the repository at this point in the history
Docker and travis: build and install as root in /
  • Loading branch information
alainjobart committed Mar 12, 2015
1 parent 8e86c4f commit 9e3caff
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ env:
- MAKE_TARGET=unit_test
before_install:
- bash -v travis/dependencies.sh
- bash -v travis/install_protobuf.sh
- bash -v travis/install_grpc.sh
install:
- bash -v bootstrap.sh
- bash -v bootstrap.sh --skip_root_installs
script:
- source dev.env
- travis_retry make build $MAKE_TARGET
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ COPY . /vt/src/github.com/youtube/vitess
# Create vitess user
RUN groupadd -r vitess && useradd -r -g vitess vitess && \
chown -R vitess:vitess /vt
USER vitess

# Bootstrap Vitess
# Compile and install required packages as root
WORKDIR /vt/src/github.com/youtube/vitess
RUN ./travis/install_protobuf.sh
RUN ./travis/install_grpc.sh

# Bootstrap Vitess
ENV MYSQL_FLAVOR MariaDB
RUN ./bootstrap.sh
USER vitess
RUN ./bootstrap.sh --skip_root_installs

# Set up environment (equivalent to '. dev.env')
ENV VTTOP /vt/src/github.com/youtube/vitess
Expand Down
52 changes: 17 additions & 35 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# Use of this source code is governed by a BSD-style license that can
# be found in the LICENSE file.

SKIP_ROOT_INSTALLS=False
if [ "$1 " == "--skip_root_installs" ]; then
SKIP_ROOT_INSTALLS=True
fi

if [ ! -f bootstrap.sh ]; then
echo "bootstrap.sh must be run from its current directory" 1>&2
exit 1
Expand Down Expand Up @@ -49,25 +54,18 @@ fi

# install protoc and proto python libraries
protobuf_dist=$VTROOT/dist/protobuf
if [ -f $protobuf_dist/.build_finished ]; then
if [ $SKIP_ROOT_INSTALLS == "True" ]; then
echo "skipping protobuf build, as root version was already installed."
elif [ -f $protobuf_dist/.build_finished ]; then
echo "skipping protobuf build. remove $protobuf_dist to force rebuild."
else
rm -rf $protobuf_dist
# The directory doesn't exist, so it wasn't picked up by dev.env yet,
# but the install needs it to exist first, and be in PYTHONPATH.
mkdir -p $protobuf_dist/lib/python2.7/site-packages
# The directory may not have existed yet, so it may not have been
# picked up by dev.env yet, but the install needs it to exist first,
# and be in PYTHONPATH.
export PYTHONPATH=$(prepend_path $PYTHONPATH $protobuf_dist/lib/python2.7/site-packages)
(cd $protobuf_dist && \
wget https://github.com/google/protobuf/archive/v3.0.0-alpha-1.zip && \
unzip v3.0.0-alpha-1.zip && \
cd protobuf-3.0.0-alpha-1 && \
./autogen.sh && \
./configure --prefix=$protobuf_dist && \
make -j 4 && \
make install && \
cd python && \
python setup.py build --cpp_implementation && \
python setup.py install --cpp_implementation --prefix=$protobuf_dist)
./travis/install_protobuf.sh $protobuf_dist
if [ $? -ne 0 ]; then
echo "protobuf build failed"
exit 1
Expand All @@ -77,37 +75,21 @@ fi

# install gRPC C++ base, so we can install the python adapters
grpc_dist=$VTROOT/dist/grpc
if [ -f $grpc_dist/.build_finished ]; then
if [ $SKIP_ROOT_INSTALLS == "True" ]; then
echo "skipping grp build, as root version was already installed."
elif [ -f $grpc_dist/.build_finished ]; then
echo "skipping gRPC build. remove $grpc_dist to force rebuild."
else
rm -rf $grpc_dist
(mkdir -p $grpc_dist && \
cd $grpc_dist && \
git clone https://github.com/grpc/grpc.git && \
cd grpc && \
git submodule update --init && \
make && \
make install prefix=$grpc_dist && \
cd src/python/src && \
python setup.py build_ext --include-dirs $grpc_dist/include --library-dirs $grpc_dist/lib && \
python setup.py install --prefix $grpc_dist)
mkdir -p $grpc_dist
./travis/install_grpc.sh $grpc_dist
if [ $? -ne 0 ]; then
echo "gRPC build failed"
exit 1
fi
touch $grpc_dist/.build_finished
fi

# The python install lines should really be:
# (and require python-pip and python-virtualenv)
#
# ./tools/run_tests/build_python.sh && \
# pip install -r src/python/requirements.txt -t $grpc_dist/lib/python2.7/site-packages && \
# CFLAGS=-I$grpc_dist/include LDFLAGS=-L$grpc_dist/lib pip install src/python/src -t $grpc_dist/lib/python2.7/site-packages
#
# but in the Docker image, this would have to run as root,
# and we don't want to run bootstrap.sh as root.

ln -nfs $VTTOP/third_party/go/launchpad.net $VTROOT/src
go install launchpad.net/gozk/zookeeper

Expand Down
30 changes: 30 additions & 0 deletions travis/install_grpc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# This script downloads and installs the grpc library, for
# go and python, in the root of the image. It assumes we're running
# as root in the image.
set -ex

# grpc_dist can be empty, in which case we just install to the default paths
grpc_dist="$1"
if [ "$grpc_dist" != "" ]; then
cd $grpc_dist
fi

git clone https://github.com/grpc/grpc.git
cd grpc
git submodule update --init
make
if [ "$grpc_dist" != "" ]; then
make install prefix=$grpc_dist
else
make install
fi
./tools/run_tests/build_python.sh
if [ "$grpc_dist" != "" ]; then
pip install -r src/python/requirements.txt -t $grpc_dist/lib/python2.7/site-packages
CFLAGS=-I$grpc_dist/include LDFLAGS=-L$grpc_dist/lib pip install src/python/src
else
pip install -r src/python/requirements.txt
pip install src/python/src
fi
31 changes: 31 additions & 0 deletions travis/install_protobuf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# This script downloads and installs the protobuf library, for
# go and python, in the root of the image. It assumes we're running
# as root in the image.
set -ex

# protobuf_dist can be empty, in which case we just install to the default paths
protobuf_dist="$1"
if [ "$protobuf_dist" != "" ]; then
cd $protobuf_dist
fi

wget https://github.com/google/protobuf/archive/v3.0.0-alpha-1.tar.gz
tar -xvzf v3.0.0-alpha-1.tar.gz
cd protobuf-3.0.0-alpha-1
./autogen.sh
if [ "$protobuf_dist" != "" ]; then
./configure --prefix=$protobuf_dist
else
./configure
fi
make
make install
cd python
python setup.py build --cpp_implementation
if [ "$protobuf_dist" != "" ]; then
python setup.py install --cpp_implementation --prefix=$protobuf_dist
else
python setup.py install --cpp_implementation
fi

0 comments on commit 9e3caff

Please sign in to comment.