forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
143 lines (106 loc) · 3.85 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
# Copyright 2016 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 := 0.4.9-dev
PACKAGES := \
github.com/open-policy-agent/opa/ast/.../ \
github.com/open-policy-agent/opa/cmd/.../ \
github.com/open-policy-agent/opa/rego/.../ \
github.com/open-policy-agent/opa/repl/.../ \
github.com/open-policy-agent/opa/runtime/.../ \
github.com/open-policy-agent/opa/server/.../ \
github.com/open-policy-agent/opa/storage/.../ \
github.com/open-policy-agent/opa/topdown/.../ \
github.com/open-policy-agent/opa/types/.../ \
github.com/open-policy-agent/opa/util/.../ \
github.com/open-policy-agent/opa/test/.../
GO := go
GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
DISABLE_CGO := CGO_ENABLED=0
BIN := opa_$(GOOS)_$(GOARCH)
REPOSITORY := openpolicyagent
IMAGE := $(REPOSITORY)/opa
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)"
GO15VENDOREXPERIMENT := 1
export GO15VENDOREXPERIMENT
.PHONY: all build check check-fmt check-lint check-vet \
clean cover deps fmt generate install perf perf-regression \
push push-latest push-release-builder release release-builder \
release-patch tag-latest test version
######################################################
#
# Development targets
#
######################################################
all: deps build test check
version:
@echo $(VERSION)
deps:
@./build/install-deps.sh
generate:
$(GO) generate
build: generate
$(DISABLE_CGO) $(GO) build -o $(BIN) -ldflags $(LDFLAGS)
image:
@$(MAKE) build GOOS=linux
@$(MAKE) image-quick
image-quick:
sed -e 's/GOARCH/$(GOARCH)/g' Dockerfile.in > .Dockerfile_$(GOARCH)
docker build -t $(IMAGE):$(VERSION) -f .Dockerfile_$(GOARCH) .
push:
docker push $(IMAGE):$(VERSION)
tag-latest:
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest
push-latest:
docker push $(IMAGE):latest
install: generate
$(DISABLE_CGO) $(GO) install -ldflags $(LDFLAGS)
test: generate
$(DISABLE_CGO) $(GO) test $(PACKAGES)
COVER_PACKAGES=$(PACKAGES)
$(COVER_PACKAGES):
@mkdir -p coverage/$(shell dirname $@)
$(DISABLE_CGO) $(GO) test -covermode=count -coverprofile=coverage/$(shell dirname $@)/coverage.out $@
$(GO) tool cover -html=coverage/$(shell dirname $@)/coverage.out || true
perf: generate
$(DISABLE_CGO) $(GO) test -v -run=donotruntests -bench=. $(PACKAGES) | grep "^Benchmark"
perf-regression:
./build/run-perf-regression.sh
cover: $(COVER_PACKAGES)
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
fmt:
$(GO) fmt $(PACKAGES)
clean:
rm -f opa_*_*
rm -f .Dockerfile_*
######################################################
#
# Release targets
#
######################################################
release-builder:
sed -e s/GOVERSION/$(shell python -c 'import yaml; print yaml.load(open("./.travis.yml"))["go"][0]')/g Dockerfile_release-builder.in > .Dockerfile_release-builder
docker build -f .Dockerfile_release-builder -t $(REPOSITORY)/release-builder .
push-release-builder:
docker push $(REPOSITORY)/release-builder
release:
docker run -it --rm -v $(PWD)/_release/$(VERSION):/_release/$(VERSION) \
-v $(PWD)/build/build-release.sh:/build-release.sh \
$(REPOSITORY)/release-builder:latest \
/build-release.sh $(VERSION) /_release/$(VERSION)
release-patch:
@docker run -it --rm -v $(PWD)/build/gen-release-patch.sh:/gen-release-patch.sh \
python:2.7 /gen-release-patch.sh $(VERSION)