-
Notifications
You must be signed in to change notification settings - Fork 49
/
Makefile
89 lines (74 loc) · 3.17 KB
/
Makefile
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
85
86
87
88
89
## The repository where the container image will be pushed to.
IMAGE := ghcr.io/plexsystems/konstraint
PLATFORMS := linux/arm/v7,linux/arm64/v8,linux/amd64
#
##@ Development
#
.PHONY: build
build: ## Builds the binary. It will be placed into the build directory.
go build -o build/konstraint
.PHONY: test
test: ## Runs the unit tests.
go test -v ./... -count=1
.PHONY: lint
lint: ## Runs the go linters.
golangci-lint run
.PHONY: acceptance
acceptance: build ## Runs the acceptance tests.
bats acceptance.bats
.PHONY: policy
policy: ## Runs the policy tests.
conftest verify -p examples
.PHONY: update-static
update-static: build ## Updates the static assets in the repository.
./build/konstraint create examples
./build/konstraint create test/create --output test/create
./build/konstraint doc examples --output examples/policies.md
./build/konstraint doc examples --output test/doc/expected.md
.PHONY: fmt
fmt: ## Ensures consistent formatting on policy tests.
conftest fmt examples
#
##@ Releases
#
.PHONY: docker-build
docker-build: ## Builds the docker image. Can optionally pass in a version.
ifeq ($(version),)
docker build -t konstraint:latest .
else
docker build -t konstraint:latest -t konstraint:$(version) --build-arg KONSTRAINT_VER=$(version) .
endif
.PHONY: dockerx-build
dockerx-build: ## Builds the docker image. Can optionally pass in a version.
ifeq ($(version),)
docker buildx build \
--platform "$(PLATFORMS)" \
-t konstraint:latest \
.
else
docker buildx build \
--push \
--platform "$(PLATFORMS)" \
-t konstraint:latest \
-t "konstraint:$(version)" \
--build-arg "KONSTRAINT_VER=$(version)" \
.
endif
.PHONY: docker-push
docker-push: ## Pushes the docker image to the container registry.
@test $(version)
docker tag konstraint:latest $(IMAGE):$(version)
docker tag konstraint:latest $(IMAGE):latest
docker push $(IMAGE):$(version)
docker push $(IMAGE):latest
.PHONY: release
release: ## Builds the binaries for each OS and creates the checksums.
@test $(version)
GOOS=darwin GOARCH=amd64 go build -o build/konstraint-darwin-amd64 -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'"
GOOS=darwin GOARCH=arm64 go build -o build/konstraint-darwin-arm64 -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'"
GOOS=windows GOARCH=amd64 go build -o build/konstraint-windows-amd64.exe -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'"
GOOS=linux GOARCH=amd64 go build -o build/konstraint-linux-amd64 -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'"
GOOS=linux GOARCH=arm64 go build -o build/konstraint-linux-arm64 -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'"
docker run --user $(shell id -u):$(shell id -g) --rm -v $(shell pwd):/konstraint alpine:3 /bin/ash -c 'cd /konstraint/build && sha256sum konstraint-* > checksums.txt'
help:
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)