|
| 1 | +GIT_COMMIT := $(shell git rev-parse HEAD) |
| 2 | +GIT_TREE_STATE := $(shell test -n "`git status --porcelain`" && echo "-dirty" || echo "") |
| 3 | + |
| 4 | +# Image URL to use all building/pushing image targets |
| 5 | +REGISTRY ?= ghcr.io/kubeflow/notebooks |
| 6 | +TAG ?= sha-$(GIT_COMMIT)$(GIT_TREE_STATE) |
| 7 | + |
| 8 | +CONTROLLER_NAME ?= workspaces-controller |
| 9 | +CONTROLLER_IMG ?= $(REGISTRY)/$(CONTROLLER_NAME):$(TAG) |
| 10 | + |
| 11 | +BACKEND_NAME ?= workspaces-backend |
| 12 | +BACKEND_IMG ?= $(REGISTRY)/$(BACKEND_NAME):$(TAG) |
| 13 | + |
| 14 | +FRONTEND_NAME ?= workspaces-frontend |
| 15 | +FRONTEND_IMG ?= $(REGISTRY)/$(FRONTEND_NAME):$(TAG) |
| 16 | + |
| 17 | +KIND_CLUSTER_NAME ?= local-e2e |
| 18 | + |
| 19 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 20 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 21 | +SHELL = /usr/bin/env bash -o pipefail |
| 22 | +.SHELLFLAGS = -ec |
| 23 | + |
| 24 | +# Export KIND_EXPERIMENTAL_PROVIDER to honor it if set in user's environment |
| 25 | +# (e.g., KIND_EXPERIMENTAL_PROVIDER=podman for podman support) |
| 26 | +export KIND_EXPERIMENTAL_PROVIDER |
| 27 | + |
| 28 | +##@ General |
| 29 | + |
| 30 | +# The help target prints out all targets with their descriptions organized |
| 31 | +# beneath their categories. The categories are represented by '##@' and the |
| 32 | +# target descriptions by '##'. The awk command is responsible for reading the |
| 33 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 34 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 35 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 36 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 37 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 38 | +# More info on the awk command: |
| 39 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 40 | + |
| 41 | +.PHONY: help |
| 42 | +help: ## Display this help. |
| 43 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 44 | + |
| 45 | +##@ Deployment |
| 46 | + |
| 47 | +.PHONY: setup-cluster |
| 48 | +setup-cluster: check-kubectl check-kind ## Set up a complete kind cluster with cert-manager and Istio. |
| 49 | + bash scripts/setup-kind.sh |
| 50 | + bash scripts/setup-cert-manager.sh |
| 51 | + bash scripts/setup-istio.sh |
| 52 | + |
| 53 | +.PHONY: teardown-cluster |
| 54 | +teardown-cluster: check-kind ## Delete the Kind cluster. |
| 55 | + kind delete cluster --name $(KIND_CLUSTER_NAME) |
| 56 | + |
| 57 | +.PHONY: deploy-controller |
| 58 | +deploy-controller: check-kind check-kind-context ## Build and deploy the controller. |
| 59 | + $(MAKE) -C ../workspaces/controller docker-build IMG=$(CONTROLLER_IMG) |
| 60 | + kind load docker-image $(CONTROLLER_IMG) --name $(KIND_CLUSTER_NAME) |
| 61 | + $(MAKE) -C ../workspaces/controller deploy IMG=$(CONTROLLER_IMG) |
| 62 | + |
| 63 | +.PHONY: deploy-backend |
| 64 | +deploy-backend: check-kind check-kind-context ## Build and deploy the backend. |
| 65 | + $(MAKE) -C ../workspaces/backend docker-build IMG=$(BACKEND_IMG) |
| 66 | + kind load docker-image $(BACKEND_IMG) --name $(KIND_CLUSTER_NAME) |
| 67 | + $(MAKE) -C ../workspaces/backend deploy IMG=$(BACKEND_IMG) |
| 68 | + |
| 69 | +.PHONY: deploy-frontend |
| 70 | +deploy-frontend: check-kind check-kind-context ## Build and deploy the frontend. |
| 71 | + $(MAKE) -C ../workspaces/frontend docker-build IMG=$(FRONTEND_IMG) |
| 72 | + kind load docker-image $(FRONTEND_IMG) --name $(KIND_CLUSTER_NAME) |
| 73 | + $(MAKE) -C ../workspaces/frontend deploy IMG=$(FRONTEND_IMG) |
| 74 | + |
| 75 | +.PHONY: deploy-all |
| 76 | +deploy-all: deploy-controller deploy-backend deploy-frontend ## Deploy all components. |
| 77 | + |
| 78 | +##@ E2E Tests |
| 79 | + |
| 80 | +.PHONY: sanity-check |
| 81 | +sanity-check: check-kind-context ## Verify all components are deployed and responding. |
| 82 | + @bash scripts/sanity-check.sh |
| 83 | + |
| 84 | +.PHONY: local-e2e |
| 85 | +local-e2e: ## Run e2e tests. |
| 86 | + @echo "..." |
| 87 | + @echo "TODO: there are no e2e tests yet, they will be defined in Cypress..." |
| 88 | + @echo "..." |
| 89 | + |
| 90 | +##@ Dependencies |
| 91 | + |
| 92 | +## Location to install dependencies to |
| 93 | +LOCALBIN ?= $(shell pwd)/bin |
| 94 | +$(LOCALBIN): |
| 95 | + mkdir -p $(LOCALBIN) |
| 96 | + |
| 97 | +.PHONY: check-kind |
| 98 | +check-kind: ## Verify that kind is available in PATH. |
| 99 | + @command -v kind >/dev/null 2>&1 || { \ |
| 100 | + echo "ERROR: kind is not found in PATH. Please install kind."; \ |
| 101 | + exit 1; \ |
| 102 | + } |
| 103 | + |
| 104 | +.PHONY: check-kind-context |
| 105 | +check-kind-context: ## Verify that the current kubectl context is set to the expected kind cluster. |
| 106 | + @{ \ |
| 107 | + current_context=$$(kubectl config current-context); \ |
| 108 | + expected_context="kind-$(KIND_CLUSTER_NAME)"; \ |
| 109 | + if [ "$$current_context" != "$$expected_context" ]; then \ |
| 110 | + echo "ERROR: Current kubectl context is '$$current_context', but expected '$$expected_context'."; \ |
| 111 | + echo "ERROR: switch to the correct context using: kubectl config use-context $$expected_context"; \ |
| 112 | + exit 1; \ |
| 113 | + fi; \ |
| 114 | + } |
| 115 | + |
| 116 | +.PHONY: check-kubectl |
| 117 | +check-kubectl: ## Verify that kubectl is available in PATH. |
| 118 | + @command -v kubectl >/dev/null 2>&1 || { \ |
| 119 | + echo "ERROR: kubectl is not found in PATH. Please install kubectl."; \ |
| 120 | + exit 1; \ |
| 121 | + } |
| 122 | + |
| 123 | +.PHONY: clean |
| 124 | +clean: ## Remove downloaded tool binaries. |
| 125 | + rm -rf $(LOCALBIN) |
| 126 | + @echo "INFO: '$(LOCALBIN)' successfully cleaned." |
0 commit comments