diff --git a/.gitignore b/.gitignore index 613e06f..90f1512 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ dist beszel/cmd/hub/hub beszel/cmd/agent/agent node_modules +beszel/build diff --git a/beszel/Makefile b/beszel/Makefile new file mode 100644 index 0000000..b9ffca2 --- /dev/null +++ b/beszel/Makefile @@ -0,0 +1,35 @@ +# Default OS/ARCH values +OS ?= $(shell go env GOOS) +ARCH ?= $(shell go env GOARCH) +# Skip building the web UI if true +SKIP_WEB ?= false + +.PHONY: tidy build-agent build-hub build clean lint +.DEFAULT_GOAL := build + +tidy: + go mod tidy + +build-web-ui: + @if command -v bun >/dev/null 2>&1; then \ + bun install --cwd ./site && \ + bun run --cwd ./site build; \ + else \ + npm install --prefix ./site && \ + npm run --prefix ./site build; \ + fi + +build-agent: tidy + CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o ./build/beszel-agent_$(OS)_$(ARCH) -ldflags "-w -s" beszel/cmd/agent + +build-hub: tidy $(if $(filter false,$(SKIP_WEB)),build-web-ui) + CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o ./build/beszel_$(OS)_$(ARCH) -ldflags "-w -s" beszel/cmd/hub + +build: build-agent build-hub + +clean: + go clean + rm -rf ./build + +lint: + golangci-lint run diff --git a/beszel/site/bun.lockb b/beszel/site/bun.lockb index ccc65f3..8505c99 100755 Binary files a/beszel/site/bun.lockb and b/beszel/site/bun.lockb differ diff --git a/readme.md b/readme.md index 59a5150..63d1def 100644 --- a/readme.md +++ b/readme.md @@ -258,13 +258,31 @@ Pausing/unpausing the agent for longer than one minute will result in incomplete Both the hub and agent are written in Go, so you can easily build them yourself, or cross-compile for different platforms. Please [install Go](https://go.dev/doc/install) first if you haven't already. -### Prepare dependencies +### Using Makefile + +Run `make` in `/beszel`. This creates a `build` directory containing the binaries. + +```bash +cd beszel && make +``` + +You can also build for different platforms: + +```bash +make OS=freebsd ARCH=arm64 +``` + +See a list of valid options by running `go tool dist list`. + +### Manual compilation + +#### Prepare dependencies ```bash cd beszel && go mod tidy ``` -### Agent +#### Agent Go to `beszel/cmd/agent` and run the following command to create a binary in the current directory: @@ -272,7 +290,7 @@ Go to `beszel/cmd/agent` and run the following command to create a binary in the CGO_ENABLED=0 go build -ldflags "-w -s" . ``` -### Hub +#### Hub The hub embeds the web UI in the binary, so you must build the website first. I use [Bun](https://bun.sh/), but you may use Node.js if you prefer: @@ -288,7 +306,7 @@ Then in `beszel/cmd/hub`: CGO_ENABLED=0 go build -ldflags "-w -s" . ``` -### Cross-compiling +#### Cross-compiling You can cross-compile for different platforms using the `GOOS` and `GOARCH` environment variables. @@ -298,7 +316,7 @@ For example, to build for FreeBSD ARM64: GOOS=freebsd GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "-w -s" . ``` -You can see a list of valid options by running `go tool dist list`. +See a list of valid options by running `go tool dist list`. ## License