|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# This script will build a Docker image for googleapis and recompile |
| 4 | +# PHP and Ruby runtimes binaries to use in GAPIC generators for these |
| 5 | +# languages. |
| 6 | +# |
| 7 | +# Run from any local working directory where you have write access. |
| 8 | +# |
| 9 | +# Usage: |
| 10 | +# $ mkdir workdir |
| 11 | +# $ cd workdir |
| 12 | +# $ sh /google/src/head/depot/google3/third_party/googleapis/stable/.kokoro/docker_update.sh |
| 13 | +# |
| 14 | +# After the script completes, it should print out commands to push the new |
| 15 | +# Docker image and to create pull requests against Ruby and PHP generators. |
| 16 | +# Whenever the image is published, tag it here: |
| 17 | +# https://pantheon.corp.google.com/gcr/images/gapic-images/global/googleapis?project=gapic-images |
| 18 | +# then release new versions of the generators and update the image tag in |
| 19 | +# start.sh scripts in Kokoro folders in all googleapis workspaces. |
| 20 | + |
| 21 | +set -e |
| 22 | + |
| 23 | +PWD="`pwd`" |
| 24 | +SHARED="$PWD/volume" |
| 25 | + |
| 26 | +if test -d "$SHARED"; then |
| 27 | + echo "The working directory $SHARED already exists, please delete it first." |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | +mkdir -p "$SHARED" |
| 31 | + |
| 32 | +# 1. Build the latest Docker image using the Dockerfile from google3 |
| 33 | +cat /google/src/head/depot/google3/third_party/googleapis/stable/.kokoro/Dockerfile > "$PWD/Dockerfile" |
| 34 | + |
| 35 | +echo "Building googleapis Docker image..." |
| 36 | +docker build -t googleapis . |
| 37 | +docker tag googleapis gcr.io/gapic-images/googleapis |
| 38 | +echo "Done." |
| 39 | + |
| 40 | +# 2. Clone Ruby and PHP generators |
| 41 | +cd "$SHARED" |
| 42 | +echo "Cloning Ruby generator..." |
| 43 | +git clone --depth 1 [email protected]:googleapis/gapic-generator-ruby.git |
| 44 | +echo "Done." |
| 45 | +echo "Cloning PHP generator..." |
| 46 | +git clone --depth 1 [email protected]:googleapis/gapic-generator-php.git |
| 47 | +echo "Done." |
| 48 | + |
| 49 | +# 3. Generate a script that would run Bazel to build both generators |
| 50 | +cat > build.sh <<EOD |
| 51 | +#!/bin/sh |
| 52 | +set -e |
| 53 | +export USER="$USER" |
| 54 | +export HOME=/volume |
| 55 | +cd /volume |
| 56 | +cd gapic-generator-ruby |
| 57 | +bazel build //rules_ruby_gapic/gapic-generator:gapic_generator_bundled_context |
| 58 | +cd /volume |
| 59 | +cd gapic-generator-php |
| 60 | +bazel build //rules_php_gapic:php_gapic_generator_binary |
| 61 | +cd .. |
| 62 | +EOD |
| 63 | +chmod +x build.sh |
| 64 | + |
| 65 | +# 4. Execute the script inside Docker image |
| 66 | +echo "Building generators inside Docker..." |
| 67 | +# Note: without --privileged, the container has problems accessing the filesystem. |
| 68 | +# We don't care much about it at this moment. Discussed here: |
| 69 | +# https://forums.docker.com/t/what-capabilities-are-required-for-ls/92223 |
| 70 | +DOCKER_COMMAND="docker run --privileged --user=$UID --workdir=/volume -i --rm -v $SHARED:/volume" |
| 71 | +$DOCKER_COMMAND --entrypoint /volume/build.sh googleapis |
| 72 | +echo "Done." |
| 73 | + |
| 74 | +# Fix permissions of the mounted folder |
| 75 | +chmod -R u+w "$SHARED" |
| 76 | + |
| 77 | +# 5. Pack the resulting Ruby and PHP binaries |
| 78 | +RUBY_DIRECTORY=`ls -d .cache/bazel/*/*/external/gapic_generator_ruby_runtime` |
| 79 | +RUBY_VERSION=`echo 'puts RUBY_VERSION' | $DOCKER_COMMAND --entrypoint "" googleapis /volume/$RUBY_DIRECTORY/bin/ruby` |
| 80 | + |
| 81 | +echo "Ruby version: $RUBY_VERSION, packing..." |
| 82 | +RUBY_ARCHIVE_DIR="ruby-$RUBY_VERSION" |
| 83 | +RUBY_TARBALL_FILENAME="ruby-${RUBY_VERSION}_glinux_x86_64.tar.gz" |
| 84 | +mkdir -p "$RUBY_ARCHIVE_DIR" |
| 85 | +cp -r "$RUBY_DIRECTORY"/bin "$RUBY_DIRECTORY"/include "$RUBY_DIRECTORY"/lib "$RUBY_ARCHIVE_DIR" |
| 86 | +tar cfz "$RUBY_TARBALL_FILENAME" "$RUBY_ARCHIVE_DIR" |
| 87 | +echo "Done: $RUBY_TARBALL_FILENAME" |
| 88 | + |
| 89 | +PHP_DIRECTORY=`ls -d .cache/bazel/*/*/external/php_micro` |
| 90 | +PHP_VERSION=`echo '<? echo phpversion(); ?>' | $DOCKER_COMMAND --entrypoint "" googleapis /volume/$PHP_DIRECTORY/bin/php` |
| 91 | + |
| 92 | +echo "PHP version: $PHP_VERSION, packing..." |
| 93 | +PHP_ARCHIVE_DIR="php-$PHP_VERSION" |
| 94 | +PHP_TARBALL_FILENAME="php-${PHP_VERSION}_linux_x86_64.tar.gz" |
| 95 | +mkdir -p "$PHP_ARCHIVE_DIR" |
| 96 | +cp -r "$PHP_DIRECTORY"/bin "$PHP_DIRECTORY"/include "$PHP_DIRECTORY"/lib "$PHP_ARCHIVE_DIR" |
| 97 | +tar cfz "$PHP_TARBALL_FILENAME" "$PHP_ARCHIVE_DIR" |
| 98 | +echo "Done: $PHP_TARBALL_FILENAME" |
| 99 | + |
| 100 | +# 6. Commit the tarballs |
| 101 | +BRANCH="update-binary-`date +%Y%m%dT%H%M%S`" |
| 102 | + |
| 103 | +RUBY_TARBALL_LOCATION=rules_ruby_gapic/prebuilt |
| 104 | +cd "$SHARED/gapic-generator-ruby" |
| 105 | +git checkout -b "$BRANCH" |
| 106 | +git rm -f "$RUBY_TARBALL_LOCATION"/*.tar.gz |
| 107 | +cp "$SHARED/$RUBY_TARBALL_FILENAME" "$RUBY_TARBALL_LOCATION/" |
| 108 | +git add "$RUBY_TARBALL_LOCATION/$RUBY_TARBALL_FILENAME" |
| 109 | +git commit -m "fix: update Ruby prebuilt binary, version $RUBY_VERSION" |
| 110 | +echo "Pushing Ruby branch to GitHub..." |
| 111 | +git push --set-upstream origin "$BRANCH" |
| 112 | +echo "Done" |
| 113 | + |
| 114 | +PHP_TARBALL_LOCATION=rules_php_gapic/resources |
| 115 | +cd "$SHARED/gapic-generator-php" |
| 116 | +git checkout -b "$BRANCH" |
| 117 | +git rm -f "$PHP_TARBALL_LOCATION"/*.tar.gz |
| 118 | +cp "$SHARED/$PHP_TARBALL_FILENAME" "$PHP_TARBALL_LOCATION/" |
| 119 | +git add "$PHP_TARBALL_LOCATION/$PHP_TARBALL_FILENAME" |
| 120 | +git commit -m "fix: update PHP prebuilt binary, version $PHP_VERSION" |
| 121 | +echo "Pushing PHP branch to GitHub..." |
| 122 | +git push --set-upstream origin "$BRANCH" |
| 123 | +echo "Done" |
| 124 | + |
| 125 | +echo |
| 126 | +echo "Please create pull requests:" |
| 127 | +echo " https://github.com/googleapis/gapic-generator-ruby/pull/new/$BRANCH" |
| 128 | +echo " https://github.com/googleapis/gapic-generator-php/pull/new/$BRANCH" |
| 129 | +echo "and push this Docker image to gcr.io:" |
| 130 | +echo " docker push gcr.io/gapic-images/googleapis" |
0 commit comments