From c55e6b986eaea38543851dc407cc0fa4485c9fe1 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Fri, 2 Feb 2024 10:34:02 +0100 Subject: [PATCH] Add infra + documentation to remote debug harvester-installer Signed-off-by: Volker Theile --- Dockerfile.dapper | 2 +- README.md | 32 ++++++++++++++++++++++++++++++-- scripts/build | 9 +++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 3bd624f42..d318ac636 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -40,7 +40,7 @@ RUN mkdir /usr/tmp && \ mv /usr/tmp/helm /usr/bin/helm # You cloud defined your own rke2 url by setup `RKE2_IMAGE_REPO` -ENV DAPPER_ENV REPO TAG DRONE_TAG DRONE_BRANCH CROSS RKE2_IMAGE_REPO USE_LOCAL_IMAGES BUILD_QCOW DRONE_BUILD_EVENT +ENV DAPPER_ENV REPO TAG DRONE_TAG DRONE_BRANCH CROSS RKE2_IMAGE_REPO USE_LOCAL_IMAGES BUILD_QCOW DRONE_BUILD_EVENT REMOTE_DEBUG ENV DAPPER_SOURCE /go/src/github.com/harvester/harvester-installer/ ENV DAPPER_OUTPUT ./bin ./dist ENV DAPPER_DOCKER_SOCKET true diff --git a/README.md b/README.md index 15076b155..f31f698d7 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Either way (ISO or PXE), the installer writes the final config out to a temporary file which is passed to [harv-install](https://github.com/harvester/harvester-installer/blob/master/package/harvester-os/files/usr/sbin/harv-install) which in turn calls `elemental install` to provision the system. The harv-install script also preloads all the container images. -Finally the system is rebooted. +Finally, the system is rebooted. On the newly installed system, `harvester-installer` remains active on the console in order to show the cluster management URL along with @@ -72,7 +72,7 @@ the current node's hostname and IP address. ## Hacking the Interactive Part of `harvester-installer` -Ordinarily `harvester-installer` needs to be run from a booted ISO +Ordinarily `harvester-installer` needs to be run from a booted ISO, so it can actually install a system. But, if you're only working on changes to the interactive part of the installer (e.g. adding or changing fields, or altering the workflow) and don't actually @@ -92,6 +92,34 @@ screen. To break out of the installer, hit CTRL-C. If you rebuild the binary it can be sync'd back to a running vagrant box with `vagrant rsync`. +To remote debug the `harvester-installer` in your IDE, you need to +install the `delve` package in your Vagrant box first. + +```sh + $ zypper addrepo https://download.opensuse.org/repositories/devel:languages:go/15.4/devel:languages:go.repo + $ zypper refresh + $ zypper install delve +``` + +Then rebuild the `harvester-installer` app and start it in the +Vagrant box. + +```sh + $ REMOTE_DEBUG=true USE_LOCAL_IMAGES=true make build + $ vagrant rsync + $ vagrant ssh + > sudo DEBUG=true TTY=/dev/tty dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec /vagrant/harvester-installer +``` + +The `harvester-installer` app will now listen for remote connections +on port `2345`. + +Run `vagrant ssh-config` on your host to get the IP address that is +needed to connect the IDE debugger to the `harvester-installer` app. +If you are using the Goland IDE, check out their [documentation](https://www.jetbrains.com/help/go/go-remote.html) +how to attach to the `harvester-installer` process on the remote +Vagrant box. + ## License Copyright (c) 2024 [Rancher Labs, Inc.](http://rancher.com) diff --git a/scripts/build b/scripts/build index 83cbf0cf3..5633c7914 100755 --- a/scripts/build +++ b/scripts/build @@ -40,10 +40,15 @@ LINKFLAGS="-X github.com/harvester/harvester-installer/pkg/config.RKE2Version=$R $LINKFLAGS" if [ "$(uname)" = "Linux" ]; then - OTHER_LINKFLAGS="-extldflags -static -s" + if [ -n "${REMOTE_DEBUG}" ]; then + OTHER_COMPILERFLAGS="all=-N -l" + OTHER_LINKFLAGS="-extldflags -static" + else + OTHER_LINKFLAGS="-extldflags -static -s" + fi fi -CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/harvester-installer . +CGO_ENABLED=0 go build -gcflags "${OTHER_COMPILERFLAGS}" -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/harvester-installer . # Copy to harvester package folder mkdir -p ${PACKAGE_HARVESTER_OS_DIR}/files/usr/bin