-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·37 lines (34 loc) · 1.57 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·37 lines (34 loc) · 1.57 KB
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
#!/bin/sh
# Build and run ipeye-tt inside the official Go image, on the host network so
# the fake balancer can own port 443 and the camera can reach the listener.
#
# ./run.sh build
# ./run.sh -mode reverse -advertise 10.0.0.2 -duration 10m -json out/run.json
# ./run.sh -mode forward -url rtsp://root:pw@camera:554/stream=0
set -e
cd "$(dirname "$0")"
IMAGE=${IPEYE_TT_IMAGE:-golang:1.24}
MODCACHE=${IPEYE_TT_MODCACHE:-ipeye-tt-gomod}
mkdir -p bin out certs
# -buildvcs=false because the checkout is bind-mounted into a container running
# as root while the working copy belongs to whoever cloned it. Git then refuses
# the repository as dubious ownership, and the stamping step fails the build
# with "error obtaining VCS status" — for everyone whose host user is not root.
build() {
docker run --rm -v "$PWD":/src -w /src -v "$MODCACHE":/go/pkg/mod \
-e GOFLAGS=-mod=mod -e CGO_ENABLED=0 "$IMAGE" \
sh -c 'go mod tidy >/dev/null && go build -trimpath -buildvcs=false -o bin/ipeye-tt ./cmd/ipeye-tt'
}
case "$1" in
build) build; echo "built bin/ipeye-tt"; exit 0 ;;
test) shift; exec docker run --rm -v "$PWD":/src -w /src -v "$MODCACHE":/go/pkg/mod "$IMAGE" go test ./... "$@" ;;
esac
[ -x bin/ipeye-tt ] || build
# Named, so a killed client never leaves the container behind; --init so a
# signal reaches the process and the verdict is still printed.
NAME=ipeye-tt-$$
trap 'docker kill "$NAME" >/dev/null 2>&1' INT TERM
docker run --rm --init --name "$NAME" --network host -v "$PWD":/src -w /src "$IMAGE" ./bin/ipeye-tt "$@"
st=$?
docker kill "$NAME" >/dev/null 2>&1
exit $st