forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-run.sh
executable file
·76 lines (65 loc) · 1.62 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
#!/usr/bin/env bash
set -euo pipefail
# docker-run.sh
#
# SUMMARY
#
# Builds given `scripts/ci-docker-images/*` and runs a command inside of
# the provided container based on this image.
#
# 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
#
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}"