forked from ory/hydra-maester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
192 lines (157 loc) · 5.29 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
ifeq ($(OS),Windows_NT)
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
ARCH=amd64
OS=windows
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS=linux
ARCH=amd64
endif
ifeq ($(UNAME_S),Darwin)
OS=darwin
ifeq ($(shell uname -m),x86_64)
ARCH=amd64
endif
ifeq ($(shell uname -m),arm64)
ARCH=arm64
endif
endif
endif
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/.bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
SHELL=/bin/bash -euo pipefail
export PATH := .bin:${PATH}
export PWD := $(shell pwd)
export K3SIMAGE := docker.io/rancher/k3s:v1.26.1-k3s1
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.15.0
ENVTEST_K8S_VERSION = 1.29.0
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
run-with-cleanup = $(1) && $(2) || (ret=$$?; $(2) && exit $$ret)
# find or download controller-gen
# download controller-gen if necessary
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN)
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
## Download envtest-setup locally if necessary.
.PHONY: envtest
envtest: $(ENVTEST)
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
.bin/ory: Makefile
curl https://raw.githubusercontent.com/ory/meta/master/install.sh | bash -s -- -b .bin ory
touch .bin/ory
.bin/kubectl: Makefile
@URL=$$(.bin/ory dev ci deps url -o ${OS} -a ${ARCH} -c .deps/kubectl.yaml); \
echo "Downloading 'kubectl' $${URL}...."; \
curl -Lo .bin/kubectl $${URL}; \
chmod +x .bin/kubectl;
.bin/kustomize: Makefile
@URL=$$(.bin/ory dev ci deps url -o ${OS} -a ${ARCH} -c .deps/kustomize.yaml); \
echo "Downloading 'kustomize' $${URL}...."; \
curl -L $${URL} | tar -xmz -C .bin kustomize; \
chmod +x .bin/kustomize;
.bin/k3d: Makefile
@URL=$$(.bin/ory dev ci deps url -o ${OS} -a ${ARCH} -c .deps/k3d.yaml); \
echo "Downloading 'k3d' $${URL}...."; \
curl -Lo .bin/k3d $${URL}; \
chmod +x .bin/k3d;
.PHONY: deps
deps: .bin/ory .bin/k3d .bin/kubectl .bin/kustomize
.PHONY: all
all: manager
# Run tests
.PHONY: test
test: manifests generate vet envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
.PHONY: k3d-up
k3d-up:
k3d cluster create --image $${K3SIMAGE} ory \
--k3s-arg=--kube-apiserver-arg="enable-admission-plugins=NodeRestriction,ServiceAccount@server:0" \
--k3s-arg=feature-gates="NamespaceDefaultLabelName=true@server:0";
.PHONY: k3d-down
k3d-down:
k3d cluster delete ory || true
.PHONY: k3d-deploy
k3d-deploy: manager-ci manifests docker-build-notest k3d-up
kubectl config set-context k3d-ory
k3d image load controller:latest -c ory
kubectl apply -f config/crd/bases
kustomize build config/default | kubectl apply -f -
.PHONY: k3d-test
k3d-test: k3d-deploy
kubectl config set-context k3d-ory
go install github.com/onsi/ginkgo/ginkgo@latest
USE_EXISTING_CLUSTER=true ginkgo -v ./controllers/...
# Run integration tests on local cluster
.PHONY: test-integration
test-integration:
$(call run-with-cleanup, $(MAKE) k3d-test, $(MAKE) k3d-down)
# Build manager binary
.PHONY: manager
manager: generate vet
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -a -o manager main.go
# Build manager binary for CI
.PHONY: manager-ci
manager-ci: generate vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate vet
go run ./main.go --hydra-url ${HYDRA_URL}
# Install CRDs into a cluster
.PHONY: install
install: manifests
kubectl apply -f config/crd/bases
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: manifests
kubectl apply -f config/crd/bases
kustomize build config/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Format the source code
format: .bin/ory node_modules
.bin/ory dev headers copyright --type=open-source
go fmt ./...
npm exec -- prettier --write .
# Run go vet against code
.PHONY: vet
vet:
go vet ./...
# Generate code
.PHONY: generate
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
.PHONY: docker-build-notest
docker-build-notest:
docker build . -t ${IMG} -f .docker/Dockerfile-build
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
.PHONY: docker-build
docker-build: test docker-build-notest
# Push the docker image
.PHONY: docker-push
docker-push:
docker push ${IMG}
licenses: .bin/licenses node_modules # checks open-source licenses
.bin/licenses
.bin/licenses: Makefile
curl https://raw.githubusercontent.com/ory/ci/master/licenses/install | sh
node_modules: package-lock.json
npm ci
touch node_modules