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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rob Thijssen 2019-05-02 12:56:20 +00:00
Родитель 5dd6faf49b
Коммит c00716af37
2 изменённых файлов: 32 добавлений и 5 удалений

Просмотреть файл

@ -14,15 +14,30 @@ if test -z "$bucket" -a -z "$SCCACHE_DISABLE" -a -z "$MOZ_PGO"; then
# 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
@ -38,7 +53,11 @@ if test -z "$bucket" -a -z "$SCCACHE_DISABLE" -a -z "$MOZ_PGO"; then
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

Просмотреть файл

@ -66,10 +66,18 @@ EOF
# 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