forked from open-policy-agent/opa-envoy-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
193 lines (143 loc) · 5.04 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
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
191
192
193
# Copyright 2018 The OPA Authors. All rights reserved.
# Use of this source code is governed by an Apache2
# license that can be found in the LICENSE file.
VERSION_OPA := $(shell ./build/get-opa-version.sh)
VERSION := $(VERSION_OPA)-envoy$(shell ./build/get-plugin-rev.sh)
VERSION_ISTIO := $(VERSION_OPA)-istio$(shell ./build/get-plugin-rev.sh)
PACKAGES := $(shell go list ./.../ | grep -v 'vendor')
CGO_ENABLED ?= 1
WASM_ENABLED ?= 1
# GOPROXY=off: Don't pull anything off the network
# see https://github.com/thepudds/go-module-knobs/blob/master/README.md
GO := CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on GOFLAGS=-mod=vendor GOPROXY=off go
GOVERSION := $(shell cat ./.go-version)
GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
DISABLE_CGO := CGO_ENABLED=0
BIN := opa_envoy_$(GOOS)_$(GOARCH)
REPOSITORY := yerinu2019
IMAGE := $(REPOSITORY)/test-auth-plugin
GO_TAGS := -tags=
ifeq ($(WASM_ENABLED),1)
GO_TAGS = -tags=opa_wasm
endif
ifeq ($(shell tty > /dev/null && echo 1 || echo 0), 1)
DOCKER_FLAGS := --rm -it
else
DOCKER_FLAGS := --rm
endif
RELEASE_BUILD_IMAGE := golang:$(GOVERSION)
RELEASE_DIR ?= _release/$(VERSION)
BUILD_COMMIT := $(shell ./build/get-build-commit.sh)
BUILD_TIMESTAMP := $(shell ./build/get-build-timestamp.sh)
BUILD_HOSTNAME := $(shell ./build/get-build-hostname.sh)
LDFLAGS := "-X github.com/open-policy-agent/opa/version.Version=$(VERSION) \
-X github.com/open-policy-agent/opa/version.Vcs=$(BUILD_COMMIT) \
-X github.com/open-policy-agent/opa/version.Timestamp=$(BUILD_TIMESTAMP) \
-X github.com/open-policy-agent/opa/version.Hostname=$(BUILD_HOSTNAME)"
.PHONY: all build build-darwin build-linux build-windows clean check check-fmt check-vet check-lint \
deploy-ci docker-login generate image image-quick push push-latest tag-latest \
test test-cluster test-e2e version generate-dockerfile
######################################################
#
# Development targets
#
######################################################
all: build test check
version:
@echo $(VERSION)
generate:
$(GO) generate ./...
build: generate
$(GO) build $(GO_TAGS) -o $(BIN) -ldflags $(LDFLAGS) ./cmd/opa-envoy-plugin/...
build-darwin:
@$(MAKE) build GOOS=darwin
build-linux:
@$(MAKE) build GOOS=linux
build-windows:
@$(MAKE) build GOOS=windows
build-tekton: build-linux generate-dockerfile
build-tekton-mac: build-darwin generate-dockerfile
generate-dockerfile:
sed -e 's/GOARCH/$(GOARCH)/g' Dockerfile > .Dockerfile_$(GOARCH)
image:
@$(MAKE) ci-go-build-linux
@$(MAKE) image-quick
image-quick:
sed -e 's/GOARCH/$(GOARCH)/g' Dockerfile > .Dockerfile_$(GOARCH)
docker build -t $(IMAGE):$(VERSION) -f .Dockerfile_$(GOARCH) .
docker tag $(IMAGE):$(VERSION) $(IMAGE):$(VERSION_ISTIO)
push:
docker push $(IMAGE):$(VERSION)
docker push $(IMAGE):$(VERSION_ISTIO)
tag-latest:
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest-envoy
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest-istio
push-latest:
docker push $(IMAGE):latest-envoy
docker push $(IMAGE):latest-istio
docker-login:
@echo "Docker Login..."
@echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USER} --password-stdin
deploy-ci: docker-login image push tag-latest push-latest
test: generate
$(DISABLE_CGO) $(GO) test -v -bench=. $(PACKAGES)
test-e2e:
bats -t test/bats/test.bats
test-cluster:
@./build/install-istio-with-kind.sh
clean:
rm -f .Dockerfile_*
rm -f opa_*_*
rm -f *.so
check: check-fmt check-vet check-lint
check-fmt:
# ./build/check-fmt.sh
check-vet:
./build/check-vet.sh
check-lint:
./build/check-lint.sh
generatepb:
protoc --proto_path=test/files \
--descriptor_set_out=test/files/combined.pb \
--include_imports \
test/files/example/Example.proto \
test/files/book/Book.proto
CI_GOLANG_DOCKER_MAKE := docker run \
$(DOCKER_FLAGS) \
-u $(shell id -u):$(shell id -g) \
-v $(PWD):/src \
-w /src \
-e GOCACHE=/src/.go/cache \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e WASM_ENABLED=$(WASM_ENABLED) \
-e TELEMETRY_URL=$(TELEMETRY_URL) \
golang:$(GOVERSION) \
make
.PHONY: ci-go-%
ci-go-%:
$(CI_GOLANG_DOCKER_MAKE) "$*"
.PHONY: release
release:
docker run $(DOCKER_FLAGS) \
-v $(PWD)/$(RELEASE_DIR):/$(RELEASE_DIR) \
-v $(PWD):/_src \
$(RELEASE_BUILD_IMAGE) \
/_src/build/build-release.sh --version=$(VERSION) --output-dir=/$(RELEASE_DIR) --source-url=/_src
.PHONY: release-build-linux
release-build-linux: ensure-release-dir
@$(MAKE) build GOOS=linux CGO_ENABLED=0 WASM_ENABLED=0
mv opa_envoy_linux_$(GOARCH) $(RELEASE_DIR)/
.PHONY: release-build-darwin
release-build-darwin: ensure-release-dir
@$(MAKE) build GOOS=darwin CGO_ENABLED=0 WASM_ENABLED=0
mv opa_envoy_darwin_$(GOARCH) $(RELEASE_DIR)/
.PHONY: release-build-windows
release-build-windows: ensure-release-dir
@$(MAKE) build GOOS=windows CGO_ENABLED=0 WASM_ENABLED=0
mv opa_envoy_windows_$(GOARCH) $(RELEASE_DIR)/opa_envoy_windows_$(GOARCH).exe
.PHONY: ensure-release-dir
ensure-release-dir:
mkdir -p $(RELEASE_DIR)
.PHONY: build-all-platforms
build-all-platforms: release-build-linux release-build-darwin release-build-windows