Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 59 additions & 6 deletions integrations/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,81 @@
here=$(cd "$(dirname "$0")" && pwd)
me=$(basename "$0")

die() {
echo "$me: *** ERROR: $*"
exit 1
}

ORG=${DOCKER_RUN_ORG:-connectedhomeip}

# directory name is
IMAGE=${DOCKER_RUN_IMAGE:-$(basename "$here")}

# version
VERSION=${DOCKER_RUN_VERSION:-$(cat "$here/version")}
VERSION=${DOCKER_RUN_VERSION:-$(cat "$here/version")} ||
die "please run me from an image directory or set environment variables:
DOCKER_RUN_ORG
DOCKER_RUN_IMAGE
DOCKER_RUN_VERSION"

# where
RUN_DIR=${DOCKER_RUN_DIR:-$(pwd)}

[[ ${*/--help//} != "${*}" ]] && {
help() {
set +x
echo "Usage: $me command
echo "Usage: $me [RUN_OPTIONS -- ] command

Run a command in a docker image described by $here

Options:
--help get this message
--help get this message

Any number of 'docker run' options can be passed
through to the invocation. Terminate this list of
options with '--' to begin command and arguments.

Examples:
To run bash interactively:
$ $me -i -- bash
note the terminating '--' for run options

To just tell me about the image
$ $me uname -a

Add /tmp as an additional volumeand run make
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing space between volume and and

$ $me --volume /tmp:/tmp -- make -C src

"
exit 0

}

docker run --rm -w "$RUN_DIR" -v "$RUN_DIR:$RUN_DIR" "$ORG/$IMAGE:$VERSION" "$@"
runargs=()

# extract run options
for arg in "$@"; do
case "$arg" in
--help)
help
exit
;;

--)
shift
break
;;

-*)
runargs+=("$arg")
shift
;;

*)
((!${#runargs[*]})) && break
runargs+=("$arg")
shift
;;

esac
done

docker run "${runargs[@]}" --rm -w "$RUN_DIR" -v "$RUN_DIR:$RUN_DIR" "$ORG/$IMAGE${VERSION:+:${VERSION}}" "$@"