Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scripts] add helper script to build otbr docker for test events #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions scripts/helpers/otbr_docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/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.
#

# otbr_docker_build.sh - utility for building (and optionally) tagging and pushing
# the otbr Docker image.
#
# Example usage:
# $ ./otbr_docker_build.sh --rev 15d556e --tag TE3 --push
#

set -ex

# Default parameters
ORG=connectedhomeip
IMAGE=otbr
PLATFORMS=linux/amd64,linux/arm/v7,linux/arm64
ARGS=()

# Temporary directory used, within $DIR
OTBR_DIR=$(mktemp -d)

if [ ! -e "$OTBR_DIR" ]; then
echo "Error while creating the temporary directory" >&2
exit 1
fi

# Ensure temporary folder is removed on exit
trap 'rm -rf "$OTBR_DIR"' EXIT

usage() {
echo "Usage: $0 --rev <otbr_revision> [--org <organization> --image <image> --tag <tag> --push]" >&2
exit 0
}

while (($#)); do
case "$1" in
--path)
OTBR_PATH="$2"
shift
;;
--rev)
REVISION="$2"
shift
;;
--org)
ORG="$2"
shift
;;
--image)
IMAGE="$2"
shift
;;
--tag)
TAG="$2"
shift
;;
--push) ARGS+=("--push") ;;
--help) usage ;;
esac
shift
done

[[ -n "$REVISION" ]] || usage
[[ -n "$TAG" ]] && ARGS+=("-t" "$ORG/$IMAGE:$TAG")

VERSION=otbr-${REVISION:0:7}

# Checkout ot-br-posix to the provided revision
git -C "$OTBR_DIR" clone https://github.com/openthread/ot-br-posix.git .
git -C "$OTBR_DIR" reset --hard "$REVISION"
Damian-Nordic marked this conversation as resolved.
Show resolved Hide resolved

# Build docker image
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use --name otbr_builder --node otbr_node --driver docker-container --platform "$PLATFORMS"
docker buildx build --no-cache -t "$ORG/$IMAGE:$VERSION" -f "$OTBR_DIR/etc/docker/Dockerfile" --platform "$PLATFORMS" "${ARGS[@]}" "$OTBR_DIR"

exit 0