Skip to content

Commit

Permalink
Add infra + documentation to remote debug harvester-installer
Browse files Browse the repository at this point in the history
Signed-off-by: Volker Theile <vtheile@suse.com>
  • Loading branch information
votdev authored and starbops committed Feb 7, 2024
1 parent b402b17 commit c55e6b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ 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
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
Expand All @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c55e6b9

Please sign in to comment.