Bugs fixed:
- Renderer.Error set WriteHeader before Content-Type, causing
the header to be silently dropped. Now sets Content-Type first.
- truncate template function operated on bytes, not runes — could
split multi-byte UTF-8 characters (Norwegian æøå). Now uses
[]rune for correct Unicode handling.
Performance:
- Skip session DB lookup (2 queries) on /static/ and /uploads/
requests — these never use user context.
UX consistency:
- Replace all http.NotFound and http.Error("Forbidden") in
handler layer with styled error pages via Renderer.Error.
- Add notFound/forbidden helper methods on Handler.
Deployment fixes:
- Remove false libc6/glibc deps from nfpm.yaml (binary is
statically linked with CGO_ENABLED=0).
- Add CGO_ENABLED=0 to Makefile build target for consistency.
- Add .dockerignore to exclude .git, dist/, data/ from build
context.
- Remove phantom 'lint' from Makefile .PHONY.
- Document ProtectSystem=strict constraint in systemd service.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.3 KiB
Makefile
85 lines
2.3 KiB
Makefile
# Favoritter build system
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
|
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.buildDate=$(BUILD_DATE)
|
|
PLATFORMS := linux/amd64 linux/arm64
|
|
DIST := dist
|
|
|
|
.PHONY: build build-all deb rpm container tarballs artifacts checksums clean test
|
|
|
|
## Build for current platform
|
|
build:
|
|
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o favoritter ./cmd/favoritter
|
|
|
|
## Run tests
|
|
test:
|
|
go test ./...
|
|
|
|
## Cross-compile for all platforms
|
|
build-all: $(DIST)
|
|
@for platform in $(PLATFORMS); do \
|
|
os=$${platform%%/*}; \
|
|
arch=$${platform##*/}; \
|
|
echo "Building $$os/$$arch..."; \
|
|
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch \
|
|
go build -ldflags="$(LDFLAGS)" \
|
|
-o $(DIST)/favoritter_$(VERSION)_$${os}_$${arch} \
|
|
./cmd/favoritter; \
|
|
done
|
|
|
|
## Build .deb packages (requires nfpm)
|
|
deb: build-all
|
|
@for platform in $(PLATFORMS); do \
|
|
arch=$${platform##*/}; \
|
|
echo "Packaging deb for $$arch..."; \
|
|
ARCH=$$arch VERSION=$(VERSION) nfpm package \
|
|
--packager deb \
|
|
--target $(DIST)/favoritter_$(VERSION)_$${arch}.deb; \
|
|
done
|
|
|
|
## Build .rpm packages (requires nfpm)
|
|
rpm: build-all
|
|
@for platform in $(PLATFORMS); do \
|
|
arch=$${platform##*/}; \
|
|
echo "Packaging rpm for $$arch..."; \
|
|
ARCH=$$arch VERSION=$(VERSION) nfpm package \
|
|
--packager rpm \
|
|
--target $(DIST)/favoritter_$(VERSION)_$${arch}.rpm; \
|
|
done
|
|
|
|
## Build container image
|
|
container:
|
|
BUILDAH_FORMAT=docker podman build \
|
|
--build-arg BUILD_DATE="$(BUILD_DATE)" \
|
|
--build-arg GIT_REVISION="$(VERSION)" \
|
|
--build-arg VERSION="$(VERSION)" \
|
|
-t favoritter:$(VERSION) \
|
|
-t favoritter:latest .
|
|
|
|
## Package binaries into tarballs
|
|
tarballs: build-all
|
|
@for platform in $(PLATFORMS); do \
|
|
os=$${platform%%/*}; \
|
|
arch=$${platform##*/}; \
|
|
name=favoritter_$(VERSION)_$${os}_$${arch}; \
|
|
echo "Creating tarball $$name.tar.gz..."; \
|
|
tar -czf $(DIST)/$$name.tar.gz \
|
|
-C $(DIST) $${name} \
|
|
-C $(CURDIR) README.md LICENSE; \
|
|
done
|
|
|
|
## Generate SHA256 checksums
|
|
checksums:
|
|
cd $(DIST) && sha256sum *.tar.gz *.deb *.rpm 2>/dev/null > checksums.txt || true
|
|
|
|
## Build all release artifacts
|
|
artifacts: tarballs deb rpm checksums
|
|
|
|
## Clean build artifacts
|
|
clean:
|
|
rm -rf $(DIST) favoritter
|
|
|
|
$(DIST):
|
|
mkdir -p $(DIST)
|