otbr_docker_build.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2021 Project CHIP Authors
  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. # http://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. # otbr_docker_build.sh - utility for building (and optionally) tagging and pushing
  18. # the otbr Docker image.
  19. #
  20. # Example usage:
  21. # $ ./otbr_docker_build.sh --rev 15d556e --tag TE3 --push
  22. #
  23. set -ex
  24. # Default parameters
  25. ORG=connectedhomeip
  26. IMAGE=otbr
  27. PLATFORMS=linux/amd64,linux/arm/v7,linux/arm64
  28. ARGS=()
  29. # Temporary directory used, within $DIR
  30. OTBR_DIR=$(mktemp -d)
  31. if [ ! -e "$OTBR_DIR" ]; then
  32. echo "Error while creating the temporary directory" >&2
  33. exit 1
  34. fi
  35. # Ensure temporary folder is removed on exit
  36. trap 'rm -rf "$OTBR_DIR"' EXIT
  37. usage() {
  38. echo "Usage: $0 --rev <otbr_revision> [--org <organization> --image <image> --tag <tag> --push]" >&2
  39. exit 0
  40. }
  41. while (($#)); do
  42. case "$1" in
  43. --path)
  44. OTBR_PATH="$2"
  45. shift
  46. ;;
  47. --rev)
  48. REVISION="$2"
  49. shift
  50. ;;
  51. --org)
  52. ORG="$2"
  53. shift
  54. ;;
  55. --image)
  56. IMAGE="$2"
  57. shift
  58. ;;
  59. --tag)
  60. TAG="$2"
  61. shift
  62. ;;
  63. --push) ARGS+=("--push") ;;
  64. --help) usage ;;
  65. esac
  66. shift
  67. done
  68. [[ -n "$REVISION" ]] || usage
  69. [[ -n "$TAG" ]] && ARGS+=("-t" "$ORG/$IMAGE:$TAG")
  70. VERSION=otbr-${REVISION:0:7}
  71. # Checkout ot-br-posix to the provided revision
  72. git -C "$OTBR_DIR" clone https://github.com/openthread/ot-br-posix.git .
  73. git -C "$OTBR_DIR" reset --hard "$REVISION"
  74. # Build docker image
  75. docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  76. docker buildx create --use --name otbr_builder --node otbr_node --driver docker-container --platform "$PLATFORMS"
  77. docker buildx build --no-cache -t "$ORG/$IMAGE:$VERSION" -f "$OTBR_DIR/etc/docker/Dockerfile" --platform "$PLATFORMS" "${ARGS[@]}" "$OTBR_DIR"
  78. exit 0