Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for delve debugging in the shell #5553

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crazy-max Looks like this broke in https://github.com/moby/buildkit/pull/5497/files . We should have a CI check to make sure it doesn't go unnoticed.

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
Loading