-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
98 lines (79 loc) · 3.92 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
.DEFAULT_GOAL := all
CHART := idam-web-public
RELEASE := ${CHART}-pr-${PR}
NAMESPACE := idam
TEST := ${RELEASE}-test-service
ACR := hmctspublic
ACR_SUBSCRIPTION := DCD-CNP-Dev
AKS_RESOURCE_GROUP := cnp-aks-rg
AKS_CLUSTER := cnp-aks-cluster
HELM_INSTALLED := $(command -v helm)
UNAME := $(uname)
# Usage example: make <command> PR='123'
setup:
- @if [ -z "${HELM_INSTALLED}" ] && [[ "${UNAME}" == 'Darwin' ]]; then \
brew install helm ; \
elif $$(helm version | grep -q 'v2'); then \
brew upgrade helm ; \
fi
@az account set --subscription ${ACR_SUBSCRIPTION}
@az configure --defaults acr=${ACR}
@az acr helm repo add
@az aks get-credentials --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_CLUSTER}
- @if [ ! -d $${HOME}/.helm ]; then \
helm init --client-only ; \
fi
clean:
- @helm uninstall --namespace ${NAMESPACE} ${RELEASE}
- @for i in $$(kubectl -n ${NAMESPACE} get deploy -o name | grep ${RELEASE}); do \
kubectl -n ${NAMESPACE} delete $${i} --grace-period=0 --force ; \
done
- @for i in $$(kubectl -n ${NAMESPACE} get rs -o name | grep ${RELEASE}); do \
kubectl -n ${NAMESPACE} delete $${i} --grace-period=0 --force ; \
done
- @for i in $$(kubectl -n ${NAMESPACE} get pod -o name | grep ${RELEASE}); do \
kubectl -n ${NAMESPACE} delete $${i} --grace-period=0 --force ; \
done
update:
helm dependency update charts/${CHART}
lint:
helm lint charts/${CHART}
template:
helm template ${RELEASE} --set "java.releaseNameOverride=${RELEASE}" --namespace ${NAMESPACE} charts/${CHART}
dry-run:
helm install ${RELEASE} --set "java.releaseNameOverride=${RELEASE}" --namespace ${NAMESPACE} --dry-run --timeout 30s --atomic charts/${CHART}
deploy:
helm install ${RELEASE} --set "java.releaseNameOverride=${RELEASE}" --set "java.replicas=1" --namespace ${NAMESPACE} --wait --timeout 8m charts/${CHART}
test:
helm test ${RELEASE} --namespace ${NAMESPACE}
force-update-pods:
@kubectl -n ${NAMESPACE} scale --current-replicas=2 --replicas=0 deploy/idam-api
@kubectl -n ${NAMESPACE} patch deploy idam-api -p '{"spec":{"template":{"spec":{"containers":[{"name":"idam-api", "imagePullPolicy": "Always"}]}}}}'
@kubectl -n ${NAMESPACE} scale --current-replicas=0 --replicas=2 deploy/idam-api
@kubectl -n ${NAMESPACE} scale --current-replicas=2 --replicas=0 deploy/idam-web-public
@kubectl -n ${NAMESPACE} patch deploy idam-web-public -p '{"spec":{"template":{"spec":{"containers":[{"name":"idam-web-public", "imagePullPolicy": "Always"}]}}}}'
@kubectl -n ${NAMESPACE} scale --current-replicas=0 --replicas=2 deploy/idam-web-public
@kubectl -n ${NAMESPACE} scale --current-replicas=1 --replicas=0 deploy/idam-web-admin
@kubectl -n ${NAMESPACE} patch deploy idam-web-admin -p '{"spec":{"template":{"spec":{"containers":[{"name":"idam-web-admin", "imagePullPolicy": "Always"}]}}}}'
@kubectl -n ${NAMESPACE} scale --current-replicas=0 --replicas=1 deploy/idam-web-admin
@echo Done
logs:
@echo "Use the spacebar to page and 'q' to exit."
@sleep 2
@kubectl -n ${NAMESPACE} logs $$(kubectl -n ${NAMESPACE} get deployments -o name | grep ${RELEASE} | awk NR==1) | more
# make port-forward PR='257'
port-forward:
@echo -e "Killing kubectl pids on 8080.\nStarting port-forward.\nCtrl-C to exit."
@kill $$(lsof -i tcp:8080 | grep kubectl | awk '{print $$2}') 2>&1 || echo 'No processes to kill.'
@sleep 1
@kubectl -n ${NAMESPACE} port-forward deployment/${RELEASE} 8080:8080 &
@open 'http://localhost:8080/login?client_id=test-public-service&redirect_uri=https://test-public-service.com'
deployment:
@kubectl -n ${NAMESPACE} describe $$(kubectl -n ${NAMESPACE} get deployments -o name | grep ${RELEASE})
pods:
@kubectl -n ${NAMESPACE} describe $$(kubectl -n ${NAMESPACE} get pods -o name | grep ${RELEASE})
events:
@kubectl -n ${NAMESPACE} describe $$(kubectl -n ${NAMESPACE} get pods -o name | grep ${RELEASE}) | grep -A 3 Events
redeploy: clean deploy
all: setup update clean lint deploy test
.PHONY: setup clean lint deploy test all