-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
84 lines (66 loc) · 2.29 KB
/
Copy pathMakefile
File metadata and controls
84 lines (66 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
IMG ?= ghcr.io/achetronic/request-validator:dev
VERSION ?= dev
BIN_NAME ?= request-validator
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
DIST_DIR ?= dist
BUILD_FLAGS ?= -trimpath -buildvcs=false -ldflags="-s -w -X main.version=$(VERSION)"
PLATFORMS ?= linux/amd64,linux/arm64
SHELL := /usr/bin/env bash
.SHELLFLAGS = -ec
.DEFAULT_GOAL := help
##@ Dev
.PHONY: fmt
fmt: ## go fmt
go fmt ./...
.PHONY: vet
vet: ## go vet
go vet ./...
.PHONY: test
test: ## go test
go test -count=1 ./...
.PHONY: race
race: ## go test -race
go test -race -count=1 ./...
##@ Build
.PHONY: build
build: ## Build the binary into bin/<os>/<arch>/<name>
mkdir -p bin/$(GOOS)/$(GOARCH)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build $(BUILD_FLAGS) -o bin/$(GOOS)/$(GOARCH)/$(BIN_NAME) ./cmd
.PHONY: package
package: build ## Package the built binary as a tar.gz under dist/
mkdir -p $(DIST_DIR)
tar -C bin/$(GOOS)/$(GOARCH) -czf \
$(DIST_DIR)/$(BIN_NAME)-$(VERSION)-$(GOOS)-$(GOARCH).tar.gz $(BIN_NAME)
.PHONY: package-signature
package-signature: ## Generate MD5 + SHA256 sidecar files for the package
cd $(DIST_DIR) && \
md5sum $(BIN_NAME)-$(VERSION)-$(GOOS)-$(GOARCH).tar.gz > $(BIN_NAME)-$(VERSION)-$(GOOS)-$(GOARCH).tar.gz.md5 && \
sha256sum $(BIN_NAME)-$(VERSION)-$(GOOS)-$(GOARCH).tar.gz > $(BIN_NAME)-$(VERSION)-$(GOOS)-$(GOARCH).tar.gz.sha256
.PHONY: run
run: ## Run from source with the example policy
go run -buildvcs=false ./cmd --config examples/policy.yaml --log-level debug
##@ Docker
.PHONY: docker-build
docker-build: ## Build a single-arch container image
docker build --build-arg VERSION=$(VERSION) -t $(IMG) .
.PHONY: docker-push
docker-push: ## Push the (single-arch) image
docker push $(IMG)
.PHONY: docker-buildx
docker-buildx: ## Build and push a multi-arch image with buildx
docker buildx build \
--platform $(PLATFORMS) \
--build-arg VERSION=$(VERSION) \
-t $(IMG) \
--push .
##@ Misc
.PHONY: clean
clean: ## Remove build artifacts
rm -rf bin dist
.PHONY: help
help: ## Show this help
@awk 'BEGIN {FS=":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} \
/^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) }' $(MAKEFILE_LIST)