-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTaskfile.yml
192 lines (169 loc) · 8.27 KB
/
Taskfile.yml
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
version: '3'
tasks:
docs:
desc: Generate the docs
cmds:
- go run cmd/help/main.go --dir docs/cli
lint:
desc: Run linting tools
cmds:
- golangci-lint run ./...
- go vet ./...
lint-fix:
desc: Run linting tools, and apply fixes.
cmds:
- golangci-lint run --fix ./...
test:
desc: Run tests
cmds:
- go test -v ./...
test-coverage:
desc: Run tests with coverage analysis
cmds:
- mkdir -p coverage
- go test -coverprofile=coverage/coverage.out ./...
- go tool cover -func=coverage/coverage.out
- echo "Generating HTML coverage report in coverage/coverage.html"
- go tool cover -html=coverage/coverage.out -o coverage/coverage.html
build:
desc: Build the binary
vars:
VERSION:
sh: git describe --tags --always --dirty || echo "dev"
COMMIT:
sh: git rev-parse --short HEAD || echo "unknown"
BUILD_DATE:
sh: date -u +"%Y-%m-%dT%H:%M:%SZ"
cmds:
- mkdir -p bin
- go build -ldflags "-s -w -X github.com/StacklokLabs/toolhive/cmd/thv/app.Version={{.VERSION}} -X github.com/StacklokLabs/toolhive/cmd/thv/app.Commit={{.COMMIT}} -X github.com/StacklokLabs/toolhive/cmd/thv/app.BuildDate={{.BUILD_DATE}}" -o bin/thv ./cmd/thv
install:
desc: Install the thv binary to GOPATH/bin
vars:
VERSION:
sh: git describe --tags --always --dirty || echo "dev"
COMMIT:
sh: git rev-parse --short HEAD || echo "unknown"
BUILD_DATE:
sh: date -u +"%Y-%m-%dT%H:%M:%SZ"
cmds:
- go install -ldflags "-s -w -X github.com/StacklokLabs/toolhive/pkg/versions.Version={{.VERSION}} -X github.com/StacklokLabs/toolhive/pkg/versions.Commit={{.COMMIT}} -X github.com/StacklokLabs/toolhive/pkg/versions.BuildDate={{.BUILD_DATE}}" -v ./cmd/thv
all:
desc: Run linting, tests, and build
deps: [lint, test, build]
all-with-coverage:
desc: Run linting, tests with coverage, and build
deps: [lint, test-coverage, build]
build-image:
desc: Build the image with ko
cmds:
- ko build --platform linux/amd64,linux/arm64 --local ./cmd/thv
test-k8s-apply:
desc: Builds the image, loads it into kind, and applies the Kubernetes manifests
vars:
IMAGE:
sh: ko build --platform linux/amd64 --local -B ./cmd/thv | tail -n 1
cmds:
# gets the local kind kubeconfig
- kind get kubeconfig > kconfig.yaml
# Load the image into kind
- echo "Loading image {{.IMAGE}} into kind..."
- kind load docker-image {{.IMAGE}}
# Apply the Kubernetes manifest
- echo "Applying Kubernetes manifest..."
- kubectl apply -f <(KO_DOCKER_REPO=kind.local ko resolve --platform linux/amd64 -f deploy/k8s/thv.yaml) --kubeconfig kconfig.yaml
# Create RoleBinding for ToolHive until (TODO: https://github.com/StacklokLabs/toolhive/issues/102) is done
- kubectl create clusterrolebinding default-view --clusterrole=cluster-admin --serviceaccount=default:default --kubeconfig kconfig.yaml
- echo "Applying Kubernetes Ingress manifest..."
- kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/deploy-ingress-nginx.yaml --kubeconfig kconfig.yaml
# we want to wait until the nginx controlle is ready before we apply our ingress object
- kubectl wait --namespace=ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/instance=ingress-nginx,app.kubernetes.io/component=controller --timeout=120s --kubeconfig kconfig.yaml
- kubectl apply -f deploy/k8s/ingress.yaml --kubeconfig kconfig.yaml
# We do the below commands because of some inconsistency between the secret and webhook caBundle. ref: https://github.com/kubernetes/ingress-nginx/issues/5968#issuecomment-849772666
- CA=$(kubectl -n ingress-nginx get secret ingress-nginx-admission -ojsonpath='{.data.ca}' --kubeconfig kconfig.yaml)
- kubectl patch validatingwebhookconfigurations ingress-nginx-admission --type='json' --patch='[{"op":"add","path":"/webhooks/0/clientConfig/caBundle","value":"'$CA'"}]' --kubeconfig kconfig.yaml
# Operator tasks
build-operator:
desc: Build the operator binary
vars:
VERSION:
sh: git describe --tags --always --dirty || echo "dev"
COMMIT:
sh: git rev-parse --short HEAD || echo "unknown"
BUILD_DATE:
sh: date -u +"%Y-%m-%dT%H:%M:%SZ"
cmds:
- mkdir -p bin
- go build -ldflags "-s -w -X github.com/StacklokLabs/toolhive/cmd/thv-operator/app.Version={{.VERSION}} -X github.com/StacklokLabs/toolhive/cmd/thv-operator/app.Commit={{.COMMIT}} -X github.com/StacklokLabs/toolhive/cmd/thv-operator/app.BuildDate={{.BUILD_DATE}}" -o bin/thv-operator ./cmd/thv-operator
install-operator:
desc: Install the thv-operator binary to GOPATH/bin
vars:
VERSION:
sh: git describe --tags --always --dirty || echo "dev"
COMMIT:
sh: git rev-parse --short HEAD || echo "unknown"
BUILD_DATE:
sh: date -u +"%Y-%m-%dT%H:%M:%SZ"
cmds:
- go install -ldflags "-s -w -X github.com/StacklokLabs/toolhive/cmd/thv-operator/app.Version={{.VERSION}} -X github.com/StacklokLabs/toolhive/cmd/thv-operator/app.Commit={{.COMMIT}} -X github.com/StacklokLabs/toolhive/cmd/thv-operator/app.BuildDate={{.BUILD_DATE}}" -v ./cmd/thv-operator
build-operator-image:
desc: Build the operator image with ko
cmds:
- ko build --platform linux/amd64,linux/arm64 --local ./cmd/thv-operator
operator-install-crds:
desc: Install CRDs into the K8s cluster
cmds:
- kubectl apply -f deploy/operator/crds/toolhive.stacklok.dev_mcpservers.yaml
operator-uninstall-crds:
desc: Uninstall CRDs from the K8s cluster
cmds:
- kubectl delete -f deploy/operator/crds/toolhive.stacklok.dev_mcpservers.yaml
operator-deploy:
desc: Deploy operator to the K8s cluster
cmds:
- kubectl apply -f deploy/operator/namespace.yaml
- kubectl apply -f deploy/operator/rbac.yaml
- kubectl apply -f <(KO_DOCKER_REPO=kind.local ko resolve --platform linux/amd64 -f deploy/operator/operator.yaml)
operator-undeploy:
desc: Undeploy operator from the K8s cluster
cmds:
- kubectl delete -f deploy/operator/operator.yaml
- kubectl delete -f deploy/operator/rbac.yaml
- kubectl delete -f deploy/operator/namespace.yaml
operator-test-k8s-apply:
desc: Builds the operator image, loads it into kind, and applies the Kubernetes manifests
vars:
IMAGE:
sh: ko build --platform linux/amd64 --local -B ./cmd/thv-operator | tail -n 1
cmds:
# gets the local kind kubeconfig
- kind get kubeconfig > kconfig.yaml
# Load the image into kind
- echo "Loading image {{.IMAGE}} into kind..."
- kind load docker-image {{.IMAGE}}
# Apply the CRDs
- echo "Applying CRDs..."
- kubectl apply -f deploy/operator/crds/toolhive.stacklok.dev_mcpservers.yaml --kubeconfig kconfig.yaml
# Apply the operator manifests
- echo "Applying operator manifests..."
- kubectl apply -f deploy/operator/namespace.yaml --kubeconfig kconfig.yaml
- kubectl apply -f deploy/operator/rbac.yaml --kubeconfig kconfig.yaml
- kubectl apply -f <(KO_DOCKER_REPO=kind.local ko resolve --platform linux/amd64 -f deploy/operator/operator.yaml) --kubeconfig kconfig.yaml
# Kubebuilder tasks
operator-generate:
desc: Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations
cmds:
- mkdir -p bin
- go install sigs.k8s.io/controller-tools/cmd/[email protected]
- $(go env GOPATH)/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./cmd/thv-operator/..."
operator-manifests:
desc: Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects
cmds:
- mkdir -p bin
- go install sigs.k8s.io/controller-tools/cmd/[email protected]
- $(go env GOPATH)/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./cmd/thv-operator/..." output:crd:artifacts:config=deploy/operator/crds output:rbac:artifacts:config=deploy/operator
operator-test:
desc: Run tests for the operator
cmds:
- go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
- KUBEBUILDER_ASSETS="$(shell setup-envtest use 1.28.0 -p path)" go test ./cmd/thv-operator/... -coverprofile cover.out