Skip to content

Commit

Permalink
Add support for delve debugging in the shell
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Goderre <[email protected]>
  • Loading branch information
LaurentGoderre committed Nov 27, 2024
1 parent c234dd9 commit d91a01d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ ENV BUILDKIT_SETUP_CGROUPV2_ROOT=1
ENTRYPOINT ["buildkitd"]

FROM buildkit-linux AS buildkit-linux-debug
COPY --link --from=dlv /usr/bin/dlv /usr/bin/dlv
COPY --link --from=dlv /out/dlv /usr/bin/dlv
COPY --link --chmod=755 <<EOF /docker-entrypoint.sh
#!/bin/sh
exec dlv exec /usr/bin/buildkitd \\
Expand Down Expand Up @@ -424,6 +424,7 @@ COPY --link --from=cni-plugins /opt/cni/bin/bridge /opt/cni/bin/host-local /opt/
COPY --link hack/fixtures/cni.json /etc/buildkit/cni.json
COPY --link hack/fixtures/dns-cni.conflist /etc/buildkit/dns-cni.conflist
COPY --link --from=binaries / /usr/bin/
COPY --link --from=dlv /out/dlv /usr/bin/dlv

# integration-tests prepares an image suitable for running all tests
FROM integration-tests-base AS integration-tests
Expand Down
34 changes: 34 additions & 0 deletions hack/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -e

if ! command -v $1 &>/dev/null; then
echo >&2 'error: binary-daemon or dynbinary-daemon must be run before run'
false
fi

COMMAND="$(command -v $1)"

if [ -n "$DELVE_PORT" ]; then
delve_listen_port="${DELVE_PORT##*:}"
fi

command=("$COMMAND")

if [ -n "$DELVE_PORT" ]; then
command=(
dlv
--listen="0.0.0.0:$delve_listen_port"
--headless=true
--log
--api-version=2
--only-same-user=false
--check-go-version=false
--accept-multiclient
exec "${command[@]}" --
)
fi

set -x
# shellcheck disable=SC2086
exec "${command[@]}"
16 changes: 13 additions & 3 deletions hack/shell
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ function clean() {
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
DOCKER_BUILDKIT=1 docker build --iidfile $iidfile --build-arg BUILDKIT_DEBUG --target dev-env .

BUILDKIT_REGISTRY_MIRROR_DIR="/root/.cache/registry"

ENV="-e DELVE_PORT -e BUILDKIT_REGISTRY_MIRROR_DIR"

trap clean EXIT
SSH=
if [ -n "$MOUNT_SSH_AUTH_SOCK" ]; then
SSH="-v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK -e SSH_AUTH_SOCK"
fi

volumes=
volumes="-v /tmp"
if [ -n "$MOUNT_BUILDKIT_SOURCE" ]; then
volumes="-v $(pwd):/src"
volumes="$volumes -v $(pwd):/src"
fi

if [ -n "$DELVE_PORT" ]; then
DELVE_PORT_FORWARD="-p $DELVE_PORT"
fi

DOCKER_FLAGS="-it --rm --privileged --name=buildkit-dev $SSH $volumes $ENV $DELVE_PORT_FORWARD"

set -x
docker run $SSH $volumes -it --privileged -v /tmp -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --rm $(cat $iidfile) ash
docker run $DOCKER_FLAGS $(cat $iidfile) ash

0 comments on commit d91a01d

Please sign in to comment.