Stanley Cheung | 9359522 | 2015-07-09 17:29:35 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2015, Google Inc. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | # |
Stanley Cheung | 1ad5ea5 | 2015-07-10 16:07:44 -0700 | [diff] [blame] | 31 | # This script is invoked by Jenkins and triggers a test run of |
| 32 | # linuxbrew installation of a selected language |
Stanley Cheung | 9359522 | 2015-07-09 17:29:35 -0700 | [diff] [blame] | 33 | set -ex |
| 34 | |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 35 | if [ "$platform" == "linux" ]; then |
Stanley Cheung | 9359522 | 2015-07-09 17:29:35 -0700 | [diff] [blame] | 36 | |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 37 | if [ "$dist_channel" == "homebrew" ]; then |
Stanley Cheung | 9359522 | 2015-07-09 17:29:35 -0700 | [diff] [blame] | 38 | |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 39 | sha1=$(sha1sum tools/jenkins/grpc_linuxbrew/Dockerfile | cut -f1 -d\ ) |
| 40 | DOCKER_IMAGE_NAME=grpc_linuxbrew_$sha1 |
Stanley Cheung | 1ad5ea5 | 2015-07-10 16:07:44 -0700 | [diff] [blame] | 41 | |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 42 | # build docker image, contains all pre-requisites |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 43 | docker build -t $DOCKER_IMAGE_NAME tools/jenkins/grpc_linuxbrew |
| 44 | |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 45 | if [ "$language" == "core" ]; then |
| 46 | command="curl -fsSL https://goo.gl/getgrpc | bash -" |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 47 | elif [[ "python nodejs ruby php" =~ "$language" ]]; then |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 48 | command="curl -fsSL https://goo.gl/getgrpc | bash -s $language" |
| 49 | else |
| 50 | echo "unsupported language $language" |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 54 | # run per-language homebrew installation script |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 55 | docker run $DOCKER_IMAGE_NAME bash -l \ |
| 56 | -c "nvm use 0.12; \ |
| 57 | npm set unsafe-perm true; \ |
| 58 | rvm use ruby-2.1; \ |
| 59 | $command" |
| 60 | |
| 61 | else |
| 62 | echo "Unsupported $platform dist_channel $dist_channel" |
| 63 | exit 1 |
| 64 | fi |
| 65 | |
| 66 | elif [ "$platform" == "macos" ]; then |
| 67 | |
| 68 | if [ "$dist_channel" == "homebrew" ]; then |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 69 | # system installed homebrew, don't interfere |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 70 | brew list -l |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 71 | |
| 72 | # Set up temp directories for test installation of homebrew |
| 73 | brew_root=/tmp/homebrew-test-$language |
| 74 | rm -rf $brew_root |
| 75 | mkdir -p $brew_root |
| 76 | git clone https://github.com/Homebrew/homebrew.git $brew_root |
| 77 | |
| 78 | # Install grpc via homebrew |
| 79 | # |
| 80 | # The temp $PATH env variable makes sure we are operating at the right copy of |
| 81 | # temp homebrew installation, and do not interfere with the system's main brew |
| 82 | # installation. |
| 83 | # |
| 84 | # TODO: replace the next section with the actual homebrew installation script |
| 85 | # i.e. curl -fsSL https://goo.gl/getgrpc | bash -s $language |
| 86 | # need to resolve a bunch of environment and privilege issue on the jenkins |
| 87 | # mac machine itself |
Stanley Cheung | a83cb91 | 2015-07-21 17:13:33 -0700 | [diff] [blame] | 88 | export OLD_PATH=$PATH |
| 89 | export PATH=$brew_root/bin:$PATH |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 90 | cd $brew_root |
| 91 | brew tap homebrew/dupes |
| 92 | brew install zlib |
| 93 | brew install openssl |
| 94 | brew tap grpc/grpc |
| 95 | brew install --without-python google-protobuf |
| 96 | brew install grpc |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 97 | brew list -l |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 98 | |
| 99 | # Install per-language modules/extensions on top of core grpc |
| 100 | # |
| 101 | # If a command below needs root access, the binary had been added to |
| 102 | # /etc/sudoers. This step needs to be repeated if we add more mac instances |
| 103 | # to our jenkins project. |
| 104 | # |
| 105 | # Examples (lines that needed to be added to /etc/sudoers): |
| 106 | # + Defaults env_keep += "CFLAGS CXXFLAGS LDFLAGS enable_grpc" |
| 107 | # + jenkinsnode1 ALL=(ALL) NOPASSWD: /usr/bin/pecl, /usr/local/bin/pip, |
| 108 | # + /usr/local/bin/npm |
| 109 | case $language in |
| 110 | *core*) ;; |
| 111 | *python*) |
| 112 | sudo CFLAGS=-I$brew_root/include LDFLAGS=-L$brew_root/lib pip install grpcio |
| 113 | pip list | grep grpcio |
| 114 | echo 'y' | sudo pip uninstall grpcio |
| 115 | ;; |
| 116 | *nodejs*) |
| 117 | sudo CXXFLAGS=-I$brew_root/include LDFLAGS=-L$brew_root/lib npm install grpc |
| 118 | npm list | grep grpc |
| 119 | sudo npm uninstall grpc |
| 120 | ;; |
| 121 | *ruby*) |
| 122 | gem install grpc -- --with-grpc-dir=$brew_root |
| 123 | gem list | grep grpc |
| 124 | gem uninstall grpc |
| 125 | ;; |
| 126 | *php*) |
| 127 | sudo enable_grpc=$brew_root CFLAGS="-Wno-parentheses-equality" pecl install grpc-alpha |
| 128 | pecl list | grep grpc |
| 129 | sudo pecl uninstall grpc |
| 130 | ;; |
| 131 | *) |
| 132 | echo "Unsupported language $language" |
| 133 | exit 1 |
| 134 | ;; |
| 135 | esac |
| 136 | |
| 137 | # clean up |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 138 | cd ~/ |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 139 | rm -rf $brew_root |
| 140 | |
| 141 | # Make sure the system brew installation is still unaffected |
Stanley Cheung | a83cb91 | 2015-07-21 17:13:33 -0700 | [diff] [blame] | 142 | export PATH=$OLD_PATH |
Stanley Cheung | f97b4f2 | 2015-07-20 19:28:18 -0700 | [diff] [blame] | 143 | brew list -l |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 144 | |
| 145 | else |
| 146 | echo "Unsupported $platform dist_channel $dist_channel" |
| 147 | exit 1 |
| 148 | fi |
| 149 | |
Stanley Cheung | 1ad5ea5 | 2015-07-10 16:07:44 -0700 | [diff] [blame] | 150 | else |
Stanley Cheung | 17bb3ec | 2015-07-17 15:30:59 -0700 | [diff] [blame] | 151 | echo "unsupported platform $platform" |
Stanley Cheung | 1ad5ea5 | 2015-07-10 16:07:44 -0700 | [diff] [blame] | 152 | exit 1 |
| 153 | fi |