hack/trace: ensure dlv server port is forwarded
also, bail with the usage text if no service name is provided
@@ -5,7 +5,13 @@ set -e -u
cd $(dirname $0)/..
container_name=""
-listen_cmd=""
+dlv_flags=""
+docker_flags="--interactive --privileged --rm --tty"
+
+usage() {
+ echo "Usage: trace (web|worker) [--listen port]"
+ exit 1
+}
while test $# -gt 0; do
case "$1" in
@@ -19,27 +25,24 @@ while test $# -gt 0; do
;;
--listen)
shift
- listen_cmd=" --headless=true --listen=:$1"
+ dlv_flags=" --headless=true --listen=:$1"
+ docker_flags+=" -p $1:$1"
shift
;;
*)
- echo "Usage: trace (web|worker) [--listen port]"
- exit 1
+ usage
;;
esac
done
-
+if [ -z "$container_name" ]; then
+ usage
+fi
trace_pid=$(docker exec $container_name pidof concourse)
docker build --tag dlv ./hack/dlv
-docker run \
- --interactive \
+docker run $docker_flags \
--pid=container:$container_name \
- --privileged \
- --rm \
- --tty \
- dlv \
- attach $trace_pid $listen_cmd
+ dlv attach $trace_pid $dlv_flags
