.travis-install.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #!/bin/bash -e
  2. # Copyright 2017, gRPC Authors All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. #
  17. # Install dependencies that aren't available as Ubuntu packages (or already present on macOS).
  18. #
  19. # Everything goes into $HOME/local.
  20. #
  21. # Scripts should add
  22. # - $HOME/local/bin to PATH
  23. # - $HOME/local/lib to LD_LIBRARY_PATH
  24. #
  25. # To speed up the CI we cache the interop test server binaries. We cache the
  26. # binaries with the gRPC version appended to their name as a means of
  27. # invalidating the cache when we bump versions.
  28. # Update .travis.yml if this changes.
  29. BIN_CACHE="$HOME"/bin_cache
  30. ZIP_CACHE="$HOME"/zip_cache
  31. PROTOBUF_VERSION=3.9.1
  32. # We need this to build gRPC C++ for the interop test server(s).
  33. BAZEL_VERSION=0.28.1
  34. GRPC_VERSION=1.23.0
  35. GREEN='\033[0;32m'
  36. BLUE='\033[0;34m'
  37. NO_COLOR='\033[0m'
  38. info() {
  39. printf "${BLUE}$1${NO_COLOR}\n"
  40. }
  41. success() {
  42. printf "${GREEN}$1${NO_COLOR}\n"
  43. }
  44. # Install the protoc compiler.
  45. install_protoc() {
  46. echo -en 'travis_fold:start:install.protoc\\r'
  47. info "Installing protoc $PROTOBUF_VERSION"
  48. # Which protoc are we using?
  49. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  50. PROTOC_ZIP=protoc-${PROTOBUF_VERSION}-osx-x86_64.zip
  51. else
  52. PROTOC_ZIP=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
  53. fi
  54. CACHED_PROTOC_ZIP="$ZIP_CACHE/$PROTOC_ZIP"
  55. # Is it cached?
  56. if [ ! -f "$CACHED_PROTOC_ZIP" ]; then
  57. # No: download it.
  58. PROTOC_URL=https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_ZIP}
  59. info "Downloading protoc from: $PROTOC_URL"
  60. if curl -fSsL "$PROTOC_URL" -o "$CACHED_PROTOC_ZIP"; then
  61. info "Downloaded protoc from: $PROTOC_URL"
  62. else
  63. info "Downloading protoc failed, removing artifacts"
  64. rm "$CACHED_PROTOC_ZIP"
  65. exit 1
  66. fi
  67. else
  68. info "Using cached protoc"
  69. fi
  70. info "Extracting protoc from $CACHED_PROTOC_ZIP"
  71. unzip -q "$CACHED_PROTOC_ZIP" -d local
  72. success "Installed protoc $PROTOBUF_VERSION"
  73. echo -en 'travis_fold:end:install.protoc\\r'
  74. }
  75. # Install Swift.
  76. install_swift() {
  77. echo -en 'travis_fold:start:install.swift\\r'
  78. # Use the Swift provided by Xcode on macOS.
  79. if [ "$TRAVIS_OS_NAME" != "osx" ]; then
  80. info "Installing Swift $SWIFT_VERSION"
  81. if [ -z "${SWIFT_URL}" ]; then
  82. SWIFT_URL=https://swift.org/builds/swift-${SWIFT_VERSION}-release/ubuntu1804/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu18.04.tar.gz
  83. fi
  84. info "Downloading Swift from $SWIFT_URL"
  85. curl -fSsL "$SWIFT_URL" -o swift.tar.gz
  86. info "Extracting Swift from swift.tar.gz"
  87. tar -xzf swift.tar.gz --strip-components=2 --directory=local
  88. success "Installed Swift $SWIFT_VERSION"
  89. else
  90. info "Skipping Swift installation: using Swift provided by Xcode"
  91. fi
  92. echo -en 'travis_fold:end:install.swift\\r'
  93. }
  94. # We need to install bazel to so we can build the gRPC interop test server.
  95. install_bazel() {
  96. echo -en 'travis_fold:start:install.bazel\\r'
  97. info "Installing Bazel $BAZEL_VERSION"
  98. # See:
  99. # - https://docs.bazel.build/versions/master/install-os-x.html
  100. # - https://docs.bazel.build/versions/master/install-ubuntu.html
  101. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  102. BAZEL_URL=https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-darwin-x86_64.sh
  103. else
  104. BAZEL_URL=https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh
  105. fi
  106. info "Downloading Bazel from: $BAZEL_URL"
  107. curl -fSsL $BAZEL_URL -o bazel-installer.sh
  108. chmod +x bazel-installer.sh
  109. info "Running ./bazel-installer.sh"
  110. ./bazel-installer.sh --prefix="$HOME/local"
  111. success "Installed Bazel"
  112. echo -en 'travis_fold:end:install.bazel\\r'
  113. }
  114. # Build the gRPC C++ interop test server and reconnect interop test server.
  115. build_grpc_cpp_server() {
  116. echo -en 'travis_fold:start:install.grpc_cpp_server\\r'
  117. info "Building gRPC $GRPC_VERSION C++ interop servers"
  118. GRPC_INTEROP_SERVER=interop_server-"$GRPC_VERSION"
  119. GRPC_RECONNECT_INTEROP_SERVER=reconnect_interop_server-"$GRPC_VERSION"
  120. # If the servers don't exist: download and build them.
  121. if [ ! -f "$BIN_CACHE/$GRPC_INTEROP_SERVER" ] || [ ! -f "$BIN_CACHE/$GRPC_RECONNECT_INTEROP_SERVER" ]; then
  122. GRPC_URL=https://github.com/grpc/grpc/archive/v${GRPC_VERSION}.tar.gz
  123. info "Downloading gRPC from: $GRPC_URL"
  124. curl -fSsL $GRPC_URL -o grpc.tar.gz
  125. # Extract it to grpc
  126. mkdir grpc
  127. info "Extracting grpc.tar.gz to grpc"
  128. tar -xzf grpc.tar.gz --strip-components=1 --directory=grpc
  129. # Build the interop servers and put them in $BIN_CACHE
  130. (
  131. cd grpc
  132. # Only update progress every second to avoid spamming the logs.
  133. "$HOME"/local/bin/bazel build \
  134. --show_progress_rate_limit=1 \
  135. test/cpp/interop:interop_server \
  136. test/cpp/interop:reconnect_interop_server
  137. # Put them in the $BIN_CACHE
  138. info "Copying interop server to $BIN_CACHE/$GRPC_INTEROP_SERVER"
  139. cp ./bazel-bin/test/cpp/interop/interop_server "$BIN_CACHE/$GRPC_INTEROP_SERVER"
  140. info "Copying interop reconnect server to $BIN_CACHE/$GRPC_RECONNECT_INTEROP_SERVER"
  141. cp ./bazel-bin/test/cpp/interop/reconnect_interop_server "$BIN_CACHE/$GRPC_RECONNECT_INTEROP_SERVER"
  142. )
  143. else
  144. info "Skipping download and build of gRPC C++, using cached binaries"
  145. fi
  146. # We should have cached servers now, copy them to $HOME/local/bin
  147. cp "$BIN_CACHE/$GRPC_INTEROP_SERVER" "$HOME"/local/bin/interop_server
  148. cp "$BIN_CACHE/$GRPC_RECONNECT_INTEROP_SERVER" "$HOME"/local/bin/reconnect_interop_server
  149. success "Copied gRPC interop servers"
  150. echo -en 'travis_fold:end:install.grpc_cpp_server\\r'
  151. }
  152. main() {
  153. cd
  154. mkdir -p local "$BIN_CACHE"
  155. mkdir -p local "$ZIP_CACHE"
  156. install_protoc
  157. install_swift
  158. if [ "$RUN_INTEROP_TESTS" = "true" ]; then
  159. install_bazel
  160. build_grpc_cpp_server
  161. fi
  162. # Verify installation
  163. info "Contents of $HOME/local:"
  164. find local
  165. success "Install script completed"
  166. }
  167. # Run the installation.
  168. main