Bug 1543026 - enable sccache on gcp r=wcosta
authorRob Thijssen <rthijssen@mozilla.com>
Thu, 02 May 2019 12:56:20 +0000
changeset 531094 5b08dd3eeec974c6ae229134906fc79dec7ef2ba
parent 531093 f526b92a7a4aa76faa3a14494c86ddddac994ab0
child 531095 7b505a8a1ad94c2e83dcbb7b505c4a16d6b21fff
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswcosta
bugs1543026
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543026 - enable sccache on gcp r=wcosta this change comprises the in-tree changes required to make use of sccache in gcp. specifically: - a gcp metadata lookup for availability-zone is added to mozconfig, enabling a build to determine its regional gcp sccache bucket - the sccache cargo build command is modified to include the gcs feature when the environment contains gcs configuration note that further changes are required on infra to support sccache use. the required changes already [exist](https://github.com/mozilla-releng/OpenCloudConfig/commit/1d515dc) and are enabled for gcp windows infra, including: - a json credential file on the build instance filesystem, containing credentials valid for the appropriate scm level bucket for the gcp region - an `SCCACHE_GCS_KEY_PATH` env variable containing the path to the json credential file - an `SCCACHE_GCS_RW_MODE` env variable containg the text `READ_WRITE` - sccache buckets must exist for each region and scm levels 1 & 3 - credentials for scm level 1 buckets **must not** be valid for scm level 3 buckets on gcp systems which do not contain credential files and the above mentioned env variables (eg gecko-[1-3]-b-linux), sccache should fail gracefully without breaking builds. Differential Revision: https://phabricator.services.mozilla.com/D29622
build/mozconfig.cache
taskcluster/scripts/misc/build-sccache.sh
--- a/build/mozconfig.cache
+++ b/build/mozconfig.cache
@@ -9,37 +9,56 @@ if test -z "$bucket" -a -z "$SCCACHE_DIS
 
     # prevent rerun if az is set, or wget is not available
     if test -z "$availability_zone" -a -x "$(command -v wget)"; then
         if test -n "${TASKCLUSTER_WORKER_GROUP}"; then
             # TASKCLUSTER_WORKER_GROUP is just the region now, so
             # stick an extra character on to make the already-convoluted logic
             # here simpler.
             availability_zone="${TASKCLUSTER_WORKER_GROUP}x"
+        elif [ -n "${SCCACHE_GCS_KEY_PATH}" ]; then
+            # gcp availability_zone is of the form <region>-<letter> where region is e.g. us-west2, and az is us-west2-a
+            gcp_zone=$(wget -T 1 -t 1 -q -O - http://169.254.169.254/computeMetadata/v1beta1/instance/zone || true)
+            availability_zone=${gcp_zone##*/}
         else
             # timeout after 1 second, and don't retry (failure indicates instance is not in ec2 or network issue)
-            # availability_zone is of the form <region><letter> where region is e.g. us-west-2, and az is us-west-2a
+            # ec2 availability_zone is of the form <region><letter> where region is e.g. us-west-2, and az is us-west-2a
             availability_zone=$(wget -T 1 -t 1 -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone || true)
         fi
         if test -z "$availability_zone" -o "$availability_zone" = "not-ec2"; then
             availability_zone=not-ec2
+        elif [ -n "${SCCACHE_GCS_KEY_PATH}" ]; then
+            # gcp region is az with last two letters trimmed
+            region=${availability_zone::${#availability_zone}-2}
+            case "${GECKO_HEAD_REPOSITORY}" in
+            *hg.mozilla.org/try*)
+                bucket=taskcluster-level-1-sccache-${region}
+                ;;
+            *hg.mozilla.org/integration/autoland*|*hg.mozilla.org/integration/mozilla-inbound*)
+                bucket=taskcluster-level-3-sccache-${region}
+                ;;
+            esac
         else
-            # region is az with last letter trimmed
+            # ec2 region is az with last letter trimmed
             region=${availability_zone%?}
             # set S3 bucket according to tree (level)
             case "${GECKO_HEAD_REPOSITORY}" in
             *hg.mozilla.org/try*)
                 bucket=taskcluster-level-1-sccache-${region}
                 ;;
             *hg.mozilla.org/integration/autoland*|*hg.mozilla.org/integration/mozilla-inbound*)
                 bucket=taskcluster-level-3-sccache-${region}
                 ;;
             esac
         fi
     fi
 fi
 
 if test -n "$bucket"; then
-    mk_add_options "export SCCACHE_BUCKET=$bucket"
+    if [ -n "${SCCACHE_GCS_KEY_PATH}" ]; then
+        mk_add_options "export SCCACHE_GCS_BUCKET=$bucket"
+    else
+        mk_add_options "export SCCACHE_BUCKET=$bucket"
+    fi
     export CCACHE="$topsrcdir/sccache2/sccache"
     export SCCACHE_VERBOSE_STATS=1
     mk_add_options MOZBUILD_MANAGE_SCCACHE_DAEMON=${topsrcdir}/sccache2/sccache
 fi
--- a/taskcluster/scripts/misc/build-sccache.sh
+++ b/taskcluster/scripts/misc/build-sccache.sh
@@ -61,20 +61,28 @@ EOF
     make -j `nproc --all`
     # `make install` installs a *ton* of docs that we don't care about.
     # Just the software, please.
     make install_sw
     popd
 
     # We don't need to set OPENSSL_STATIC here, because we only have static
     # libraries in the directory we are passing.
-    env "OPENSSL_DIR=$OPENSSL_BUILD_DIRECTORY" cargo build --features "all dist-server" --verbose --release
+    if [ -n "${SCCACHE_GCS_KEY_PATH}" ]; then
+        env "OPENSSL_DIR=$OPENSSL_BUILD_DIRECTORY" cargo build --features "all dist-server gcs" --verbose --release
+    else
+        env "OPENSSL_DIR=$OPENSSL_BUILD_DIRECTORY" cargo build --features "all dist-server" --verbose --release
+    fi
     ;;
 MINGW*)
-    cargo build --verbose --release
+    if [ -n "${SCCACHE_GCS_KEY_PATH}" ]; then
+        cargo build --verbose --release --features=gcs
+    else
+        cargo build --verbose --release
+    fi
     ;;
 esac
 
 mkdir sccache2
 cp target/release/sccache* sccache2/
 tar -acf sccache2.tar.$COMPRESS_EXT sccache2
 mkdir -p $UPLOAD_DIR
 cp sccache2.tar.$COMPRESS_EXT $UPLOAD_DIR