blob: eea25b62e6e21da264990062dd24c923c44182d9 [file] [log] [blame]
Stanley Cheung93595222015-07-09 17:29:35 -07001#!/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 Cheung1ad5ea52015-07-10 16:07:44 -070031# This script is invoked by Jenkins and triggers a test run of
32# linuxbrew installation of a selected language
Stanley Cheung93595222015-07-09 17:29:35 -070033set -ex
34
Stanley Cheung17bb3ec2015-07-17 15:30:59 -070035if [ "$platform" == "linux" ]; then
Stanley Cheung93595222015-07-09 17:29:35 -070036
Stanley Cheung17bb3ec2015-07-17 15:30:59 -070037 if [ "$dist_channel" == "homebrew" ]; then
Stanley Cheung93595222015-07-09 17:29:35 -070038
Stanley Cheung17bb3ec2015-07-17 15:30:59 -070039 sha1=$(sha1sum tools/jenkins/grpc_linuxbrew/Dockerfile | cut -f1 -d\ )
40 DOCKER_IMAGE_NAME=grpc_linuxbrew_$sha1
Stanley Cheung1ad5ea52015-07-10 16:07:44 -070041
Stanley Cheungf97b4f22015-07-20 19:28:18 -070042 # build docker image, contains all pre-requisites
Stanley Cheung17bb3ec2015-07-17 15:30:59 -070043 docker build -t $DOCKER_IMAGE_NAME tools/jenkins/grpc_linuxbrew
44
Stanley Cheung17bb3ec2015-07-17 15:30:59 -070045 if [ "$language" == "core" ]; then
46 command="curl -fsSL https://goo.gl/getgrpc | bash -"
Stanley Cheungf97b4f22015-07-20 19:28:18 -070047 elif [[ "python nodejs ruby php" =~ "$language" ]]; then
Stanley Cheung17bb3ec2015-07-17 15:30:59 -070048 command="curl -fsSL https://goo.gl/getgrpc | bash -s $language"
49 else
50 echo "unsupported language $language"
51 exit 1
52 fi
53
Stanley Cheungf97b4f22015-07-20 19:28:18 -070054 # run per-language homebrew installation script
Stanley Cheung17bb3ec2015-07-17 15:30:59 -070055 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
66elif [ "$platform" == "macos" ]; then
67
68 if [ "$dist_channel" == "homebrew" ]; then
Stanley Cheungf97b4f22015-07-20 19:28:18 -070069 # system installed homebrew, don't interfere
Stanley Cheung17bb3ec2015-07-17 15:30:59 -070070 brew list -l
Stanley Cheungf97b4f22015-07-20 19:28:18 -070071
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 Cheunga83cb912015-07-21 17:13:33 -070088 export OLD_PATH=$PATH
89 export PATH=$brew_root/bin:$PATH
Stanley Cheungf97b4f22015-07-20 19:28:18 -070090 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 Cheung17bb3ec2015-07-17 15:30:59 -070097 brew list -l
Stanley Cheungf97b4f22015-07-20 19:28:18 -070098
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 Cheung17bb3ec2015-07-17 15:30:59 -0700138 cd ~/
Stanley Cheungf97b4f22015-07-20 19:28:18 -0700139 rm -rf $brew_root
140
141 # Make sure the system brew installation is still unaffected
Stanley Cheunga83cb912015-07-21 17:13:33 -0700142 export PATH=$OLD_PATH
Stanley Cheungf97b4f22015-07-20 19:28:18 -0700143 brew list -l
Stanley Cheung17bb3ec2015-07-17 15:30:59 -0700144
145 else
146 echo "Unsupported $platform dist_channel $dist_channel"
147 exit 1
148 fi
149
Stanley Cheung1ad5ea52015-07-10 16:07:44 -0700150else
Stanley Cheung17bb3ec2015-07-17 15:30:59 -0700151 echo "unsupported platform $platform"
Stanley Cheung1ad5ea52015-07-10 16:07:44 -0700152 exit 1
153fi