Skip to content

Commit 359cf5a

Browse files
authored
feat(kokoro): Add Kokoro CI configuration from v2.13.x (#15394)
* feat(kokoro): Add Kokoro CI configuration from v2.13.x This re-introduces the Kokoro build configurations for macOS and Windows based on the previously working setup from the v2.13.x release. This is the first step in the proof-of-concept evaluation. b/438767727. * feat: update bazel version to 7.6.1 * feat(kokoro): Align Kokoro scripts with current GHA workflows * Fix: Apply formatting changes
1 parent 5afc916 commit 359cf5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2321
-19
lines changed

ci/kokoro/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1-
# Kokoro Configuration and Build script
1+
# Kokoro Configuration and Build scripts.
22

3-
As part of the software supply chain security efforts, the automation team runs
4-
a Kokoro job to capture the commit hash of each release. The script and
5-
configuration for this Kokoro job live in this directory.
3+
This directory contains the build scripts and configuration files for Kokoro,
4+
Google's internal CI system for open source projects.
5+
6+
We use Kokoro because:
7+
8+
- We can run Windows and macOS builds. Kokoro can also run Linux builds, but we
9+
use Google Cloud Build for our Linux builds.
10+
- We can store secrets, such as key files or access tokens, and run integration
11+
builds against production.
12+
13+
The documentation for Kokoro is available to Googlers only (sorry) at go/kokoro,
14+
there are extensive codelabs and detailed descriptions of the system there.
15+
16+
In brief, the Kokoro configuration is split in two:
17+
18+
1. A series of configuration files inside Google define what builds exist, and
19+
what resources these builds have access to.
20+
- These files are in a hierarchy that mirrors the ci/kokoro directory in this
21+
repo.
22+
- The `common.cfg` files are parsed first.
23+
- The `common.cfg` files are applied according to the directory hierarchy.
24+
- Finally any settings in `foobar.cfg` are applied.
25+
1. A series of configuration files in the `ci/kokoro` directory further define
26+
the build configuration:
27+
- They define the build script for each build, though they are often common.
28+
- They define which of the resources *allowed* by the internal configuration
29+
are actually *used* by that build.
30+
31+
Somewhat unique to Kokoro one must define a separate *INTEGRATION* vs.
32+
*PRESUBMIT* thus the duplication of configuration files for essentially the same
33+
settings.

ci/kokoro/lib/cache.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Make our include guard clean against set -o nounset.
18+
test -n "${CI_KOKORO_LIB_CACHE_SH__:-}" || declare -i CI_KOKORO_LIB_CACHE_SH__=0
19+
if ((CI_KOKORO_LIB_CACHE_SH__++ != 0)); then
20+
return 0
21+
fi # include guard
22+
23+
source module /ci/kokoro/lib/gcloud.sh
24+
source module /ci/lib/io.sh
25+
26+
readonly CACHE_KEYFILE="${KOKORO_GFILE_DIR:-/dev/shm}/build-results-service-account.json"
27+
28+
cache_download_enabled() {
29+
if [[ ! -f "${CACHE_KEYFILE}" ]]; then
30+
io::log "Service account for cache access is not configured."
31+
io::log "No attempt will be made to download the cache, exit with success."
32+
return 1
33+
fi
34+
35+
if [[ "${RUNNING_CI:-}" != "yes" ]]; then
36+
io::log "Cache not downloaded as this is not a CI build."
37+
return 1
38+
fi
39+
40+
return 0
41+
}
42+
43+
cache_gcloud_cleanup() {
44+
revoke_service_account_keyfile "${CACHE_KEYFILE}" || true
45+
delete_gcloud_config || true
46+
}
47+
48+
cache_download_tarball() {
49+
local -r GCS_FOLDER="$1"
50+
local -r DESTINATION="$2"
51+
local -r FILENAME="$3"
52+
53+
trap cache_gcloud_cleanup RETURN
54+
create_gcloud_config
55+
activate_service_account_keyfile "${CACHE_KEYFILE}"
56+
57+
io::log_h2 "Downloading build cache ${FILENAME} from ${GCS_FOLDER}"
58+
io::log "gcloud configuration"
59+
"${GCLOUD_BIN}" version
60+
env "CLOUDSDK_ACTIVE_CONFIG_NAME=${GCLOUD_CONFIG}" \
61+
"${GCLOUD_BIN}" --quiet storage "${CACHE_GSUTIL_DEBUG:--q}" \
62+
cp "gs://${GCS_FOLDER}/${FILENAME}" "${DESTINATION}"
63+
}
64+
65+
cache_upload_enabled() {
66+
if [[ ! -f "${CACHE_KEYFILE}" ]]; then
67+
io::log "Service account for cache access is not configured."
68+
io::log "No attempt will be made to upload the cache, exit with success."
69+
return 1
70+
fi
71+
72+
if [[ "${RUNNING_CI:-}" != "yes" || "${KOKORO_JOB_TYPE:-}" != "CONTINUOUS_INTEGRATION" ]]; then
73+
io::log "Cache not updated as this is not a CI build or it is a PR build."
74+
return 1
75+
fi
76+
return 0
77+
}
78+
79+
cache_upload_tarball() {
80+
local -r SOURCE_DIRECTORY="$1"
81+
local -r FILENAME="$2"
82+
local -r GCS_FOLDER="$3"
83+
84+
io::log_h2 "Uploading build cache ${FILENAME} to ${GCS_FOLDER}"
85+
io::log "gsutil configuration"
86+
gsutil version -l
87+
88+
trap cache_gcloud_cleanup RETURN
89+
create_gcloud_config
90+
activate_service_account_keyfile "${CACHE_KEYFILE}"
91+
env "CLOUDSDK_ACTIVE_CONFIG_NAME=${GCLOUD_CONFIG}" \
92+
"${GCLOUD_BIN}" --quiet storage "${CACHE_GSUTIL_DEBUG:--q}" \
93+
cp "${SOURCE_DIRECTORY}/${FILENAME}" "gs://${CACHE_FOLDER}/"
94+
95+
io::log "Upload completed"
96+
}

ci/kokoro/lib/gcloud.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Make our include guard clean against set -o nounset.
18+
test -n "${CI_KOKORO_LIB_GCLOUD_SH__:-}" || declare -i CI_KOKORO_LIB_GCLOUD_SH__=0
19+
if ((CI_KOKORO_LIB_GCLOUD_SH__++ != 0)); then
20+
return 0
21+
fi # include guard
22+
23+
source module /ci/lib/io.sh
24+
25+
if [[ -z "${GCLOUD_CONFIG:-}" ]]; then
26+
readonly GCLOUD_CONFIG="cloud-cpp-integration"
27+
fi
28+
29+
if [[ -z "${GCLOUD_ARGS:-}" ]]; then
30+
readonly GCLOUD_ARGS=(
31+
# Do not seek confirmation for any actions, assume the default
32+
"--quiet"
33+
34+
# Run the command using a custom configuration, this avoids affecting the
35+
# user's `default` configuration
36+
"--configuration=${GCLOUD_CONFIG}"
37+
)
38+
fi
39+
40+
GCLOUD_BIN="/usr/local/google-cloud-sdk/bin/gcloud"
41+
if [ ! -x "${GCLOUD_BIN}" ]; then
42+
# If the bin wasn't found at the above path, hope it's found in ${PATH}.
43+
GCLOUD_BIN="gcloud"
44+
fi
45+
readonly GCLOUD_BIN
46+
47+
activate_service_account_keyfile() {
48+
local -r keyfile="$1"
49+
local -r account="$(sed -n 's/.*"client_email": "\(.*\)",.*/\1/p' "${keyfile}")"
50+
"${GCLOUD_BIN}" "${GCLOUD_ARGS[@]}" auth activate-service-account \
51+
--key-file "${keyfile}" >/dev/null
52+
"${GCLOUD_BIN}" "${GCLOUD_ARGS[@]}" config set account "${account}"
53+
}
54+
55+
revoke_service_account_keyfile() {
56+
local -r keyfile="$1"
57+
local -r account="$(sed -n 's/.*"client_email": "\(.*\)",.*/\1/p' "${keyfile}")"
58+
"${GCLOUD_BIN}" "${GCLOUD_ARGS[@]}" auth revoke "${account}" >/dev/null
59+
}
60+
61+
delete_gcloud_config() {
62+
"${GCLOUD_BIN}" --quiet config configurations delete "${GCLOUD_CONFIG}"
63+
}
64+
65+
create_gcloud_config() {
66+
if ! "${GCLOUD_BIN}" --quiet config configurations \
67+
describe "${GCLOUD_CONFIG}" >/dev/null 2>&1; then
68+
io::log "Create the gcloud configuration for the cloud-cpp tests."
69+
"${GCLOUD_BIN}" --quiet --no-user-output-enabled config configurations \
70+
create --no-activate "${GCLOUD_CONFIG}" >/dev/null
71+
fi
72+
if [[ -n "${GOOGLE_CLOUD_PROJECT:-}" ]]; then
73+
# At this point, we haven't yet activated our service account, but we also
74+
# don't want this config setting to use any default account that may
75+
# already exist on the machine, so we explicitly set `--account=""` to
76+
# avoid using incidental gcloud accounts.
77+
"${GCLOUD_BIN}" "${GCLOUD_ARGS[@]}" --account="" config set project "${GOOGLE_CLOUD_PROJECT}"
78+
fi
79+
}

ci/kokoro/lib/vcpkg.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2022 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Make our include guard clean against set -o nounset.
18+
test -n "${CI_KOKORO_LIB_VCPKG_SH__:-}" || declare -i CI_KOKORO_LIB_VCPKG_SH__=0
19+
if ((CI_KOKORO_LIB_VCPKG_SH__++ != 0)); then
20+
return 0
21+
fi # include guard
22+
23+
source module /ci/lib/io.sh
24+
source module /ci/kokoro/lib/cache.sh
25+
source module /ci/kokoro/lib/gcloud.sh
26+
27+
install_vcpkg() {
28+
local -r vcpkg_dir="$1"
29+
local url
30+
31+
mkdir -p "${vcpkg_dir}"
32+
io::log "Downloading vcpkg into ${vcpkg_dir}..."
33+
VCPKG_VERSION="$(<ci/etc/vcpkg-version.txt)"
34+
url="https://github.com/microsoft/vcpkg/archive/${VCPKG_VERSION}.tar.gz"
35+
if [[ "${VCPKG_VERSION}" =~ [0-9]{4}.[0-9]{2}.[0-9]{2} ]]; then
36+
# vcpkg uses date-like tags for releases
37+
url="https://github.com/microsoft/vcpkg/archive/refs/tags/${VCPKG_VERSION}.tar.gz"
38+
fi
39+
ci/retry-command.sh 3 120 curl -fsSL "${url}" |
40+
tar -C "${vcpkg_dir}" --strip-components=1 -zxf -
41+
42+
io::log_h2 "Configure VCPKG to use GCS as a cache"
43+
readonly CACHE_BUCKET="${GOOGLE_CLOUD_CPP_KOKORO_RESULTS:-cloud-cpp-kokoro-results}"
44+
readonly CACHE_FOLDER="build-cache/google-cloud-cpp/vcpkg/macos"
45+
export VCPKG_BINARY_SOURCES="x-gcs,gs://${CACHE_BUCKET}/${CACHE_FOLDER},readwrite"
46+
export X_VCPKG_IGNORE_LOCK_FAILURES=true
47+
48+
create_gcloud_config
49+
activate_service_account_keyfile "${CACHE_KEYFILE}"
50+
export CLOUDSDK_ACTIVE_CONFIG_NAME="${GCLOUD_CONFIG}"
51+
io::run gsutil ls "gs://${CACHE_BUCKET}/"
52+
# Eventually we can remove this, but the current caches contain both `ccache`
53+
# files (which we want), and `vcpkg` files (which we don't want).
54+
io::run rm -fr "${HOME}/.cache/vcpkg"
55+
56+
ci/retry-command.sh 3 120 "${vcpkg_dir}/bootstrap-vcpkg.sh"
57+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
timeout_mins: 480

ci/kokoro/macos/bazel.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
timeout_mins: 480

0 commit comments

Comments
 (0)