.travis-install.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. # Only applies to Linux, we get Swift from Xcode on macOS.
  31. SWIFT_VERSION=5.0.2
  32. PROTOBUF_VERSION=3.9.1
  33. # We need this to build gRPC C++ for the interop test server(s).
  34. BAZEL_VERSION=0.28.1
  35. GRPC_VERSION=1.23.0
  36. GREEN='\033[0;32m'
  37. BLUE='\033[0;34m'
  38. NO_COLOR='\033[0m'
  39. info() {
  40. printf "${BLUE}$1${NO_COLOR}\n"
  41. }
  42. success() {
  43. printf "${GREEN}$1${NO_COLOR}\n"
  44. }
  45. # Install the protoc compiler.
  46. install_protoc() {
  47. echo -en 'travis_fold:start:install.protoc\\r'
  48. info "Installing protoc $PROTOBUF_VERSION"
  49. # Install protoc
  50. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  51. PROTOC_URL=https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-osx-x86_64.zip
  52. else
  53. PROTOC_URL=https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
  54. fi
  55. info "Downloading protoc from: $PROTOC_URL"
  56. curl -fSsL $PROTOC_URL -o protoc.zip
  57. info "Extracting protoc from protoc.zip"
  58. unzip -q protoc.zip -d local
  59. success "Installed protoc $PROTOBUF_VERSION"
  60. echo -en 'travis_fold:end:install.protoc\\r'
  61. }
  62. # Install Swift.
  63. install_swift() {
  64. echo -en 'travis_fold:start:install.swift\\r'
  65. # Use the Swift provided by Xcode on macOS.
  66. if [ "$TRAVIS_OS_NAME" != "osx" ]; then
  67. info "Installing Swift $SWIFT_VERSION"
  68. SWIFT_URL=https://swift.org/builds/swift-${SWIFT_VERSION}-release/ubuntu1804/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu18.04.tar.gz
  69. info "Downloading Swift from $SWIFT_URL"
  70. curl -fSsL $SWIFT_URL -o swift.tar.gz
  71. info "Extracting Swift from swift.tar.gz"
  72. tar -xzf swift.tar.gz --strip-components=2 --directory=local
  73. success "Installed Swift $SWIFT_VERSION"
  74. else
  75. info "Skipping Swift installation: using Swift provided by Xcode"
  76. fi
  77. echo -en 'travis_fold:end:install.swift\\r'
  78. }
  79. # We need to install bazel to so we can build the gRPC interop test server.
  80. install_bazel() {
  81. echo -en 'travis_fold:start:install.bazel\\r'
  82. info "Installing Bazel $BAZEL_VERSION"
  83. # See:
  84. # - https://docs.bazel.build/versions/master/install-os-x.html
  85. # - https://docs.bazel.build/versions/master/install-ubuntu.html
  86. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  87. BAZEL_URL=https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-darwin-x86_64.sh
  88. else
  89. BAZEL_URL=https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh
  90. fi
  91. info "Downloading Bazel from: $BAZEL_URL"
  92. curl -fSsL $BAZEL_URL -o bazel-installer.sh
  93. chmod +x bazel-installer.sh
  94. info "Running ./bazel-installer.sh"
  95. ./bazel-installer.sh --prefix="$HOME/local"
  96. success "Installed Bazel"
  97. echo -en 'travis_fold:end:install.bazel\\r'
  98. }
  99. # Build the gRPC C++ interop test server and reconnect interop test server.
  100. build_grpc_cpp_server() {
  101. echo -en 'travis_fold:start:install.grpc_cpp_server\\r'
  102. info "Building gRPC $GRPC_VERSION C++ interop servers"
  103. GRPC_INTEROP_SERVER=interop_server-"$GRPC_VERSION"
  104. GRPC_RECONNECT_INTEROP_SERVER=reconnect_interop_server-"$GRPC_VERSION"
  105. # If the servers don't exist: download and build them.
  106. if [ ! -f "$BIN_CACHE/$GRPC_INTEROP_SERVER" ] || [ ! -f "$BIN_CACHE/$GRPC_RECONNECT_INTEROP_SERVER" ]; then
  107. GRPC_URL=https://github.com/grpc/grpc/archive/v${GRPC_VERSION}.tar.gz
  108. info "Downloading gRPC from: $GRPC_URL"
  109. curl -fSsL $GRPC_URL -o grpc.tar.gz
  110. # Extract it to grpc
  111. mkdir grpc
  112. info "Extracting grpc.tar.gz to grpc"
  113. tar -xzf grpc.tar.gz --strip-components=1 --directory=grpc
  114. # Build the interop servers and put them in $BIN_CACHE
  115. (
  116. cd grpc
  117. # Only update progress every second to avoid spamming the logs.
  118. "$HOME"/local/bin/bazel build \
  119. --show_progress_rate_limit=1 \
  120. test/cpp/interop:interop_server \
  121. test/cpp/interop:reconnect_interop_server
  122. # Put them in the $BIN_CACHE
  123. info "Copying interop server to $BIN_CACHE/$GRPC_INTEROP_SERVER"
  124. cp ./bazel-bin/test/cpp/interop/interop_server "$BIN_CACHE/$GRPC_INTEROP_SERVER"
  125. info "Copying interop reconnect server to $BIN_CACHE/$GRPC_RECONNECT_INTEROP_SERVER"
  126. cp ./bazel-bin/test/cpp/interop/reconnect_interop_server "$BIN_CACHE/$GRPC_RECONNECT_INTEROP_SERVER"
  127. )
  128. else
  129. info "Skipping download and build of gRPC C++, using cached binaries"
  130. fi
  131. # We should have cached servers now, copy them to $HOME/local/bin
  132. cp "$BIN_CACHE/$GRPC_INTEROP_SERVER" "$HOME"/local/bin/interop_server
  133. cp "$BIN_CACHE/$GRPC_RECONNECT_INTEROP_SERVER" "$HOME"/local/bin/reconnect_interop_server
  134. success "Copied gRPC interop servers"
  135. echo -en 'travis_fold:end:install.grpc_cpp_server\\r'
  136. }
  137. main() {
  138. cd
  139. mkdir -p local "$BIN_CACHE"
  140. install_protoc
  141. install_swift
  142. if [ "$RUN_INTEROP_TESTS" = "true" ]; then
  143. install_bazel
  144. build_grpc_cpp_server
  145. fi
  146. # Verify installation
  147. info "Contents of $HOME/local:"
  148. find local
  149. success "Install script completed"
  150. }
  151. # Run the installation.
  152. main