blob: 761d911ef4467e866d91ad5d84e2bdbfe205ef3b [file] [log] [blame]
Artur Tynecki8a2bb572023-05-16 16:52:06 +02001#!/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
19HERE="$(dirname "$0")"
20CHIP_ROOT="$(realpath "$HERE"/..)"
21BUILD_VERSION="latest"
22IMAGE_TAG="matter-dev-environment:local"
23USER_UID=$UID
24
25function show_usage() {
26 cat <<EOF
27Usage: $0
28
29Build vscode dev environment docker image.
30
31Options:
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
36EOF
37}
38
39SHORT=t:,u:,h:,v
40LONG=tag:,uid:,help:,version:
41OPTS=$(getopt -n build --options "$SHORT" --longoptions "$LONG" -- "$@")
42
43eval set -- "$OPTS"
44
45while :; 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
73done
74
75if [ "$USER_UID" = "0" ]; then
76 USER_UID=1000
77fi
78
79docker 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"