-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathrun
executable file
·38 lines (30 loc) · 947 Bytes
/
run
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
#!/bin/bash
set -e
if [ "" == "${1:-}" ] ; then
echo "ERROR: include an image name as the first argument" 2>&1
exit 1
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
IMAGE_NAME="$1"
DOCKER_IMAGE=${DOCKER_IMAGE:-bosh/$IMAGE_NAME}
# $UID is a readonly variable set by bash by default.
NEW_UID="$UID"
NEW_GID="$(id -g)"
if [[ "$UID" == 0 ]]; then
echo "This script is not intended to be run as root..."
echo "Passing UID to container as 1000..."
NEW_UID=1000
fi
if [[ "$NEW_GID" == 0 ]]; then
echo "This script is not intended to be run as root..."
echo "Passing GID to container as 1000..."
NEW_GID=1000
fi
pushd "$IMAGE_NAME"
docker build \
--build-arg USER_ID="$NEW_UID" \
--build-arg GROUP_ID="$NEW_GID" \
-t "$DOCKER_IMAGE" \
.
popd
exec docker run --privileged -v "$DIR/../..:/opt/bosh" --workdir /opt/bosh "--user=$NEW_UID:$NEW_GID" -t -i "$DOCKER_IMAGE"