forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-run.sh
executable file
·79 lines (67 loc) · 1.64 KB
/
docker-run.sh
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
#!/usr/bin/env bash
# docker-run.sh
#
# SUMMARY
#
# Builds given `scripts/ci-docker-images/*` and runs a command inside of
# the provided container based on this image.
set -eou pipefail
#
# Requirements
#
if [ -z "${1:-}" ]; then
echo "You must pass the docker image tag as the first argument"
exit 1
fi
if [ -z "${2:-}" ]; then
echo "You must pass a command to execute as the second argument"
exit 1
fi
#
# Variables
#
DOCKER=${USE_CONTAINER:-docker}
tag="$1"
image="timberiodev/vector-$tag:latest"
#
# (Re)Build
#
if ! $DOCKER inspect $image >/dev/null 2>&1 || [ "${REBUILD_CONTAINER_IMAGE:-true}" == true ]
then
$DOCKER build \
--file scripts/ci-docker-images/$tag/Dockerfile \
--tag $image \
.
fi
#
# Execute
#
# Set flags for "docker run".
# The `--rm` flag is used to delete containers on exit.
# The `--interactive` flag is used to keep `stdin` open.
docker_flags=("--rm" "--interactive")
# If the script's input is connected to a terminal, then
# use `--tty` to allocate a pseudo-TTY.
if [ -t 0 ]; then
docker_flags+=("--tty")
fi
# If `DOCKER_PRIVILEGED` environment variable is set to true,
# pass `--privileged`. One use case is to register `binfmt`
# handlers in order to run builders for ARM architectures
# using `qemu-user`.
if [ "${DOCKER_PRIVILEGED:-false}" == true ]; then
docker_flags+=("--privileged")
fi
# pass environment variables prefixed with `PASS_` to the container
# with removed `PASS_` prefix
IFS=$'\n'
for line in $(env | grep '^PASS_' | sed 's/^PASS_//'); do
docker_flags+=("-e" "$line")
done
unset IFS
$DOCKER run \
"${docker_flags[@]}" \
-w "$PWD" \
-v "$PWD":"$PWD" \
$image \
"${@:2}"