forked from snyk/policy-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
147 lines (136 loc) · 6.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
MODELS_DIR="pkg/models"
GO_SOURCE = $(shell find cmd pkg rego -type f -name '*.go') $(shell find pkg rego -type f -name '*.rego')
CLI_SOURCE = $(GO_SOURCE) go.mod go.sum
CURRENT_VERSION=$(shell awk '/^\#\# v[0-9]/ { print $$2 }' CHANGELOG.md | head -n 1 | sed 's/^v//')
GITCOMMIT=$(shell git rev-parse --short HEAD 2> /dev/null || true)
# Hardcoding -dev here to make it easier to distinguish between ad-hoc builds
# and goreleaser builds.
define LDFLAGS
-X \"github.com/snyk/policy-engine/pkg/version.Version=$(CURRENT_VERSION)-dev\"
endef
policy-engine: $(CLI_SOURCE)
go build -ldflags="$(LDFLAGS)"
demo:
go build
./policy-engine run \
-d examples/metadata \
-d examples/01-simple.rego \
-d examples/02-simple-attributes.rego \
-d examples/03-advanced.rego \
-d examples/04-advanced-resources.rego \
-d examples/05-advanced-primary-resource.rego \
-d examples/06-advanced-correlation.rego \
-d examples/07-advanced-attributes.rego \
-d examples/08-missing.rego \
examples/main.tf
swagger:
rm -f $(MODELS_DIR)/model_*.go
docker run --rm -it \
--volume $(shell pwd):/workspace \
--user $(shell id -u):$(shell id -g) \
--workdir /workspace \
swaggerapi/swagger-codegen-cli-v3 \
generate \
-i swagger.yaml \
-l go \
-o $(MODELS_DIR) \
--model-package models \
-D packageName=models
sed -i.bak \
-e 's/Object/interface\{\}/g' \
-e 's/OneOfRuleResultResourceAttributePathItems/interface\{\}/g' \
-e 's/int32/int/g' \
-e 's/\*State /State /g' \
-e 's/\*\[]SourceLocation /[]SourceLocation /g' \
-e 's/\tResources \[]RuleResultResource /\tResources []*RuleResultResource /g' \
-e 's/Type_ /Type /g' \
$(MODELS_DIR)/*.go
rm -rf \
$(MODELS_DIR)/*.bak \
$(MODELS_DIR)/.swagger-codegen \
$(MODELS_DIR)/api \
$(MODELS_DIR)/docs \
$(MODELS_DIR)/.gitignore \
$(MODELS_DIR)/.swagger-codegen-ignore \
$(MODELS_DIR)/.travis.yml \
$(MODELS_DIR)/api_default.go \
$(MODELS_DIR)/client.go \
$(MODELS_DIR)/configuration.go \
$(MODELS_DIR)/git_push.sh \
$(MODELS_DIR)/model_one_of_rule_result_resource_attribute_path_items.go \
$(MODELS_DIR)/README.md \
$(MODELS_DIR)/response.go
gofmt -w $(MODELS_DIR)/*.go
.PHONY: install_tools
install_tools:
go install github.com/golang/mock/mockgen@v1.6.0
go install github.com/goreleaser/goreleaser@v1.9.2
go install github.com/miniscruff/changie@v1.7.0
PLAIN_VERSION := $(VERSION:v%=%)
.PHONY: release
release:
@echo "Testing if $(VERSION) is set..."
test $(VERSION)
changie batch $(VERSION)
changie merge
git checkout -b release/$(PLAIN_VERSION)
git add changes CHANGELOG.md
git diff --staged
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} == y ]
git commit -m "Bump version to $(VERSION)"
git push origin release/$(PLAIN_VERSION)
@echo "Go to https://github.com/snyk/policy-engine/compare/release/$(PLAIN_VERSION)?expand=1"
TERRAFORM_VERSION=1.3.8
.PHONY: vendor_terraform
vendor_terraform:
curl -Lo terraform.zip https://github.com/hashicorp/terraform/archive/refs/tags/v$(TERRAFORM_VERSION).zip
unzip -o terraform.zip
mkdir -p pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/addrs pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/configs pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/didyoumean pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/experiments pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/getproviders pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/httpclient pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/instances pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/lang pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/logging pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/modsdir pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/registry pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/tfdiags pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/getmodules pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/depsfile pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/ipaddr pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/providers pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/replacefile pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/copy pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/states pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/checks pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/terraform pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/dag pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/plans pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/provisioners pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/internal/refactoring pkg/internal/terraform
cp -r terraform-$(TERRAFORM_VERSION)/version pkg/internal/terraform
cp terraform-$(TERRAFORM_VERSION)/LICENSE pkg/internal/terraform
find pkg/internal/terraform/ -name '*.go' \
-exec sed -i".bak" 's#github\.com/hashicorp/terraform/internal/#github.com/snyk/policy-engine/pkg/internal/terraform/#' '{}' \;
find pkg/internal/terraform/ -name '*.go' \
-exec sed -i".bak" 's#github\.com/hashicorp/terraform/version#github.com/snyk/policy-engine/pkg/internal/terraform/version#' '{}' \;
find pkg/internal/terraform/ -name '*.bak' -delete
find pkg/internal/terraform/ -name '*_test.go' -delete
git apply patches/terraform.patch
go mod tidy
rm -rf terraform.zip terraform-$(TERRAFORM_VERSION)
# Produce extra files that should be attached to releases:
#
# - capabilities.json
# - regolib.tar.gz
.PHONY: release_extra_files
release_extra_files:
mkdir -p release_extra_files/
go run . capabilities >release_extra_files/capabilities.json
find rego -name '*.rego' \
-and -not -name '*_test.rego' \
-and -not -name '*_example.rego' | \
xargs tar -czf release_extra_files/regolib.tar.gz