Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / integrations / docker / run.sh
1 #!/usr/bin/env bash
2
3 #
4 #    Copyright (c) 2020 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 # run.sh   - utility for running a Docker image
20 #
21 # This script expects to live in a directory named after the image
22 #  with a version file next to it.  So: use symlinks
23 #
24 here=$(cd "$(dirname "$0")" && pwd)
25 me=$(basename "$0")
26
27 die() {
28     echo "$me: *** ERROR: $*"
29     exit 1
30 }
31
32 ORG=${DOCKER_RUN_ORG:-connectedhomeip}
33
34 # directory name is
35 IMAGE=${DOCKER_RUN_IMAGE:-$(basename "$here")}
36
37 # version
38 VERSION=${DOCKER_RUN_VERSION:-$(cat "$here/version")} ||
39     die "please run me from an image directory or set environment variables:
40           DOCKER_RUN_ORG
41           DOCKER_RUN_IMAGE
42           DOCKER_RUN_VERSION"
43
44 # full image name
45 FULL_IMAGE_NAME="$ORG/$IMAGE${VERSION:+:${VERSION}}"
46
47 # where
48 RUN_DIR=${DOCKER_RUN_DIR:-$(pwd)}
49
50 help() {
51     set +x
52     echo "Usage: $me [RUN_OPTIONS -- ] command
53
54   Run a command in a docker image described by $here
55
56   Options:
57    --help        get this message
58
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.
62
63   Examples:
64     To run bash interactively:
65       $ $me -i -- bash
66      note the terminating '--' for run options
67
68     To just tell me about the image
69       $ $me uname -a
70
71     Add /tmp as an additional volume and run make
72       $ $me --volume /tmp:/tmp -- make -C src
73
74 "
75
76 }
77
78 runargs=()
79
80 # extract run options
81 for arg in "$@"; do
82     case "$arg" in
83         --help)
84             help
85             exit
86             ;;
87
88         --)
89             shift
90             break
91             ;;
92
93         -*)
94             runargs+=("$arg")
95             shift
96             ;;
97
98         *)
99             ((!${#runargs[*]})) && break
100             runargs+=("$arg")
101             shift
102             ;;
103
104     esac
105 done
106
107 docker pull "$FULL_IMAGE_NAME" || "$here"/build.sh
108
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" "$@"