forked from rdkcentral/BartonCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerw
More file actions
executable file
·86 lines (74 loc) · 2.35 KB
/
Copy pathdockerw
File metadata and controls
executable file
·86 lines (74 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# ------------------------------ tabstop = 4 ----------------------------------
#
# If not stated otherwise in this file or this component's LICENSE file the
# following copyright and licenses apply:
#
# Copyright 2024 Comcast Cable Communications Management, LLC
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0
#
# ------------------------------ tabstop = 4 ----------------------------------
notice() {
echo "-- $0: $@"
}
set -e
if [ -f /.dockerenv ]; then
echo "ERROR: dockerw is already running inside a container."
echo "Run commands directly in the current container instead of nesting containers."
exit 1
fi
COMPOSE_INTERACTIVE_FLAGS=""
EXTRA_ENV="-e SSH_AUTH_SOCK"
DEV_VOL=""
HOST_NETWORK=""
while getopts ":ne:dH" opt; do
case ${opt} in
n) # process option n
COMPOSE_INTERACTIVE_FLAGS="--no-TTY"
;;
e) # extra environment variables
EXTRA_ENV="${EXTRA_ENV} -e ${OPTARG}"
;;
d) # add /dev volume mapping
DEV_VOL="-v /dev:/dev"
;;
H) # use host networking (useful for Matter device access)
HOST_NETWORK="--network host"
;;
esac
done
shift "$(($OPTIND - 1))"
DIR=$(pwd)
# generate the `docker/.env` file and ensure the network/image is created
$DIR/docker/setupDockerEnv.sh
COMPOSE_FILE="${DIR}/docker/compose.yaml"
EXTRA_VOLUMES="${DEV_VOL}"
VOLUMES_ARGS="-v $HOME:$HOME
$EXTRA_VOLUMES"
# create a unique container name prefixed with the user id, useful when on a shared machine
USER_ID=$(id -u -n)
RANDOM_NUMBER=$(shuf -i 100000-999999 -n 1)
CONTAINER_NAME="${USER_ID}_${RANDOM_NUMBER}"
docker compose -f "${COMPOSE_FILE}" run \
--rm \
--name ${CONTAINER_NAME} \
${COMPOSE_INTERACTIVE_FLAGS} \
${HOST_NETWORK} \
--workdir "${DIR}" \
${VOLUMES_ARGS} \
${EXTRA_ENV} \
barton \
$*