.travis-install.sh 5.9 KB

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