From 1d55202ec5bbe851c0764072badfca9f9b6ba632 Mon Sep 17 00:00:00 2001 From: Bartosz Leper Date: Tue, 28 Nov 2023 15:01:45 +0100 Subject: [PATCH] Support running Teleport in a "hot reload" mode This change follows the example of our Cloud project which uses the same solution under the hood. --- Makefile | 5 +++++ README.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Makefile b/Makefile index 00a6290a029ee..d080b09c99593 100644 --- a/Makefile +++ b/Makefile @@ -296,6 +296,11 @@ $(BUILDDIR)/tctl: $(BUILDDIR)/teleport: ensure-webassets bpf-bytecode rdpclient GOOS=$(OS) GOARCH=$(ARCH) $(CGOFLAG) go build -tags "webassets_embed $(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(WEBASSETS_TAG) $(RDPCLIENT_TAG) $(PIV_BUILD_TAG)" -o $(BUILDDIR)/teleport $(BUILDFLAGS) ./tool/teleport +TELEPORT_ARGS ?= start +.PHONY: teleport-hot-reload +teleport-hot-reload: + CompileDaemon --graceful-kill=true --exclude-dir=".git" --exclude-dir="node_modules" --build="make $(BUILDDIR)/teleport" --command="$(BUILDDIR)/teleport $(TELEPORT_ARGS)" + # NOTE: Any changes to the `tsh` build here must be copied to `windows.go` in Dronegen until # we can use this Makefile for native Windows builds. .PHONY: $(BUILDDIR)/tsh diff --git a/README.md b/README.md index bc5d2fd784927..138e6373c6c40 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,41 @@ sudo mkdir -p -m0700 /var/lib/teleport sudo chown $USER /var/lib/teleport ``` +#### Running Teleport in a hot reload mode + +To speed up your development process, you can run Teleport using +[`CompileDaemon`](https://github.com/githubnemo/CompileDaemon). This will build +and run the Teleport binary, and then rebuild and restart it whenever any Go +source files change. + +1. Install CompileDaemon: + + ```shell + go install github.com/githubnemo/CompileDaemon@latest + ``` + + Note that we use `go install` instead of the suggested `go get`, because we + don't want CompileDaemon to become a dependency of the project. + +1. Build and run the Teleport binary: + + ```shell + make teleport-hot-reload + ``` + + By default, this runs a `teleport start` command. If you want to customize + the command, for example by providing a custom config file location, you can + use the `TELEPORT_ARGS` parameter: + + ```shell + make teleport-hot-reload TELEPORT_ARGS='start --config=/path/to/config.yaml' + ``` + +Note that you still need to run [`make grpc`](api/proto/README.md) if you modify +any Protocol Buffers files to regenerate the generated Go sources; regenerating +these sources should in turn cause the CompileDaemon to rebuild and restart +Teleport. + ### Web UI The Teleport Web UI resides in the [web](web) directory.