From 1c8c7ee7455d014214be2db36ddd906102a18704 Mon Sep 17 00:00:00 2001
From: Jan Tattermusch <jtattermusch@google.com>
Date: Wed, 9 Dec 2015 12:51:02 -0800
Subject: [PATCH] try to prevent PHP interop flake

---
 tools/jenkins/grpc_interop_php/Dockerfile       | 14 ++++++++++++++
 tools/jenkins/grpc_interop_php/build_interop.sh | 10 +---------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/tools/jenkins/grpc_interop_php/Dockerfile b/tools/jenkins/grpc_interop_php/Dockerfile
index 09da713691..492d20cdb5 100644
--- a/tools/jenkins/grpc_interop_php/Dockerfile
+++ b/tools/jenkins/grpc_interop_php/Dockerfile
@@ -100,5 +100,19 @@ RUN /bin/bash -l -c "rvm all do gem install ronn rake"
 RUN curl -sS https://getcomposer.org/installer | php
 RUN mv composer.phar /usr/local/bin/composer
 
+# Download the patched PHP protobuf so that PHP gRPC clients can be generated
+# from proto3 schemas.
+RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php
+
+RUN /bin/bash -l -c "rvm use ruby-2.1 \
+  && cd /var/local/git/protobuf-php \
+  && rvm all do rake pear:package version=1.0 \
+  && pear install Protobuf-1.0.tgz"
+
+# As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency
+# into composer cache to prevent "composer install" from cloning on each build.
+RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git \
+  /root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/
+
 # Define the default command.
 CMD ["bash"]
diff --git a/tools/jenkins/grpc_interop_php/build_interop.sh b/tools/jenkins/grpc_interop_php/build_interop.sh
index cd9d67804a..87262f1d62 100755
--- a/tools/jenkins/grpc_interop_php/build_interop.sh
+++ b/tools/jenkins/grpc_interop_php/build_interop.sh
@@ -29,7 +29,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 # Builds PHP interop server and client in a base image.
-set -e
+set -ex
 
 mkdir -p /var/local/git
 git clone --recursive /var/local/jenkins/grpc /var/local/git/grpc
@@ -45,18 +45,10 @@ make install-certs
 # gRPC core and protobuf need to be installed
 make install
 
-# Download the patched PHP protobuf so that PHP gRPC clients can be generated
-# from proto3 schemas.
-git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php
-
 (cd src/php/ext/grpc && phpize && ./configure && make)
 
 (cd third_party/protobuf && make install)
 
-(cd /var/local/git/protobuf-php \
-  && rvm all do rake pear:package version=1.0 \
-  && pear install Protobuf-1.0.tgz)
-
 (cd src/php && composer install)
 
 (cd src/php && protoc-gen-php -i tests/interop/ -o tests/interop/ tests/interop/test.proto)
-- 
GitLab