-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cloud build config file for remote builder
- Loading branch information
1 parent
4cb51b4
commit 06c9ec5
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
steps: | ||
- name: gcr.io/$PROJECT_ID/remote-builder | ||
env: | ||
- GIT_CLONE_CMD=git clone --recurse-submodules https://github.com/project-chip/connectedhomeip.git; | ||
- RUN_COVERAGE_CMD=connectedhomeip/scripts/build_coverage.sh; | ||
- CLEANUP_CMD=rm -rf connectedhomeip; | ||
|
||
logsBucket: matter-build-automation-build-logs | ||
|
||
# Global timeout for all steps | ||
timeout: 21600s | ||
queueTtl: 21600s | ||
|
||
artifacts: | ||
objects: | ||
location: "gs://matter-build-automation-artifacts/$PROJECT_ID/$COMMIT_SHA/" | ||
paths: ["/coverage_html.tar.gz"] | ||
|
||
# Using higher CPU machines generally speeds up builds, except bootstrap is always | ||
# slow. | ||
options: | ||
machineType: "E2_HIGHCPU_32" | ||
diskSizeGb: 500 |
4 changes: 4 additions & 0 deletions
4
integrations/docker/images/chip-build-remote-builder/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM google/cloud-sdk | ||
|
||
COPY run.sh /bin | ||
CMD ["bash", "-xe", "/bin/run.sh"] |
24 changes: 24 additions & 0 deletions
24
integrations/docker/images/chip-build-remote-builder/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Docker gcr.io:\$PROJECT_ID:remote-builder | ||
|
||
gcr.io:\$PROJECT_ID:remote-builder is the name of the Docker image used by | ||
Matter for continuous integration and coverage statistics using Google Cloud | ||
Platform. | ||
|
||
Contents of this directory: | ||
|
||
- build.sh - utility for building (and optionally) tagging and pushing the | ||
remote-builder Docker image | ||
- cloudbuild.yaml - build config file contains instructions for Cloud Build to | ||
build, package, and push the remote-builder Docker image. | ||
- Dockerfile - description of the image | ||
|
||
In order to use remote-builder, you need to first build the builder: | ||
|
||
`./build.sh` | ||
|
||
When using the remote-builder image, the following will happen: | ||
|
||
1. A temporary SSH key will be created in your Container Builder workspace | ||
2. SSH into a virtual machine instance with your configured flags | ||
3. Your command will be run inside that compute engine instance's workspace | ||
4. The workspace will be copied back to your Container Builder workspace |
23 changes: 23 additions & 0 deletions
23
integrations/docker/images/chip-build-remote-builder/build.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Copyright (c) 2022 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# build.sh - utility for building (and optionally) tagging and pushing | ||
# the a Docker image | ||
# | ||
|
||
gcloud builds submit --config=cloudbuild.yaml . |
6 changes: 6 additions & 0 deletions
6
integrations/docker/images/chip-build-remote-builder/cloudbuild.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
steps: | ||
- name: "gcr.io/cloud-builders/docker" | ||
args: ["build", "-t", "gcr.io/$PROJECT_ID/remote-builder", "."] | ||
images: | ||
- "gcr.io/$PROJECT_ID/remote-builder" | ||
tags: ["cloud-builders-community"] |
71 changes: 71 additions & 0 deletions
71
integrations/docker/images/chip-build-remote-builder/run.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/bin/bash -xe | ||
|
||
# | ||
# Copyright (c) 2022 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# run.sh - utility for running a Docker image | ||
# | ||
# This script expects to live in a directory named after the image | ||
# with a version file next to it. So: use symlinks | ||
# | ||
USERNAME=${USERNAME:-ubuntu} | ||
PROJECT=$(gcloud info --format='value(config.project)') | ||
INSTANCE_NAME=${INSTANCE_NAME:-matter-remote-builder} | ||
ZONE=${ZONE:-us-central1-c} | ||
GCLOUD=${GCLOUD:-gcloud} | ||
RETRIES=${RETRIES:-3} | ||
SSH_ARGS=${SSH_ARGS:---project=${PROJECT} --zone="$ZONE"} | ||
|
||
# Run command on the instance via ssh | ||
function ssh() { | ||
"$GCLOUD" compute ssh "$SSH_ARGS" "$USERNAME@$INSTANCE_NAME" -- "$1" | ||
} | ||
|
||
# Always delete workspace after attempting build | ||
function cleanup() { | ||
ssh "$CLEANUP_CMD" | ||
} | ||
|
||
"$GCLOUD" config set project "$PROJECT_ID" | ||
"$GCLOUD" config set compute/zone "$ZONE" | ||
|
||
trap cleanup EXIT | ||
|
||
RETRY_COUNT=1 | ||
while [ "$(ssh 'printf pass')" != "pass" ]; do | ||
echo "[Try $RETRY_COUNT of $RETRIES] Waiting for instance to start accepting SSH connections..." | ||
if [ "$RETRY_COUNT" == "$RETRIES" ]; then | ||
echo "Retry limit reached, giving up!" | ||
exit 1 | ||
fi | ||
sleep 10 | ||
RETRY_COUNT=$(($RETRY_COUNT + 1)) | ||
done | ||
|
||
# Cleanup workspace if there is leftover | ||
ssh "$CLEANUP_CMD" | ||
|
||
# Setup workspace with connectedhomeip | ||
ssh "$GIT_CLONE_CMD" | ||
|
||
# Run coverage tests | ||
ssh "$RUN_COVERAGE_CMD" | ||
|
||
"$GCLOUD" compute scp "$SSH_ARGS" \ | ||
"/home/ubuntu/connectedhomeip/out/coverage/coverage/coverage_html.tar.gz" "$PWD" | ||
|
||
# Always delete workspace after build | ||
ssh "$CLEANUP_CMD" |