Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
190 lines (148 loc) · 4.83 KB
/
Copy pathMakefile
File metadata and controls
190 lines (148 loc) · 4.83 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
CGO_ENABLED ?= 0
GENERATE ?= 1
GOFLAGS ?= "-buildmode=exe"
GO := CGO_ENABLED=$(CGO_ENABLED) GOFLAGS="$(GOFLAGS)" go
VERSION ?= $(shell git describe --tags --always)
DOCKER := docker
DOCKER_UID ?= 0
DOCKER_GID ?= 0
REPOSITORY ?= openpolicyagent
IMAGE := $(REPOSITORY)/opa-control-plane
GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
GO_TAGS := -tags=
BIN := opactl_$(GOOS)_$(GOARCH)
ifeq ($(shell tty > /dev/null && echo 1 || echo 0), 1)
DOCKER_FLAGS := --rm -it
else
DOCKER_FLAGS := --rm
endif
LDFLAGS := "-s"
GOLANGCI_LINT_VERSION := v2.9.0
# golangci-lint runs in a container that has no Go caches of its own, so it
# re-downloads and re-type-checks every dependency on each run. Share the host
# caches with it to keep the run inside the linter's own timeout.
GOMODCACHE ?= $(shell go env GOMODCACHE 2>/dev/null)
LINT_CACHE := $(shell pwd)/.go/lint-cache
LINT_DOCKER_FLAGS := -v $(shell pwd):/app:ro,Z -w /app \
-v $(LINT_CACHE)/build:/lint-cache/build:Z -e GOCACHE=/lint-cache/build \
-v $(LINT_CACHE)/golangci:/lint-cache/golangci:Z -e GOLANGCI_LINT_CACHE=/lint-cache/golangci
ifneq ($(GOMODCACHE),)
LINT_DOCKER_FLAGS += -v $(GOMODCACHE):/go/pkg/mod:Z -e GOMODCACHE=/go/pkg/mod
endif
DOCKER_RUNNING ?= $(shell docker ps >/dev/null 2>&1 && echo 1 || echo 0)
# Get current git SHA and add -dirty if there are uncommitted changes
VCS := $(shell git rev-parse --short HEAD)$(shell test -n "$(shell git status --porcelain)" && echo -dirty)
GOVERSION := $(shell cat .go-version)
# Supported platforms to include in image manifest lists
DOCKER_PLATFORMS := linux/amd64,linux/arm64
######################################################
#
# Development targets
#
######################################################
.PHONY: all
all: build test
.PHONY: generate
generate:
ifeq ($(GENERATE), 1)
$(GO) generate ./...
else
@echo Skipping "go generate"
endif
.PHONY: build
build: go-build
# NB(sr): build-linux is used via ci-go-build-linux for cross-building. `go generate` will
# use `go run`, and run into an arch/format mismatch. In CI, the generated files are already
# in place, so we skip re-generating them.
.PHONY: build-linux
build-linux:
@$(MAKE) build GOOS=linux CGO_ENABLED=0 GENERATE=0
.PHONY: test
test: go-test go-bench library-test authz-test
.PHONY: go-build
go-build: generate
$(GO) build $(GO_TAGS) -o $(BIN) -ldflags $(LDFLAGS)
.PHONY: go-test
go-test: generate
$(GO) test $(GO_TAGS) ./...
.PHONY: go-bench
go-bench: generate
$(GO) test -benchmem -run=- -bench=. $(GO_TAGS) ./...
.PHONY: go-e2e-migrate-test
go-e2e-migrate-test: generate
$(GO) test -tags=migration_e2e ./e2e -v -run '^TestMigration/'
.PHONY: ci-build-linux
ci-build-linux:
$(MAKE) ci-go-build-linux GOARCH=arm64
$(MAKE) ci-go-build-linux GOARCH=amd64
.PHONY: docker-login
docker-login:
@echo "Docker Login..."
@echo ${DOCKER_PASSWORD} | $(DOCKER) login -u ${DOCKER_USER} --password-stdin
.PHONY: image
image:
@$(MAKE) ci-go-build-linux
@$(MAKE) image-quick
.PHONY: image-quick
image-quick: image-quick-$(GOARCH)
.PHONY: image-quick-%
image-quick-%:
$(DOCKER) build \
-t $(IMAGE):$(VERSION) \
--build-arg BASE=chainguard/static:latest \
--platform=linux/$(GOARCH) \
-f Dockerfile \
.
.PHONY: push-manifest-list-%
push-manifest-list-%:
$(DOCKER) buildx build \
--platform=$(DOCKER_PLATFORMS) \
--push \
-t $(IMAGE):$* \
--build-arg BASE=chainguard/static:latest \
-f Dockerfile \
.
.PHONY: push-image
push-image: docker-login push-manifest-list-$(VERSION)
.PHONY: deploy-ci
deploy-ci: docker-login ci-build-linux push-manifest-list-$(VERSION) push-manifest-list-edge
.PHONY: release-ci
release-ci: gorelease docker-login ci-build-linux push-manifest-list-$(VERSION) push-manifest-list-latest
.PHONY: gorelease
gorelease:
goreleaser release --clean --timeout=60m
.PHONY: libary-test
library-test:
make -C libraries/entitlements-v1 test
make -C libraries/envoy-v2.0 test
make -C libraries/envoy-v2.1 test
make -C libraries/kong-gateway-v1 test
make -C libraries/kubernetes-v2 test
make -C libraries/terraform-v2.0 test
.PHONY: authz-test
authz-test:
$(GO) run github.com/open-policy-agent/opa test -b ./internal/authz
CI_GOLANG_DOCKER_MAKE := $(DOCKER) run \
$(DOCKER_FLAGS) \
-u $(DOCKER_UID):$(DOCKER_GID) \
-v $(PWD):/src \
-w /src \
-e GOCACHE=/src/.go/cache \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e GOARCH=$(GOARCH) \
golang:$(GOVERSION)
.PHONY: ci-go-%
ci-go-%:
$(CI_GOLANG_DOCKER_MAKE) /bin/bash -c "git config --global --add safe.directory /src && make $*"
.PHONY: clean
clean:
rm -f opactl_*_*
.PHONY: check
check:
ifeq ($(DOCKER_RUNNING), 1)
@mkdir -p $(LINT_CACHE)/build $(LINT_CACHE)/golangci
docker run --rm $(LINT_DOCKER_FLAGS) golangci/golangci-lint:${GOLANGCI_LINT_VERSION} golangci-lint run -v
else
@echo "Docker not installed or running. Skipping golangci run."
endif