-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
166 lines (129 loc) · 5.98 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
###### Help ###################################################################
.DEFAULT_GOAL = help
.PHONY: help
help: ## list Makefile targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
###### Setup ##################################################################
IAAS=gcp
CSB_VERSION := $(or $(CSB_VERSION), $(shell grep 'github.com/cloudfoundry/cloud-service-broker' go.mod | grep -v replace | awk '{print $$NF}' | sed -e 's/v//'))
CSB_RELEASE_VERSION := $(CSB_VERSION)
####### broker environment variables
SECURITY_USER_NAME := $(or $(SECURITY_USER_NAME), gcp-broker)
SECURITY_USER_PASSWORD := $(or $(SECURITY_USER_PASSWORD), gcp-broker-pw)
GSB_PROVISION_DEFAULTS := $(or $(GSB_PROVISION_DEFAULTS), {"authorized_network_id": "https://www.googleapis.com/compute/v1/projects/$GOOGLE_PROJECT/global/networks/$GCP_PAS_NETWORK"})
BROKER_GO_OPTS=PORT=8080 \
DB_TYPE=sqlite3 \
DB_PATH=/tmp/csb-db \
SECURITY_USER_NAME=$(SECURITY_USER_NAME) \
SECURITY_USER_PASSWORD=$(SECURITY_USER_PASSWORD) \
GOOGLE_CREDENTIALS='$(GOOGLE_CREDENTIALS)' \
GOOGLE_PROJECT=$(GOOGLE_PROJECT) \
PAK_BUILD_CACHE_PATH=$(PAK_BUILD_CACHE_PATH) \
GSB_PROVISION_DEFAULTS='$(GSB_PROVISION_DEFAULTS)' \
GSB_SERVICE_CSB_GOOGLE_POSTGRES_PLANS='$(GSB_SERVICE_CSB_GOOGLE_POSTGRES_PLANS)' \
GSB_SERVICE_CSB_GOOGLE_MYSQL_PLANS='$(GSB_SERVICE_CSB_GOOGLE_MYSQL_PLANS)' \
GSB_SERVICE_CSB_GOOGLE_STORAGE_BUCKET_PLANS='$(GSB_SERVICE_CSB_GOOGLE_STORAGE_BUCKET_PLANS)' \
GSB_COMPATIBILITY_ENABLE_BETA_SERVICES=$(GSB_COMPATIBILITY_ENABLE_BETA_SERVICES)
PAK_PATH=$(PWD) #where the brokerpak zip resides
RUN_CSB=$(BROKER_GO_OPTS) go run github.com/cloudfoundry/cloud-service-broker/v2
LDFLAGS="-X github.com/cloudfoundry/cloud-service-broker/v2/utils.Version=$(CSB_VERSION)"
GET_CSB="env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) github.com/cloudfoundry/cloud-service-broker/v2"
###### Targets ################################################################
.PHONY: build
build: $(IAAS)-services-*.brokerpak ## build brokerpak
$(IAAS)-services-*.brokerpak: *.yml terraform/*/*/*.tf | $(PAK_BUILD_CACHE_PATH)
$(RUN_CSB) pak build
.PHONY: run
run: google_credentials google_project ## start CSB
$(RUN_CSB) pak build --target current
$(RUN_CSB) serve
.PHONY: docs
docs: build brokerpak-user-docs.md ## build docs
brokerpak-user-docs.md: *.yml
$(RUN_CSB) pak docs $(PAK_PATH)/$(shell ls *.brokerpak) > $@ # GO
.PHONY: examples
examples: ## display available examples
$(RUN_CSB) examples
.PHONY: run-examples
run-examples: ## run examples tests, set service_name and/or example_name
$(RUN_CSB) run-examples --service-name="$(service_name)" --example-name="$(example_name)"
.PHONY: test ## run the tests
test: lint run-integration-tests
.PHONY: run-integration-tests
run-integration-tests: ## run integration tests for this brokerpak
cd ./integration-tests && go run github.com/onsi/ginkgo/v2/ginkgo -r .
.PHONY: run-terraform-tests
run-terraform-tests: ## run terraform tests for this brokerpak
cd ./terraform-tests && go run github.com/onsi/ginkgo/v2/ginkgo -r .
.PHONY: info
info: build ## use the CSB to parse the buildpak and print out contents and versions
$(RUN_CSB) pak info $(PAK_PATH)/$(shell ls *.brokerpak)
.PHONY: validate
validate: build ## use the CSB to validate the buildpak
$(RUN_CSB) pak validate $(PAK_PATH)/$(shell ls *.brokerpak)
# fetching bits for cf push broker
.PHONY: cloud-service-broker
cloud-service-broker: go.mod ## build or fetch CSB binary
"$(GET_CSB)"
APP_NAME := $(or $(APP_NAME), cloud-service-broker-gcp)
DB_TLS := $(or $(DB_TLS), skip-verify)
.PHONY: push-broker
push-broker: cloud-service-broker build google_credentials google_project gcp_pas_network ## push the broker to targeted Cloud Foundry
MANIFEST=cf-manifest.yml APP_NAME=$(APP_NAME) DB_TLS=$(DB_TLS) GSB_PROVISION_DEFAULTS='$(GSB_PROVISION_DEFAULTS)' ./scripts/push-broker.sh
.PHONY: google_credentials
google_credentials:
ifndef GOOGLE_CREDENTIALS
$(error variable GOOGLE_CREDENTIALS not defined)
endif
.PHONY: google_project
google_project:
ifndef GOOGLE_PROJECT
$(error variable GOOGLE_PROJECT not defined)
endif
.PHONY: gcp_pas_network
gcp_pas_network:
ifndef GCP_PAS_NETWORK
$(error variable GCP_PAS_NETWORK not defined - must be GCP network for PAS foundation)
endif
.PHONY: clean
clean: ## clean up build artifacts
- rm -f $(IAAS)-services-*.brokerpak
- rm -f ./cloud-service-broker
- rm -f ./brokerpak-user-docs.md
$(PAK_BUILD_CACHE_PATH):
@echo "Folder $(PAK_BUILD_CACHE_PATH) does not exist. Creating it..."
mkdir -p $@
.PHONY: latest-csb
latest-csb: ## point to the very latest CSB on GitHub
go get -d github.com/cloudfoundry/cloud-service-broker@main
go mod tidy
.PHONY: local-csb
local-csb: ## point to a local CSB repo
echo "replace \"github.com/cloudfoundry/cloud-service-broker/v2\" => \"$$PWD/../cloud-service-broker\"" >>go.mod
go mod tidy
.PHONY: lint
lint: checkgoformat checkgoimports checktfformat vet staticcheck ## checks format, imports and vet
checktfformat: ## checks that Terraform HCL is formatted correctly
@@if [ "$$(terraform fmt -recursive --check)" ]; then \
echo "terraform fmt check failed: run 'make format'"; \
exit 1; \
fi
checkgoformat: ## checks that the Go code is formatted correctly
@@if [ -n "$$(gofmt -s -e -l -d .)" ]; then \
echo "gofmt check failed: run 'make format'"; \
exit 1; \
fi
checkgoimports: ## checks that Go imports are formatted correctly
@@if [ -n "$$(go run golang.org/x/tools/cmd/goimports -l -d .)" ]; then \
echo "goimports check failed: run 'make format'"; \
exit 1; \
fi
vet: ## Runs go vet
go vet ./...
staticcheck: ## Runs staticcheck
go run honnef.co/go/tools/cmd/staticcheck ./...
.PHONY: format
format: ## format the source
gofmt -s -e -l -w .
go run golang.org/x/tools/cmd/goimports -l -w .
terraform fmt --recursive