-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile
208 lines (180 loc) · 9.34 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
203
204
205
206
207
208
.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
.PHONY: go-fmt
go-fmt: ## Run gofmt on worker and bot
$(CMD_PREFIX) gofmt -l -w .
.PHONY: go-lint
go-lint: ## Run golint on worker and bot
$(CMD_PREFIX) cd ./worker; golangci-lint run ./...
$(CMD_PREFIX) cd ./gobot; golangci-lint run ./...
.PHONY: md-lint
md-lint: ## Lint markdown files
$(ECHO_PREFIX) printf " %-12s ./...\n" "[MD LINT]"
$(CMD_PREFIX) podman run --rm -v $(CURDIR):/workdir docker.io/davidanson/markdownlint-cli2:v0.6.0 > /dev/null
.PHONY: shellcheck
shellcheck: ## Run shellcheck on scripts/*.sh
$(ECHO_PREFIX) printf " %-12s ./...\n" "[SHELLCHECK] scripts/*.sh"
$(CMD_PREFIX) if ! which shellcheck $(PIPE_DEV_NULL) ; then \
echo "Please install shellcheck." ; \
echo "https://github.com/koalaman/shellcheck#user-content-installing" ; \
exit 1 ; \
fi
$(CMD_PREFIX) shellcheck scripts/*.sh
.PHONY: ansible-lint
ansible-lint: ## Run ansible-lint on playbooks/*.yml
$(CMD_PREFIX) if ! which ansible-galaxy >/dev/null 2>&1; then \
echo "Please install ansible-galaxy." ; \
echo "See: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html" ; \
exit 1 ; \
fi
$(CMD_PREFIX) if ! which ansible-lint >/dev/null 2>&1; then \
echo "Please install ansible-lint." ; \
echo "See: https://ansible.readthedocs.io/projects/lint/installing/#installing-the-latest-version" ; \
exit 1 ; \
fi
$(CMD_PREFIX) ansible-galaxy install -r ./deploy/ansible/requirements.yml
$(ECHO_PREFIX) printf " %-12s ./...\n" "[ANSIBLE LINT]"
$(CMD_PREFIX) ansible-lint
.PHONY: png-lint
png-lint: ## Lint the png files from excalidraw
$(ECHO_PREFIX) printf " %-12s ./...\n" "[PNG LINT]"
$(CMD_PREFIX) for file in $^; do \
if echo "$$file" | grep -q --basic-regexp --file=.excalidraw-ignore; then continue ; fi ; \
if ! grep -q "excalidraw+json" $$file; then \
echo "$$file was not exported from excalidraw with 'Embed Scene' enabled." ; \
echo "If this is not an excalidraw file, add it to .excalidraw-ignore" ; \
exit 1 ; \
fi \
done
.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: ## Run Yaml linters
$(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 ./ --strict
gobot-image: gobot/Containerfile ## Build continaer image for the Go bot
$(ECHO_PREFIX) printf " %-12s gobot/Containerfile\n" "[PODMAN]"
$(CMD_PREFIX) podman build -f gobot/Containerfile -t ghcr.io/instructlab/instructlab-bot/instructlab-gobot:main .
worker-test-image: worker/Containerfile.test ## Build container image for a test worker
$(ECHO_PREFIX) printf " %-12s worker/Containerfile.test\n" "[PODMAN]"
$(CMD_PREFIX) podman build -f worker/Containerfile.test -t ghcr.io/instructlab/instructlab-bot/instructlab-serve:main .
ilabserve-base-image: worker/Containerfile.servebase ## Build container image for ilab serve
$(ECHO_PREFIX) printf " %-12s worker/Containerfile.servebase\n" "[PODMAN]"
$(CMD_PREFIX) podman build -f worker/Containerfile.servebase -t ghcr.io/instructlab/instructlab-bot/instructlab-serve-base:main .
all-images: gobot-image worker-test-image ## Build all container images
$(ECHO_PREFIX) printf " %-12s BUILD ALL CONTAINER IMAGES\n"
.PHONY: gobot
gobot: gobot/gobot ## Build gobot
gobot/gobot: $(wildcard gobot/*.go) $(wildcard gobot/*/*.go)
$(CMD_PREFIX) $(MAKE) -C gobot gobot
.PHONY: worker
worker: worker/worker ## Build worker
worker/worker: $(wildcard worker/*.go) $(wildcard worker/cmd/*.go)
$(CMD_PREFIX) $(MAKE) -C worker worker
.PHONY: push-gobot-images
push-gobot-images: ## Build gobot multi platform container images and push it to ghcr.io
$(ECHO_PREFIX) printf " %-12s gobot/Containerfile\n" "[PODMAN]"
$(CMD_PREFIX) podman build --platform linux/amd64,linux/arm64 --manifest instructlab-gobot -f gobot/Containerfile .
$(CMD_PREFIX) podman tag localhost/instructlab-gobot ghcr.io/instructlab/instructlab-bot/instructlab-gobot:main
$(CMD_PREFIX) podman manifest rm localhost/instructlab-gobot
$(CMD_PREFIX) podman manifest push --all ghcr.io/instructlab/instructlab-bot/instructlab-gobot:main
$(CMD_PREFIX) podman manifest rm ghcr.io/instructlab/instructlab-bot/instructlab-gobot:main
.PHONY: push-worker-test-images
push-worker-test-images: ## Build worker (test) multi platform container images and push it to ghcr.io
$(ECHO_PREFIX) printf " %-12s worker/Containerfile.test\n" "[PODMAN]"
$(CMD_PREFIX) podman build --platform linux/amd64,linux/arm64 --manifest instructlab-worker -f worker/Containerfile.test .
$(CMD_PREFIX) podman tag localhost/instructlab-worker ghcr.io/instructlab/instructlab-bot/instructlab-serve:main
$(CMD_PREFIX) podman manifest rm localhost/instructlab-worker
$(CMD_PREFIX) podman manifest push --all ghcr.io/instructlab/instructlab-bot/instructlab-serve:main
$(CMD_PREFIX) podman manifest rm ghcr.io/instructlab/instructlab-bot/instructlab-serve:main
.PHONY: push-images
push-images: push-gobot-images push-worker-test-images ## Build gobot and worker (test) multi platform container images and push it to ghcr.io
.PHONY: run-dev
run-dev: ## Deploy the bot development stack.
$(ECHO_PREFIX) printf " %-12s \n" "[RUN DEV STACK]"
$(CMD_PREFIX) if [ ! -f .env ]; then \
echo ".env not found. Copy .env.example to .env and configure it." ; \
exit 1 ; \
fi
$(ECHO_PREFIX) printf "Deploy the development stack\n"
$(CMD_PREFIX) podman compose -f ./deploy/compose/dev-single-worker-compose.yaml up -d
.PHONY: stop-dev
stop-dev: ## Stop the bot development stack.
$(ECHO_PREFIX) printf " %-12s \n" "[STOP DEV STACK]"
$(ECHO_PREFIX) printf "Stop the development stack\n"
$(CMD_PREFIX) podman compose -f ./deploy/compose/dev-single-worker-compose.yaml down
.PHONY: redis-stack
redis-stack: ## Run a redis-stack container
$(ECHO_PREFIX) printf " %-12s redis/redis-stack:latest\n" "[PODMAN]"
$(CMD_PREFIX) podman run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
.PHONY: deploy-aws-stack
deploy-aws-stack: ## Deploy the bot stack to AWS
$(ECHO_PREFIX) printf " %-12s \n" "[DEPLOY AWS INSTRUCT LAB BOT STACK]"
$(ECHO_PREFIX) printf "Deploy the Instruct Lab Bot stack to AWS\n"
$(CMD_PREFIX) cd ./deploy/ansible/ && ansible-playbook ./deploy-ec2-bot.yml
$(CMD_PREFIX) cd ./deploy/ansible/ && ansible-playbook -i ./inventory.txt ./deploy-bot-stack.yml
$(CMD_PREFIX) cd ./deploy/ansible/ && ansible-playbook ./deploy-ec2-worker.yml
$(CMD_PREFIX) cd ./deploy/ansible/ && ansible-playbook -i ./inventory.txt ./deploy-worker-stack.yml
.PHONY: images
images: gobot-image worker-test-image ## Build all container images
.PHONY: kind-load-images
kind-load-images: ## Load images into kind
$(ECHO_PREFIX) printf " %-12s \n" "[LOAD IMAGES INTO KIND]"
$(CMD_PREFIX) podman save ghcr.io/instructlab/instructlab-bot/instructlab-gobot:main -o /tmp/instructlab-gobot.tar
$(CMD_PREFIX) kind load image-archive --name instructlab-bot-dev /tmp/instructlab-gobot.tar
$(CMD_PREFIX) rm /tmp/instructlab-gobot.tar
$(CMD_PREFIX) podman save ghcr.io/instructlab/instructlab-bot/instructlab-serve:main -o /tmp/instructlab-serve.tar
$(CMD_PREFIX) kind load image-archive --name instructlab-bot-dev /tmp/instructlab-serve.tar
$(CMD_PREFIX) rm /tmp/instructlab-serve.tar
.PHONY: run-on-kind
run-on-kind:
$(ECHO_PREFIX) printf " %-12s \n" "[RUN ON KIND]"
$(CMD_PREFIX) if [ ! -f .env ]; then \
echo ".env not found. Copy .env.example to .env and configure it." ; \
exit 1 ; \
fi
$(CMD_PREFIX) kind create cluster --config deploy/kind.yaml
$(CMD_PREFIX) kubectl cluster-info --context kind-instructlab-bot-dev
$(CMD_PREFIX) podman save ghcr.io/instructlab/instructlab-bot/instructlab-gobot:main -o /tmp/instructlab-gobot.tar
$(CMD_PREFIX) kind load image-archive --name instructlab-bot-dev /tmp/instructlab-gobot.tar
$(CMD_PREFIX) rm /tmp/instructlab-gobot.tar
$(CMD_PREFIX) podman save ghcr.io/instructlab/instructlab-bot/instructlab-serve:main -o /tmp/instructlab-serve.tar
$(CMD_PREFIX) kind load image-archive --name instructlab-bot-dev /tmp/instructlab-serve.tar
$(CMD_PREFIX) rm /tmp/instructlab-serve.tar
$(CMD_PREFIX) kubectl create namespace instructlab-bot
$(CMD_PREFIX) kubectl create -n instructlab-bot secret generic instructlab-bot --from-env-file=.env
$(CMD_PREFIX) kubectl apply -k deploy/instructlab-bot/overlays/dev
.PHONY: docker-clean
docker-clean:
@container_ids=$$(podman ps -a --format "{{.ID}}" | awk '{print $$1}'); \
echo "removing all stopped containers (non-force)"; \
for id in $$container_ids; do \
echo "Removing container: $$id,"; \
podman rm $$id; \
done