forked from GoogleCloudPlatform/config-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
94 lines (79 loc) · 2.72 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
PROTO_DOCKER_IMAGE=gcv-proto-builder
PLATFORMS := linux windows darwin
BUILD_DIR=./bin
NAME=config-validator
# Build docker image used for generating proto files
.PHONY: proto-builder
proto-builder:
docker build -t $(PROTO_DOCKER_IMAGE) -f ./build/proto/Dockerfile .
# Generate validator.proto
.PHONY: proto
proto: proto-builder
docker run \
-v `pwd`:/go/src/github.com/forseti-security/config-validator \
$(PROTO_DOCKER_IMAGE) \
protoc -I/proto -I./api --go_out=plugins=grpc:./pkg/api/validator ./api/validator.proto
# Generate validator.proto for Python
.PHONY: pyproto
pyproto:
mkdir -p build-grpc
docker run \
-v `pwd`:/go/src/github.com/forseti-security/config-validator \
$(PROTO_DOCKER_IMAGE) \
python -m grpc_tools.protoc -I/proto -I./api --python_out=./build-grpc --grpc_python_out=./build-grpc ./api/validator.proto
@echo "Generated files available in ./build-grpc"
.PHONY: test
test:
GO111MODULE=on go test ./...
# Format source code, generate protos, and build policy-tool and server
.PHONY: build
build: format proto tools
# Build the Config Validator Docker iamge
.PHONY: docker_build
docker_build: build
docker build -t gcr.io/config-validator/config-validator:latest .
# Build and run the Config Validator Docker image listening on port 50052
# Set env var POLICY_LIBRARY_DIR to the local path of the policy library
.PHONY: docker_run
docker_run: guard-POLICY_LIBRARY_DIR docker_build
docker run --rm -p 50052:50052 --name config-validator \
-v $(POLICY_LIBRARY_DIR):/policy-library \
gcr.io/config-validator/config-validator:latest \
--policyPath='/policy-library/policies' \
--policyLibraryPath='/policy-library/lib' \
-port=50052 \
-v 7 \
-alsologtostderr
.PHONY: release
release: $(PLATFORMS)
.PHONY: $(PLATFORMS)
$(PLATFORMS):
GO111MODULE=on GOOS=$@ GOARCH=amd64 CGO_ENABLED=0 go build -o "${BUILD_DIR}/${NAME}-$@-amd64" cmd/server/main.go
.PHONY: clean
clean:
rm bin/${NAME}*
# Automatically format Go source code
.PHONY: format
format:
go fmt ./...
# Build policy-tool and server
.PHONY: tools
tools:
go build ./cmd/...
POLICY_TOOLS := $(foreach p,$(PLATFORMS),policy-tool-$(p))
.PHONY: $(POLICY_TOOLS)
$(POLICY_TOOLS):
GO111MODULE=on GOOS=$(subst policy-tool-,,$@) GOARCH=amd64 CGO_ENABLED=0 \
go build -o "${BUILD_DIR}/$@-amd64" cmd/policy-tool/policy-tool.go
DIRTY := $(shell git diff --no-ext-diff --quiet --exit-code || echo -n -dirty)
TAG := $(shell git log -n1 --pretty=format:%h)
IMAGE := gcr.io/config-validator/policy-tool:commit-$(TAG)$(DIRTY)
policy-tool-docker:
docker build -t $(IMAGE) -f ./build/policy-tool/Dockerfile .
docker push $(IMAGE)
# Helper target to require an env var to be set
guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi