add makefile

This commit is contained in:
Henry Dollman
2024-10-29 21:07:16 -04:00
parent 3209c53201
commit 67f88188e1
4 changed files with 59 additions and 5 deletions

1
.gitignore vendored
View File

@@ -11,3 +11,4 @@ dist
beszel/cmd/hub/hub beszel/cmd/hub/hub
beszel/cmd/agent/agent beszel/cmd/agent/agent
node_modules node_modules
beszel/build

35
beszel/Makefile Normal file
View File

@@ -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

Binary file not shown.

View File

@@ -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. 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 ```bash
cd beszel && go mod tidy 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: 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" . 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: 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" . 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. 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" . 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 ## License