forked from instructlab/ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
202 lines (171 loc) · 8.8 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
.PHONY: help
help:
@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)
#
# If you want to see the full commands, run:
# NOISY_BUILD=y make
#
ifeq ($(NOISY_BUILD),)
ECHO_PREFIX=@
CMD_PREFIX=@
PIPE_DEV_NULL=> /dev/null 2> /dev/null
else
ECHO_PREFIX=@\#
CMD_PREFIX=
PIPE_DEV_NULL=
endif
ILAB_KUBE_CONTEXT?=kind-instructlab-ui
ILAB_KUBE_NAMESPACE?=instructlab
ILAB_KUBE_CLUSTER_NAME?=instructlab-ui
TAG=$(shell git rev-parse HEAD)
##@ Development - Helper commands for development
.PHONY: md-lint
md-lint: ## Lint markdown files
$(ECHO_PREFIX) printf " %-12s ./...\n" "[MD LINT]"
$(CMD_PREFIX) docker run --rm -v $(CURDIR):/workdir docker.io/davidanson/markdownlint-cli2:v0.6.0 > /dev/null
.PHONY: action-lint
action-lint: ## Lint GitHub Action workflows
$(ECHO_PREFIX) printf " %-12s .github/...\n" "[ACTION LINT]"
$(CMD_PREFIX) if ! which actionlint $(PIPE_DEV_NULL) ; then \
echo "Please install actionlint." ; \
echo "go install github.com/rhysd/actionlint/cmd/actionlint@latest" ; \
exit 1 ; \
fi
$(CMD_PREFIX) actionlint -color
.PHONY: yaml-lint
yaml-lint: ## Lint yaml files
$(CMD_PREFIX) if ! which yamllint >/dev/null 2>&1; then \
echo "Please install yamllint." ; \
echo "See: https://yamllint.readthedocs.io/en/stable/quickstart.html" ; \
exit 1 ; \
fi
$(ECHO_PREFIX) printf " %-12s ./...\n" "[YAML LINT]"
$(CMD_PREFIX) yamllint -c .yamllint.yaml deploy --strict
##@ Artifacts - Command to build and publish artifacts
ui-image: Containerfile ## Build continaer image for the InstructLab UI
$(ECHO_PREFIX) printf " %-12s Containerfile\n" "[docker]"
$(CMD_PREFIX) docker build -f Containerfile -t ghcr.io/instructlab/ui/ui:$(TAG) .
$(CMD_PREFIX) docker tag ghcr.io/instructlab/ui/ui:$(TAG) ghcr.io/instructlab/ui/ui:main
ps-image: Containerfile.ps ## Build continaer image for the pathservice
$(ECHO_PREFIX) printf " %-12s Containerfile.ps\n" "[docker]"
$(CMD_PREFIX) docker build -f Containerfile.ps -t ghcr.io/instructlab/ui/pathservice:$(TAG) .
$(CMD_PREFIX) docker tag ghcr.io/instructlab/ui/pathservice:$(TAG) ghcr.io/instructlab/ui/pathservice:main
##@ Local Dev - Local machine based deployment of the UI stack
.PHONY: stop-dev-local
stop-dev-local: ## Stop the npm and pathservice local instances
$(CMD_PREFIX) echo "Stopping ui and pathservice..."
$(CMD_PREFIX) if [ -f ui.pid ]; then kill -2 `cat ui.pid` && rm ui.pid || echo "Failed to stop ui"; fi
$(CMD_PREFIX) if [ -f pathservice.pid ]; then kill -2 `cat pathservice.pid` && rm pathservice.pid || echo "Failed to stop pathservice"; fi
$(CMD_PREFIX) echo "Development environment stopped."
.PHONY: start-dev-local
start-dev-local: ## Start the npm and pathservice local instances
$(CMD_PREFIX) echo "Starting ui and pathservice..."
$(CMD_PREFIX) cd ./pathservice; go run main.go & echo $$! > ../pathservice.pid
$(CMD_PREFIX) npm run dev & echo $$! > ui.pid
$(CMD_PREFIX) echo "Development environment started."
##@ Podman Dev - Podman desktop based Deployment of the UI stack
.PHONY: stop-dev-podman
stop-dev-podman: ## Stop UI development stack running in podman
$(CMD_PREFIX) echo "Deleting UI development stack running in podman..."
$(CMD_PREFIX) podman-compose -f ./deploy/compose/ui-compose.yml down
$(CMD_PREFIX) echo "Development environment deleted."
.PHONY: start-dev-podman
start-dev-podman: ## Start UI development stack in podman
$(CMD_PREFIX) echo "Deploying UI development stack using compose..."
$(CMD_PREFIX) if [ ! -f .env ]; then \
echo "Please create a .env file in the root of the project." ; \
exit 1 ; \
fi
$(CMD_PREFIX) yes | cp -rf .env ./deploy/compose/.env
$(CMD_PREFIX) podman-compose -f ./deploy/compose/ui-compose.yml up -d
$(CMD_PREFIX) echo "Development environment started."
##@ Kubernetes - Kind cluster based dev environment
.PHONY: check-kind
check-kind:
$(CMD_PREFIX) if [ -z "$(shell which kind)" ]; then \
echo "Please install kind and then start the kind dev environment." ; \
echo "https://kind.sigs.k8s.io/" ; \
exit 1 ; \
fi
.PHONY: check-kubectl
check-kubectl:
$(CMD_PREFIX) if [ -z "$(shell which kubectl)" ]; then \
echo "Please install kubectl" ; \
echo "https://kubernetes.io/docs/tasks/tools/#kubectl" ; \
exit 1 ; \
fi
.PHONY: load-images
load-images: ## Load images onto Kind cluster
$(CMD_PREFIX) kind load --name $(ILAB_KUBE_CLUSTER_NAME) docker-image ghcr.io/instructlab/ui/ui:main
.PHONY: stop-dev-kind
stop-dev-kind: check-kind ## Stop the Kind cluster to destroy the development environment
$(CMD_PREFIX) kind delete cluster --name $(ILAB_KUBE_CLUSTER_NAME)
.PHONY: setup-kind
setup-kind: check-kind check-kubectl stop-dev ## Create a Kind cluster with ingress enabled
$(CMD_PREFIX) kind create cluster --config ./deploy/k8s/overlays/kind/kind.yaml
$(CMD_PREFIX) kubectl cluster-info
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) apply -f ./deploy/k8s/overlays/kind/kind-ingress.yaml
.PHONY: wait-for-readiness
wait-for-readiness: # Wait for operators to be ready
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) -n ingress-nginx rollout restart deployment ingress-nginx-controller
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) -n ingress-nginx rollout status deployment ingress-nginx-controller --timeout=10m
.PHONY: deploy
deploy: wait-for-readiness ## Deploy a InstructLab UI development stack onto a kubernetes cluster
$(CMD_PREFIX) if [ ! -f .env ]; then \
echo "Please create a .env file in the root of the project." ; \
exit 1 ; \
fi
$(CMD_PREFIX) yes | cp -rf .env ./deploy/k8s/overlays/kind/.env
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) apply -k ./deploy/k8s/overlays/kind
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) wait --for=condition=Ready pods -n $(ILAB_KUBE_NAMESPACE) --all -l app.kubernetes.io/part-of=ui --timeout=15m
.PHONY: redeploy
redeploy: ui-image load-images ## Redeploy the InstructLab UI stack onto a kubernetes cluster
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) -n $(ILAB_KUBE_NAMESPACE) rollout restart deploy/ui
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) -n $(ILAB_KUBE_NAMESPACE) rollout restart deploy/pathservice
.PHONY: undeploy
undeploy: ## Undeploy the InstructLab UI stack from a kubernetes cluster
$(CMD_PREFIX) if [ -f ./deploy/k8s/overlays/kind/.env ]; then \
rm ./deploy/k8s/overlays/kind/.env ; \
fi
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) delete namespace $(ILAB_KUBE_NAMESPACE)
.PHONY: start-dev-kind ## Run the development environment on Kind cluster
start-dev-kind: setup-kind deploy ## Setup a Kind cluster and deploy InstructLab UI on it
##@ OpenShift - UI prod and qa deployment on OpenShift
.PHONY: deploy-qa-openshift
deploy-qa-openshift: ## Deploy QA stack of the InstructLab UI on OpenShift
$(CMD_PREFIX) if [ ! -f .env ]; then \
echo "Please create a .env file in the root of the project." ; \
exit 1 ; \
fi
$(CMD_PREFIX) yes | cp -rf .env ./deploy/k8s/overlays/openshift/qa/.env
$(CMD_PREFIX) oc apply -k ./deploy/k8s/overlays/openshift/qa
$(CMD_PREFIX) oc wait --for=condition=Ready pods -n $(ILAB_KUBE_NAMESPACE) --all -l app.kubernetes.io/part-of=ui --timeout=15m
.PHONY: redeploy-qa-openshift
redeploy-qa-openshift: ## Redeploy QA stack of the InstructLab UI on OpenShift
$(CMD_PREFIX) oc -n $(ILAB_KUBE_NAMESPACE) rollout restart deploy/ui
$(CMD_PREFIX) oc -n $(ILAB_KUBE_NAMESPACE) rollout restart deploy/pathservice
.PHONY: undeploy-qa-openshift
undeploy-qa-openshift: ## Undeploy QA stack of the InstructLab UI on OpenShift
$(CMD_PREFIX) oc delete -k ./deploy/k8s/overlays/openshift/qa
$(CMD_PREFIX) if [ -f ./deploy/k8s/overlays/openshift/qa/.env ]; then \
rm ./deploy/k8s/overlays/openshift/qa/.env ; \
fi
.PHONY: deploy-prod-openshift
deploy-prod-openshift: ## Deploy production stack of the InstructLab UI on OpenShift
$(CMD_PREFIX) if [ ! -f .env ]; then \
echo "Please create a .env file in the root of the project." ; \
exit 1 ; \
fi
$(CMD_PREFIX) yes | cp -rf .env ./deploy/k8s/overlays/openshift/prod/.env
$(CMD_PREFIX) oc apply -k ./deploy/k8s/overlays/openshift/prod
$(CMD_PREFIX) oc wait --for=condition=Ready pods -n $(ILAB_KUBE_NAMESPACE) --all -l app.kubernetes.io/part-of=ui --timeout=15m
.PHONY: redeploy-prod-openshift
redeploy-prod-openshift: ## Redeploy production stack of the InstructLab UI on OpenShift
$(CMD_PREFIX) oc -n $(ILAB_KUBE_NAMESPACE) rollout restart deploy/ui
$(CMD_PREFIX) oc -n $(ILAB_KUBE_NAMESPACE) rollout restart deploy/pathservice
.PHONY: undeploy-prod-openshift
undeploy-prod-openshift: ## Undeploy production stack of the InstructLab UI on OpenShift
$(CMD_PREFIX) oc delete -k ./deploy/k8s/overlays/openshift/prod
$(CMD_PREFIX) if [ -f ./deploy/k8s/overlays/openshift/prod/.env ]; then \
rm ./deploy/k8s/overlays/openshift/prod/.env ; \
fi