blob: b4786ab2845d4c1b953f589446508f622c647765 [file]
#!/bin/bash
# Copyright 2022 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# This script is put into the VM metadata as the startup script. It fetches the
# rest of the configuration from the repo at the specified commit.
set -xeuo pipefail
echo "Running setup script"
# Unfortunately this has to be duplicated from functions.sh because here we
# haven't fetched that file yet.
get_metadata() {
local url="http://metadata.google.internal/computeMetadata/v1/${1}"
ret=0
curl "${url}" \
--silent --fail --show-error \
--header "Metadata-Flavor: Google" || ret=$?
if [[ "${ret}" != 0 ]]; then
echo "Failed fetching ${url}" >&2
return "${ret}"
fi
}
get_attribute() {
get_metadata "instance/attributes/${1}"
}
REPO="$(get_attribute github-runner-config-repo)"
CONFIG_REF="$(get_attribute github-runner-config-ref)"
echo "Fetching from ${CONFIG_REF}"
cd /tmp/
rm -rf config
curl --silent --fail --show-error --location \
"https://github.com/${REPO}/archive/${CONFIG_REF}.tar.gz" \
| tar -zx -f - \
--strip-components=4 --wildcards \
*/build_tools/github_actions/runner/config/
chown -R runner:runner config/
# The setup script currently expects the config to be in the runner home
# directory, but we're making that configurable.
# TODO: remove this when setup script is updated
cp -r ./config /home/runner/
./config/setup.sh