25aa001135
P0-01 Go module + cmd/server + cmd/agent skeletons + internal/ tree
P0-02 LICENSE (PolyForm NC 1.0.0), README, CONTRIBUTING
P0-03 golangci-lint, pre-commit, .editorconfig, .gitignore
P0-04 Gitea Actions CI: test (race+coverage), lint, cross-platform build matrix
P0-05 Dockerfile.server (multi-stage, distroless/static), docker-compose.yml
P0-06 Makefile with build/test/lint/fmt/run/release targets
build, vet, test, and cross-compile to linux/{amd64,arm64} + windows/amd64
all verified locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
2.6 KiB
Makefile
69 lines
2.6 KiB
Makefile
# restic-manager — common dev targets
|
|
|
|
SHELL := /bin/bash
|
|
BIN_DIR := bin
|
|
SERVER_BIN := $(BIN_DIR)/restic-manager-server
|
|
AGENT_BIN := $(BIN_DIR)/restic-manager-agent
|
|
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
|
LDFLAGS := -s -w -X main.version=$(VERSION)
|
|
GOFLAGS := -trimpath
|
|
DOCKER_IMAGE ?= ghcr.io/dcglab/restic-manager
|
|
DOCKER_TAG ?= dev
|
|
|
|
.PHONY: help build server agent test test-race lint fmt tidy clean run-server run-agent docker release
|
|
|
|
help:
|
|
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN{FS=":.*?## "};{printf " \033[36m%-14s\033[0m %s\n",$$1,$$2}'
|
|
|
|
build: server agent ## Build server + agent into ./bin
|
|
|
|
server: ## Build the server binary
|
|
@mkdir -p $(BIN_DIR)
|
|
CGO_ENABLED=0 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(SERVER_BIN) ./cmd/server
|
|
|
|
agent: ## Build the agent binary
|
|
@mkdir -p $(BIN_DIR)
|
|
CGO_ENABLED=0 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(AGENT_BIN) ./cmd/agent
|
|
|
|
test: ## Run tests
|
|
go test ./...
|
|
|
|
test-race: ## Run tests with the race detector
|
|
go test -race -coverprofile=coverage.out ./...
|
|
|
|
lint: ## Run golangci-lint
|
|
golangci-lint run ./...
|
|
|
|
fmt: ## Format with gofumpt + goimports
|
|
gofumpt -w .
|
|
goimports -local gitea.dcglab.co.uk/steve/restic-manager -w .
|
|
|
|
tidy: ## go mod tidy
|
|
go mod tidy
|
|
|
|
clean: ## Remove build artifacts
|
|
rm -rf $(BIN_DIR) coverage.out coverage.html
|
|
|
|
run-server: server ## Build and run the server
|
|
$(SERVER_BIN)
|
|
|
|
run-agent: agent ## Build and run the agent
|
|
$(AGENT_BIN)
|
|
|
|
docker: ## Build the server Docker image
|
|
docker build -f deploy/Dockerfile.server --build-arg VERSION=$(VERSION) -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
|
|
|
|
release: ## Cross-compile for all supported platforms
|
|
@mkdir -p $(BIN_DIR)
|
|
@for target in linux/amd64 linux/arm64 windows/amd64; do \
|
|
goos=$${target%/*}; goarch=$${target#*/}; \
|
|
ext=""; if [ "$$goos" = "windows" ]; then ext=".exe"; fi; \
|
|
echo "==> $$goos/$$goarch"; \
|
|
GOOS=$$goos GOARCH=$$goarch CGO_ENABLED=0 \
|
|
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" \
|
|
-o $(BIN_DIR)/restic-manager-server-$$goos-$$goarch$$ext ./cmd/server; \
|
|
GOOS=$$goos GOARCH=$$goarch CGO_ENABLED=0 \
|
|
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" \
|
|
-o $(BIN_DIR)/restic-manager-agent-$$goos-$$goarch$$ext ./cmd/agent; \
|
|
done
|