A new selfupdate package asks one URL what the newest build is — a Gitea/Forgejo repo API base, or any directory holding VERSION, SHA256SUMS and hamlab-linux-<arch>, which is what make release already writes and what install.sh already downloads. The binary is checked against SHA256SUMS before it goes near the running one, and a token is sent when the source is behind a login, so a private Gitea serves its own fleet without opening the instance to everyone. Version ordering is install.sh's vnum rule, so the daemon and the installer never disagree about which build is newer. Settings gains an Updates card: installed, published, when it last looked, the source, release notes, Check for updates, and Install. The rail badges Settings when a newer build is out. Nothing installs unasked — it restarts the daemon and drops terminals. scripts/gitea-release.sh (make gitea-release) publishes dist/ as a Gitea release. Deliberate, and not part of deploy: deploy pushes to the machines this hub owns, publishing offers the build to every install anywhere. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
88 lines
3.6 KiB
Makefile
88 lines
3.6 KiB
Makefile
# Commit first, then deploy: the version is the commit the binary was built from.
|
|
VERSION ?= $(shell git describe --tags --always 2>/dev/null || echo dev)
|
|
GO ?= go
|
|
PREFIX ?= /usr/local/bin
|
|
PUBLISH ?= /home/core/apps/hamlab-demo/site
|
|
|
|
# every architecture a release carries; arm is ARMv6 hard-float, so it covers every Raspberry Pi
|
|
ARCHES ?= amd64 arm64 arm 386 riscv64
|
|
LDFLAGS = -s -w -X main.version=$(VERSION)
|
|
# static, no cgo: the same file runs on glibc, musl (Alpine) and anything else with a Linux kernel
|
|
GOBUILD = CGO_ENABLED=0 GOOS=linux GOARM=6 $(GO) build -trimpath -ldflags "$(LDFLAGS)"
|
|
|
|
.PHONY: all web build go dev cross release publish gitea-release deploy push-nodes push-nodes-force test clean
|
|
|
|
all: build
|
|
|
|
web:
|
|
cd web && npm ci --no-audit --no-fund && npm run build
|
|
|
|
build: web go
|
|
|
|
# backend only (assumes web/dist already built)
|
|
go:
|
|
$(GOBUILD) -o bin/hamlab ./cmd/hamlab
|
|
|
|
# one other architecture: make build-arm64, build-arm, build-386, build-riscv64, build-amd64
|
|
build-%: web
|
|
GOARCH=$* $(GOBUILD) -o bin/hamlab-linux-$* ./cmd/hamlab
|
|
|
|
dev:
|
|
cd web && npm run dev
|
|
|
|
# siblings for every other architecture; installed beside the binary, and the hub pushes
|
|
# each managed machine the one that matches it
|
|
cross:
|
|
@for a in $(filter-out $(shell $(GO) env GOARCH),$(ARCHES)); do \
|
|
echo "build linux/$$a"; GOARCH=$$a $(GOBUILD) -o bin/hamlab-linux-$$a ./cmd/hamlab || exit 1; done
|
|
|
|
# dist/: one static binary per architecture, install.sh, SHA256SUMS. Serve the directory
|
|
# anywhere (or attach it to a release) and install.sh does the rest.
|
|
release: web
|
|
rm -rf dist && mkdir -p dist
|
|
@for a in $(ARCHES); do \
|
|
echo "build linux/$$a"; GOARCH=$$a $(GOBUILD) -o dist/hamlab-linux-$$a ./cmd/hamlab || exit 1; done
|
|
sed 's|@VERSION@|$(VERSION)|' install.sh > dist/install.sh && chmod +x dist/install.sh
|
|
echo $(VERSION) > dist/VERSION
|
|
cd dist && sha256sum hamlab-linux-* install.sh > SHA256SUMS
|
|
|
|
test:
|
|
$(GO) vet ./... && $(GO) test ./...
|
|
sh -n install.sh
|
|
cd web && npm test --silent
|
|
|
|
# installs here (keeping the config, user and password), then updates every managed machine
|
|
# Offer this build to every install, wherever it is: a release on Gitea, which is what
|
|
# Settings -> Updates reads. Deliberate, and not part of deploy — deploy pushes to the
|
|
# machines this hub owns, publishing offers it to everyone else.
|
|
gitea-release: release
|
|
./scripts/gitea-release.sh $(RELEASE_ARGS)
|
|
|
|
deploy: build cross
|
|
./bin/hamlab install --prefix $(PREFIX)
|
|
@sleep 1; $(PREFIX)/hamlab push-nodes || true
|
|
@# The public installer must never lag the fleet: it would offer everyone an older build, and
|
|
@# "upgrade" a current machine backwards. Publish only where this hub serves the download site.
|
|
@if [ -d $(PUBLISH) ]; then $(MAKE) --no-print-directory publish; fi
|
|
|
|
# push the installed binary to every managed machine (what deploy does last)
|
|
push-nodes:
|
|
$(PREFIX)/hamlab push-nodes
|
|
|
|
# same, interrupting running tasks and attached terminals on the nodes
|
|
push-nodes-force:
|
|
$(PREFIX)/hamlab push-nodes --force
|
|
|
|
clean:
|
|
rm -rf bin dist internal/web/dist web/dist
|
|
|
|
# Put the release where `curl -fsSL https://hamlab-demo.bigham.dev/install.sh | sh` finds it:
|
|
# the static site beside the demo page (nginx, public through NPM). Binaries first, VERSION
|
|
# last, so nobody is ever pointed at files that aren't there yet.
|
|
publish: release
|
|
mkdir -p $(PUBLISH)/dl
|
|
cp dist/hamlab-linux-* dist/SHA256SUMS $(PUBLISH)/dl/
|
|
cp dist/install.sh $(PUBLISH)/dl/install.sh && cp dist/install.sh $(PUBLISH)/install.sh
|
|
cp dist/VERSION $(PUBLISH)/dl/VERSION
|
|
@echo "published $(VERSION): curl -fsSL https://hamlab-demo.bigham.dev/install.sh | sh"
|