forked from ZupIT/horusec-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (110 loc) · 5.38 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
GO ?= go
GOFMT ?= gofmt
GO_FILES ?= $$(find . -name '*.go' | grep -v vendor)
GOLANG_CI_LINT ?= $(shell pwd)/bin/golangci-lint
GO_IMPORTS ?= goimports
GO_IMPORTS_LOCAL ?= github.com/ZupIT/horusec-operator
HORUSEC ?= horusec
CONTROLLER_GEN ?= $(shell pwd)/bin/controller-gen
KUSTOMIZE ?= $(shell pwd)/bin/kustomize
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
OPERATOR_VERSION ?= $(shell semver get release)
REGISTRY_IMAGE ?= horuszup/horusec-operator:${OPERATOR_VERSION}
ADDLICENSE ?= addlicense
fmt: # Check fmt in application
$(GOFMT) -w $(GO_FILES)
lint: # Check lint in application
ifeq ($(wildcard $(GOLANG_CI_LINT)), $(GOLANG_CI_LINT))
$(GOLANG_CI_LINT) run -v --timeout=5m -c .golangci.yml ./...
else
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s latest
$(GOLANG_CI_LINT) run -v --timeout=5m -c .golangci.yml ./...
endif
coverage: # Check coverage in application
curl -fsSL https://raw.githubusercontent.com/ZupIT/horusec-devkit/main/scripts/coverage.sh | bash -s 0 .
tests: # Run all tests in application
$(GO) clean -testcache && $(GO) test -v ./... -timeout=2m -parallel=1 -failfast -short
fix-imports: # Setup all imports to default mode
ifeq (, $(shell which $(GO_IMPORTS)))
$(GO) get -u golang.org/x/tools/cmd/goimports
$(GO_IMPORTS) -local $(GO_IMPORTS_LOCAL) -w $(GO_FILES)
else
$(GO_IMPORTS) -local $(GO_IMPORTS_LOCAL) -w $(GO_FILES)
endif
security: # Run security pipeline
ifeq (, $(shell which $(HORUSEC)))
curl -fsSL https://raw.githubusercontent.com/ZupIT/horusec/master/deployments/scripts/install.sh | bash -s latest
$(HORUSEC) start -p="./" -e="true"
else
$(HORUSEC) start -p="./" -e="true"
endif
build: # Build operator image
$(GO) build -o "./tmp/bin/operator" ./cmd/app
pipeline: fmt fix-imports lint test coverage build security # Run all processes of the pipeline
up-sample: # Up all dev dependencies kubernetes
chmod +x ./config/samples/sample_install_dependencies.sh
./config/samples/sample_install_dependencies.sh
apply-sample: # Apply yaml in kubernetes
kubectl apply -f ./config/samples/install_v2alpha1_horusecplatform.yaml
replace-sample: # Replace to re-apply yaml in kubernetes
kubectl replace -f ./config/samples/install_v2alpha1_horusecplatform.yaml
install-semver: # Install semver binary
curl -fsSL https://raw.githubusercontent.com/ZupIT/horusec-devkit/main/scripts/install-semver.sh | bash
docker-up-alpha: # Update alpha in docker image
chmod +x ./deployments/scripts/update-image.sh
./deployments/scripts/update-image.sh alpha false
docker-up-rc: # Update rc in docker image
chmod +x ./deployments/scripts/update-image.sh
./deployments/scripts/update-image.sh rc false
docker-up-release: # Update release in docker image
chmod +x ./deployments/scripts/update-image.sh
./deployments/scripts/update-image.sh release false
docker-up-release-latest: # Update release and latest in docker image
chmod +x ./deployments/scripts/update-image.sh
./deployments/scripts/update-image.sh release true
docker-up-minor-latest: # Update minor and latest in docker image
chmod +x ./deployments/scripts/update-image.sh
./deployments/scripts/update-image.sh minor true
######### Operator commands #########
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
kustomize: # Install kustomize binary
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
controller-gen: # Install controller-gen binary
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
manifests: controller-gen # Update all manifests in config
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config="./config/crd/bases"
generate: controller-gen # Generate new controller
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
generate-service-yaml: kustomize install-semver
mkdir -p $(shell pwd)/tmp
cd config/manager && $(KUSTOMIZE) edit set image controller=$(REGISTRY_IMAGE)
$(KUSTOMIZE) build config/default > $(shell pwd)/tmp/horusec-operator.yaml
install: manifests kustomize # install horusec crd in kubernetes
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize # uninstall horusec crd in kubernetes
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize install-semver # deploy horusec-operator in environment
cd config/manager && $(KUSTOMIZE) edit set image controller=$(REGISTRY_IMAGE)
$(KUSTOMIZE) build config/default | kubectl apply -f -
undeploy: # undeploy horusec-operator in environment
$(KUSTOMIZE) build config/default | kubectl delete -f -
mock: # generate source code for a mock
mockgen -package=test -destination test/kubernetes_client.go -source=internal/horusec/usecase/kubeclient.go KubernetesClient
license:
$(GO) get -u github.com/google/addlicense
@$(ADDLICENSE) -check -f ./copyright.txt $(shell find -regex '.*\.\(go\|js\|ts\|yml\|yaml\|sh\|dockerfile\)')
license-fix:
$(GO) get -u github.com/google/addlicense
@$(ADDLICENSE) -f ./copyright.txt $(shell find -regex '.*\.\(go\|js\|ts\|yml\|yaml\|sh\|dockerfile\)')