chore: improve ci process (#130)
This commit is contained in:
127
Makefile
127
Makefile
@ -11,10 +11,14 @@ else
|
||||
endif
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
OS=darwin
|
||||
ARCH=amd64
|
||||
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
|
||||
@ -22,22 +26,63 @@ 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
|
||||
KUSTOMIZE ?= $(LOCALBIN)/kustomize
|
||||
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
|
||||
ENVTEST ?= $(LOCALBIN)/setup-envtest
|
||||
|
||||
## Tool Versions
|
||||
KUSTOMIZE_VERSION ?= v5.1.1
|
||||
CONTROLLER_TOOLS_VERSION ?= v0.11.3
|
||||
ENVTEST_K8S_VERSION = 1.26.1
|
||||
|
||||
HELL=/bin/bash -o pipefail
|
||||
# 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
|
||||
|
||||
@ -46,36 +91,33 @@ all: manager
|
||||
test: manifests generate vet envtest
|
||||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
|
||||
|
||||
# Start KIND pseudo-cluster
|
||||
.PHONY: kind-start
|
||||
kind-start:
|
||||
kind create cluster
|
||||
.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";
|
||||
|
||||
# Stop KIND pseudo-cluster
|
||||
.PHONY: kind-stop
|
||||
kind-stop:
|
||||
kind delete cluster
|
||||
.PHONY: k3d-down
|
||||
k3d-down:
|
||||
k3d cluster delete ory || true
|
||||
|
||||
# Deploy on KIND
|
||||
# Ensures the controller image is built, deploys the image to KIND cluster along with necessary configuration
|
||||
.PHONY: kind-deploy
|
||||
kind-deploy: manager manifests docker-build-notest kind-start kustomize
|
||||
kubectl config set-context kind-kind
|
||||
kind load docker-image controller:latest
|
||||
.PHONY: k3d-deploy
|
||||
k3d-deploy: manager 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 -
|
||||
kustomize build config/default | kubectl apply -f -
|
||||
|
||||
# private
|
||||
.PHONY: kind-test
|
||||
kind-test: kind-deploy
|
||||
kubectl config set-context kind-kind
|
||||
.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 KIND cluster
|
||||
# Run integration tests on local cluster
|
||||
.PHONY: test-integration
|
||||
test-integration:
|
||||
$(call run-with-cleanup, $(MAKE) kind-test, $(MAKE) kind-stop)
|
||||
$(call run-with-cleanup, $(MAKE) k3d-test, $(MAKE) k3d-down)
|
||||
|
||||
# Build manager binary
|
||||
.PHONY: manager
|
||||
@ -94,9 +136,9 @@ install: manifests
|
||||
|
||||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
|
||||
.PHONY: deploy
|
||||
deploy: manifests kustomize
|
||||
deploy: manifests
|
||||
kubectl apply -f config/crd/bases
|
||||
$(KUSTOMIZE) build config/default | kubectl apply -f -
|
||||
kustomize build config/default | kubectl apply -f -
|
||||
|
||||
# Generate manifests e.g. CRD, RBAC etc.
|
||||
.PHONY: manifests
|
||||
@ -134,35 +176,6 @@ docker-build: test docker-build-notest
|
||||
docker-push:
|
||||
docker push ${IMG}
|
||||
|
||||
## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
|
||||
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
|
||||
.PHONY: kustomize
|
||||
kustomize: $(KUSTOMIZE)
|
||||
$(KUSTOMIZE): $(LOCALBIN)
|
||||
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
|
||||
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
|
||||
rm -rf $(LOCALBIN)/kustomize; \
|
||||
fi
|
||||
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) --output install_kustomize.sh && bash install_kustomize.sh $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); rm install_kustomize.sh; }
|
||||
|
||||
# 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 v0.1.48
|
||||
touch .bin/ory
|
||||
|
||||
licenses: .bin/licenses node_modules # checks open-source licenses
|
||||
.bin/licenses
|
||||
|
||||
|
Reference in New Issue
Block a user