From 22494008ae1f7d55a1a1b2437b260e334701af03 Mon Sep 17 00:00:00 2001 From: FernandoLGuzman <31297194+FernandoLGuzman@users.noreply.github.com> Date: Fri, 14 Oct 2022 07:16:37 -0700 Subject: [PATCH] Add docker step to chef cloud build (#22885) * Add chef dockerfile * Add script for building chef docker images * Add chef dockerization cloud step * Restyled by whitespace * Restyled by prettier-yaml * Restyled by shellharden * Remove hardcoded values from docker script * Restyled by prettier-yaml * Restyled by shellharden Co-authored-by: Restyled.io --- examples/chef/create_docker.sh | 31 +++++++++++++++++++++++++++++++ examples/chef/dockerfile | 18 ++++++++++++++++++ integrations/cloudbuild/chef.yaml | 16 ++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100755 examples/chef/create_docker.sh create mode 100644 examples/chef/dockerfile diff --git a/examples/chef/create_docker.sh b/examples/chef/create_docker.sh new file mode 100755 index 00000000000000..f38da15015017d --- /dev/null +++ b/examples/chef/create_docker.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 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. +# + +set -e # Exit on any script error. + +OUT_DIRECTORY="$WORKING_DIR/out/" + +# Clean up the out directory before extracting device files +rm -r "$OUT_DIRECTORY"* + +# Extract device files +tar -xf "$TAR_PATH" -C "$OUT_DIRECTORY" + +# Build the docker image +docker build -f "$WORKING_DIR"/dockerfile -t "$IMAGE_NAME":latest -t "$IMAGE_NAME:short-sha_$SHORT_SHA" \ + -t "$IMAGE_NAME:build-id_$BUILD_ID" -t "$IMAGE_NAME:commit-sha_$COMMIT_SHA" -t "$IMAGE_NAME:revision-id_$REVISION_ID" \ + --build-arg DEVICE_NAME="$DEVICE_NAME" . diff --git a/examples/chef/dockerfile b/examples/chef/dockerfile new file mode 100644 index 00000000000000..0b0b3204c46db4 --- /dev/null +++ b/examples/chef/dockerfile @@ -0,0 +1,18 @@ +FROM debian:bullseye + +ARG DEVICE_NAME + +RUN apt-get update && \ + apt-get install -y \ + libglib2.0-0 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +COPY examples/chef/out/${DEVICE_NAME} /chef_device +COPY examples/chef/out/${DEVICE_NAME}.map /chef_device.map +COPY examples/chef/out/${DEVICE_NAME}.matter /chef_device.matter +COPY examples/chef/out/${DEVICE_NAME}_hashmeta.yaml /chef_device_hashmeta.yaml + +ENV DBUS_SYSTEM_BUS_ADDRESS="unix:path=/var/run/dbus/system_bus_socket" + +CMD ["/chef_device"] diff --git a/integrations/cloudbuild/chef.yaml b/integrations/cloudbuild/chef.yaml index ecbb7842aec8fe..b8deb6461f19a1 100644 --- a/integrations/cloudbuild/chef.yaml +++ b/integrations/cloudbuild/chef.yaml @@ -40,6 +40,20 @@ steps: - name: pwenv path: /pwenv + - name: "gcr.io/cloud-builders/docker" + args: + - "-c" + - COMMIT_SHA=$COMMIT_SHA SHORT_SHA=$SHORT_SHA REVISION_ID=$REVISION_ID + BUILD_ID=$BUILD_ID IMAGE_NAME=$_DOCKER_IMAGE_NAME + DEVICE_NAME=$_DOCKER_DEVICE_NAME + WORKING_DIR=/workspace/examples/chef + TAR_PATH=/workspace/artifacts/linux_x86-$_DOCKER_DEVICE_NAME.tar.gz + ./examples/chef/create_docker.sh + id: DockerAll + entrypoint: /usr/bin/bash + waitFor: + - CompileNoip + logsBucket: matter-build-automation-build-logs # Global timeout for all steps @@ -50,6 +64,8 @@ artifacts: objects: location: "gs://matter-build-automation-artifacts/$PROJECT_ID/$COMMIT_SHA/" paths: ["/workspace/artifacts/*.tar.gz"] +images: + - $_DOCKER_IMAGE_NAME # Using higher CPU machines generally speeds up builds, except bootstrap is always # slow. options: