This repository has been archived by the owner on Oct 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.local
67 lines (56 loc) · 2.69 KB
/
Makefile.local
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
LOCAL_BIN = $(PWD)/bin
LOCAL_TMP = $(PWD)/tmp
PATH:=$(LOCAL_BIN):$(PATH) # Use our local stuff first
ARCH = amd64
OS = $(shell uname -s | tr A-Z a-z)
LOCAL_DOMAIN=monetr.mini
WEB_UI_IMAGE_NAME=web-ui
MINIKUBE=minikube
KUBECTL=$(MINIKUBE) kubectl --
YQ=$(LOCAL_BIN)/yq
$(LOCAL_BIN):
mkdir -p $(LOCAL_BIN)
YQ_VERSION=v4.7.1
YQ_BINARY=yq_$(OS)_$(ARCH)
YQ_URL=https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/$(YQ_BINARY).tar.gz
YQ_DIR=$(LOCAL_TMP)/yq
$(YQ): $(LOCAL_BIN)
rm -rf $(YQ_DIR) || true
mkdir -p $(YQ_DIR)
curl -L $(YQ_URL) -o $(YQ_DIR).tar.gz
tar -xzf $(YQ_DIR).tar.gz -C $(YQ_DIR)
mv $(YQ_DIR)/yq_$(OS)_$(ARCH) $(YQ)
rm -rf $(YQ_DIR) || true
MINIKUBE_NAMESPACE=default
WEB_UI_NAME=web-ui
LOCAL_WEB_UI_DEPLOY=$(PWD)/minikube/$(WEB_UI_NAME).yaml
SRC_HASH=$(shell find -s $(PWD)/src -type f -exec shasum {} \; | shasum | cut -d " " -f 1)
BASE_IMAGE_NAME = registry.$(LOCAL_DOMAIN)/$(WEB_UI_IMAGE_NAME)
IMAGE_NAME = $(BASE_IMAGE_NAME):$(SRC_HASH)
LOCAL_RELEASE_STR=$(shell printf "LOCAL-%s-%s" $$(date -u +%Y.%m.%d.%H.%M) $$(git config user.email))
build-web-ui-mini: build
eval $$(minikube docker-env) && docker build \
--cache-from=$(BASE_IMAGE_NAME):latest \
-t $(IMAGE_NAME) \
-t $(BASE_IMAGE_NAME):latest \
-f Dockerfile.local . && \
docker push $(IMAGE_NAME) && \
docker push $(BASE_IMAGE_NAME):latest
# yq e '.image.tag = "$(SRC_HASH)"' -i $(VALUES)
deploy-web-ui: build-web-ui-mini
$(KUBECTL) apply -f $(LOCAL_WEB_UI_DEPLOY) --namespace $(MINIKUBE_NAMESPACE)
$(KUBECTL) rollout status deploy/$(WEB_UI_NAME) --namespace $(MINIKUBE_NAMESPACE) --timeout=30s
###################### DEBUGGING THE WEB UI ##################################
LOCAL_IP=$(shell ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $$2 }' | cut -f2 -d: | head -n1)
local-ui: $(YQ)
LOCAL_IP=$(LOCAL_IP) $(YQ) e '.subsets[0].addresses[0].ip = strenv(LOCAL_IP)' $(PWD)/minikube/ui-endpoint.yaml | $(KUBECTL) apply -f -
$(KUBECTL) get svc/$(WEB_UI_NAME) -n $(MINIKUBE_NAMESPACE) -o yaml | $(YQ) e 'del(.spec.selector)' - | $(KUBECTL) apply -f -
$(KUBECTL) scale deploy/$(WEB_UI_NAME) --replicas=0 -n $(MINIKUBE_NAMESPACE) || true
ifdef TMUX # If the user is already in tmux then just spawn a new session and switch to it.
tmux new -s local-ui -d 'make start' && tmux switch -t local-ui || true
else # If the user is not, start a new session and then enter tmux to attach.
tmux new -s local-ui -d 'make start' && tmux attach -t local-ui || true
endif
$(KUBECTL) delete svc/$(WEB_UI_NAME) --namespace $(MINIKUBE_NAMESPACE)
$(KUBECTL) apply -f $(LOCAL_WEB_UI_DEPLOY) --namespace $(MINIKUBE_NAMESPACE)
$(KUBECTL) scale deploy/$(WEB_UI_NAME) --replicas=1 -n $(MINIKUBE_NAMESPACE) || true