Artur Tynecki | 8a2bb57 | 2023-05-16 16:52:06 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # Copyright (c) 2023 Project CHIP Authors |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | HERE="$(dirname "$0")" |
| 20 | CHIP_ROOT="$(realpath "$HERE"/..)" |
| 21 | BUILD_VERSION="latest" |
| 22 | IMAGE_TAG="matter-dev-environment:local" |
| 23 | USER_UID=$UID |
| 24 | |
| 25 | function show_usage() { |
| 26 | cat <<EOF |
| 27 | Usage: $0 |
| 28 | |
| 29 | Build vscode dev environment docker image. |
| 30 | |
| 31 | Options: |
| 32 | -h,--help Show this help |
| 33 | -t,--tag Image tag - default is matter-dev-environment:local |
| 34 | -u,--uid User UIDa - default is the current user ID |
| 35 | -v,--version Build version - default is the latest |
| 36 | EOF |
| 37 | } |
| 38 | |
| 39 | SHORT=t:,u:,h:,v |
| 40 | LONG=tag:,uid:,help:,version: |
| 41 | OPTS=$(getopt -n build --options "$SHORT" --longoptions "$LONG" -- "$@") |
| 42 | |
| 43 | eval set -- "$OPTS" |
| 44 | |
| 45 | while :; do |
| 46 | case "$1" in |
| 47 | -h | --help) |
| 48 | show_usage |
| 49 | exit 0 |
| 50 | ;; |
| 51 | -t | --tag) |
| 52 | IMAGE_TAG=$2 |
| 53 | shift 2 |
| 54 | ;; |
| 55 | -u | --uid) |
| 56 | USER_UID=$2 |
| 57 | shift 2 |
| 58 | ;; |
| 59 | -v | --version) |
| 60 | BUILD_VERSION=$2 |
| 61 | shift 2 |
| 62 | ;; |
| 63 | --) |
| 64 | shift |
| 65 | break |
| 66 | ;; |
| 67 | *) |
| 68 | echo "Unexpected option: $1" |
| 69 | show_usage |
| 70 | exit 2 |
| 71 | ;; |
| 72 | esac |
| 73 | done |
| 74 | |
| 75 | if [ "$USER_UID" = "0" ]; then |
| 76 | USER_UID=1000 |
| 77 | fi |
| 78 | |
| 79 | docker build \ |
| 80 | -t "$IMAGE_TAG" \ |
| 81 | --pull \ |
| 82 | --build-arg USER_UID="$USER_UID" \ |
| 83 | --build-arg BUILD_VERSION="$BUILD_VERSION" \ |
| 84 | --network=host \ |
| 85 | "$HERE" |