|
| 1 | +# Image URL to use for building/pushing the frontend image |
| 2 | +IMG ?= nbv2-frontend:latest |
| 3 | + |
| 4 | +# CONTAINER_TOOL defines the container tool to be used for building images. |
| 5 | +# Tested with Docker by default. You may replace with podman. |
| 6 | +CONTAINER_TOOL ?= docker |
| 7 | + |
| 8 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 9 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 10 | +SHELL = /usr/bin/env bash -o pipefail |
| 11 | +.SHELLFLAGS = -ec |
| 12 | + |
| 13 | +.PHONY: all |
| 14 | +all: help |
| 15 | + |
| 16 | +##@ General |
| 17 | + |
| 18 | +# The help target prints all targets with descriptions organized beneath categories. |
| 19 | +.PHONY: help |
| 20 | +help: ## Display this help. |
| 21 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 22 | + |
| 23 | +##@ Clean |
| 24 | + |
| 25 | +.PHONY: clean |
| 26 | +clean: ## Remove local test/build artifacts. |
| 27 | + rm -rf ./bin ./Dockerfile.cross |
| 28 | + |
| 29 | +##@ Build |
| 30 | + |
| 31 | +# If you wish to build the image targeting other platforms you can use the --platform flag. |
| 32 | +# (i.e. docker build --platform linux/arm64). Requires Docker BuildKit. |
| 33 | +.PHONY: docker-build |
| 34 | +docker-build: ## Build docker image for the frontend. |
| 35 | + $(CONTAINER_TOOL) build -t ${IMG} . |
| 36 | + |
| 37 | +.PHONY: docker-push |
| 38 | +docker-push: ## Push docker image for the frontend. |
| 39 | + $(CONTAINER_TOOL) push ${IMG} |
| 40 | + |
| 41 | +# PLATFORMS defines the target platforms for cross-platform support. |
| 42 | +PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le |
| 43 | + |
| 44 | +.PHONY: docker-buildx |
| 45 | +docker-buildx: ## Build and push docker image for cross-platform support. |
| 46 | + # copy existing Dockerfile and insert --platform=$${BUILDPLATFORM} into Dockerfile.cross, preserving the original |
| 47 | + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross |
| 48 | + - $(CONTAINER_TOOL) buildx create --name project-v3-builder |
| 49 | + $(CONTAINER_TOOL) buildx use project-v3-builder |
| 50 | + - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . |
| 51 | + - $(CONTAINER_TOOL) buildx rm project-v3-builder |
| 52 | + rm Dockerfile.cross |
| 53 | + |
| 54 | +##@ Deployment |
| 55 | + |
| 56 | +# KUSTOMIZE_DIR point at a directory containing kustomization.yaml for the frontend deployment. |
| 57 | +# Optionally set KUSTOMIZE_IMAGE_NAME (defaults to "frontend") to the image name key used in that kustomization. |
| 58 | + |
| 59 | +.PHONY: deploy |
| 60 | +deploy: kustomize ## Deploy frontend to the K8s cluster specified in ~/.kube/config. |
| 61 | + cd manifests/kustomize/overlays/istio && $(KUSTOMIZE) edit set image workspaces-frontend=${IMG} |
| 62 | + $(KUBECTL) apply -k manifests/kustomize/overlays/istio |
| 63 | + |
| 64 | +.PHONY: undeploy |
| 65 | +undeploy: kustomize ## Undeploy frontend from the K8s cluster specified in ~/.kube/config. |
| 66 | + $(KUBECTL) delete -k manifests/kustomize/overlays/istio --ignore-not-found=true |
| 67 | + |
| 68 | + |
| 69 | +##@ Dependencies |
| 70 | + |
| 71 | +# Location to install dependencies to |
| 72 | +LOCALBIN ?= $(shell pwd)/bin |
| 73 | +$(LOCALBIN): |
| 74 | + mkdir -p $(LOCALBIN) |
| 75 | + |
| 76 | +# Tool Binaries |
| 77 | +KUBECTL ?= kubectl |
| 78 | +KUSTOMIZE ?= $(LOCALBIN)/kustomize |
| 79 | + |
| 80 | +# Tool Versions |
| 81 | +KUSTOMIZE_VERSION ?= v5.5.0 |
| 82 | + |
| 83 | +.PHONY: kustomize |
| 84 | +kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. |
| 85 | +$(KUSTOMIZE): $(LOCALBIN) |
| 86 | + $(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION)) |
| 87 | + |
| 88 | +# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist |
| 89 | +# $1 - target path with name of binary |
| 90 | +# $2 - package url which can be installed |
| 91 | +# $3 - specific version of package |
| 92 | +define go-install-tool |
| 93 | +@[ -f "$(1)-$(3)" ] || { \ |
| 94 | +set -e; \ |
| 95 | +package=$(2)@$(3) ;\ |
| 96 | +echo "Downloading $${package}" ;\ |
| 97 | +rm -f $(1) || true ;\ |
| 98 | +GOBIN=$(LOCALBIN) go install $${package} ;\ |
| 99 | +mv $(1) $(1)-$(3) ;\ |
| 100 | +} ;\ |
| 101 | +ln -sf $(1)-$(3) $(1) |
| 102 | +endef |
0 commit comments