4 # Copyright (c) 2020 Project CHIP Authors
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 # run.sh - utility for running a Docker image
21 # This script expects to live in a directory named after the image
22 # with a version file next to it. So: use symlinks
24 here=$(cd "$(dirname "$0")" && pwd)
28 echo "$me: *** ERROR: $*"
32 ORG=${DOCKER_RUN_ORG:-connectedhomeip}
35 IMAGE=${DOCKER_RUN_IMAGE:-$(basename "$here")}
38 VERSION=${DOCKER_RUN_VERSION:-$(cat "$here/version")} ||
39 die "please run me from an image directory or set environment variables:
45 FULL_IMAGE_NAME="$ORG/$IMAGE${VERSION:+:${VERSION}}"
48 RUN_DIR=${DOCKER_RUN_DIR:-$(pwd)}
52 echo "Usage: $me [RUN_OPTIONS -- ] command
54 Run a command in a docker image described by $here
57 --help get this message
59 Any number of 'docker run' options can be passed
60 through to the invocation. Terminate this list of
61 options with '--' to begin command and arguments.
64 To run bash interactively:
66 note the terminating '--' for run options
68 To just tell me about the image
71 Add /tmp as an additional volume and run make
72 $ $me --volume /tmp:/tmp -- make -C src
99 ((!${#runargs[*]})) && break
107 docker pull "$FULL_IMAGE_NAME" || "$here"/build.sh
109 docker run "${runargs[@]}" --rm --mount "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" -w "$RUN_DIR" -v "$RUN_DIR:$RUN_DIR" "$FULL_IMAGE_NAME" "$@"