forked from agntcy/oasf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
269 lines (241 loc) · 8.03 KB
/
Taskfile.yml
File metadata and controls
269 lines (241 loc) · 8.03 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
version: "3"
## Load config from dotenv file
dotenv:
- '{{ .ROOT_DIR }}/.env'
## Collection of config params
vars:
## Image config
IMAGE_REPO: '{{ .IMAGE_REPO | default "ghcr.io/agntcy" }}'
IMAGE_TAG: '{{ .IMAGE_TAG }}'
## Dependency config
BIN_DIR: '{{ .ROOT_DIR }}/bin'
HELM_VERSION: '3.16.3'
HELM_BIN: '{{ .BIN_DIR }}/helm-{{.HELM_VERSION}}'
KUBECTL_VERSION: '1.31.3'
KUBECTL_BIN: '{{ .BIN_DIR }}/kubectl-{{.KUBECTL_VERSION}}'
KIND_VERSION: '0.25.0'
KIND_BIN: '{{ .BIN_DIR }}/kind-{{.KIND_VERSION}}'
## Set refresh interval for observable tasks like hot-reload
interval: 500ms
tasks:
##
## General
##
default:
cmds:
- task -l
build:
desc: Build project artifacts
cmds:
- task: build:charts
- task: build:images
build:charts:
desc: Build helm charts
deps:
- deps:helm
vars:
HELM_ALL_CHART_PATHS:
sh: find . -name Chart.yaml -exec dirname {} \;
cmds:
- for: { var: HELM_ALL_CHART_PATHS }
cmd: 'cd {{ .ITEM }} && {{ .HELM_BIN }} dependency update'
build:images:
desc: Build container images
vars:
BAKE_OPTS: '--set *.platform=linux/{{ARCH}}'
cmds:
- docker buildx bake {{.BAKE_OPTS}}
release:
desc: Release images for all components with a release tag
prompt:
- Are you sure you want to push the images to remote registry?
vars:
RELEASE_TAG: '{{ .RELEASE_TAG | default "latest" }}'
cmds:
# TODO: use buildx to simplify
- |
images=$(docker buildx bake default --print | jq -r '.target | with_entries(.value |= .tags[0]) | to_entries[] | .value')
echo "$images" | while read image; do
target_name="${image%%:*}"
echo "Releasing images for $target_name"
docker tag $image $target_name:latest
docker tag $image $target_name:{{.RELEASE_TAG}}
docker image rm $image
docker push --all-tags $target_name
done
up:
desc: Deploy services in an ephemeral kind cluster
preconditions:
- which yq
deps:
- deps:helm
- deps:kubectl
- deps:kind
vars:
# Kind args
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "test-oasf-cluster" }}'
KIND_CREATE_OPTS: '{{ .KIND_CREATE_OPTS | default "" }}'
KIND_CONFIG_PATH: '/tmp/{{.KIND_CLUSTER_NAME}}'
# Deployment args
HELM_NAMESPACE: '{{ .HELM_NAMESPACE | default "default" }}'
HELM_CHART_PATH: '{{ .ROOT_DIR }}/install/charts/oasf'
HELM_VALUES_PATH: '{{ .HELM_VALUES_PATH | default (printf "%s/install/charts/oasf/values-test.yaml" .ROOT_DIR) }}'
RELEASE_NAME: 'oasf'
cmds:
# Clean up previous deployment
- task: down
# Create volume config to share between Kind and host
- |
cat <<EOF > {{.KIND_CONFIG_PATH}}
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
extraMounts:
- hostPath: {{ .ROOT_DIR }}/schema
containerPath: /schema
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 30080
hostPort: 8080
protocol: TCP
EOF
# Create ephemeral cluster
- '{{ .KIND_BIN }} create cluster {{ .KIND_CREATE_OPTS }} --name {{ .KIND_CLUSTER_NAME }} --config {{.KIND_CONFIG_PATH}}'
- '{{ .KIND_BIN }} export kubeconfig --name {{ .KIND_CLUSTER_NAME }}'
# Check cluster status
- '{{ .KUBECTL_BIN }} cluster-info'
# Extract images from values-test.yaml and load them into kind
- |
{{- if .IMAGE_TAG }}
{{ .KIND_BIN }} load docker-image "{{ .IMAGE_REPO }}/oasf-server:{{ .IMAGE_TAG }}" --name {{ .KIND_CLUSTER_NAME }}
{{- else }}
images=$(yq eval '.image.versions[].server' {{ .HELM_VALUES_PATH }})
echo "Images to load: $images"
echo "$images" | while read image; do
{{ .KIND_BIN }} load docker-image "{{ .IMAGE_REPO }}/oasf-server:$image" --name {{ .KIND_CLUSTER_NAME }}
done
{{- end }}
# Deploy chart
- |
{{ .HELM_BIN }} upgrade {{.RELEASE_NAME}} \
{{ .HELM_CHART_PATH }} \
-f {{ .HELM_VALUES_PATH }} \
--set image.repository="{{ .IMAGE_REPO }}/oasf-server" \
{{- if .IMAGE_TAG }}
--set image.versions[0].server={{.IMAGE_TAG}} \
{{- end }}
--namespace {{ .HELM_NAMESPACE }} \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
# Wait for the ingress controller deployment to be available
- |
echo "Waiting for Deployment {{.RELEASE_NAME}}-ingress-controller in namespace {{.HELM_NAMESPACE}} to become available..."
if ! {{ .KUBECTL_BIN }} wait deployment/{{.RELEASE_NAME}}-ingress-controller \
--for=condition=Available \
-n {{ .HELM_NAMESPACE }} \
--timeout=120s; then
echo "Error: Deployment {{.RELEASE_NAME}}-ingress-controller did not become available within 120 seconds."
exit 1
fi
echo
echo "Deployment is available at http://localhost:8080."
reload:
desc: Hot reload schema changes after deployment
watch: true
deps:
- deps:kubectl
sources:
- 'schema/**/*'
vars:
LABEL_SELECTOR: 'default-schema=true'
preconditions:
- '{{ .KUBECTL_BIN }} get po -l {{.LABEL_SELECTOR}}'
cmds:
- |
POD_NAME=$({{ .KUBECTL_BIN }} get pods -l {{.LABEL_SELECTOR}} -o jsonpath="{.items[0].metadata.name}")
{{.KUBECTL_BIN}} exec $POD_NAME -- ./bin/schema_server rpc "Schema.reload()"
- echo "Reloaded schema! Use CTRL + C to exit."
down:
desc: Stop services and remove ephemeral kind cluster
deps:
- deps:kind
vars:
# Kind args
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "test-oasf-cluster" }}'
cmds:
- '{{ .KIND_BIN }} delete cluster --name {{ .KIND_CLUSTER_NAME }}'
test:
desc: Run end-to-end test suite
cmds:
- defer: { task: down }
- task: up
# NOTE: For now, we are only interested to know if the
# chart can be deployed or not.
# TODO: add test cases here
##
## Dependencies
##
deps:
desc: Install project dependencies
cmds:
- task: deps:helm
- task: deps:kubectl
- task: deps:kind
deps:bin-dir:
desc: Create bin directory
internal: true
run: once
cmd: mkdir -p {{.BIN_DIR}}
status:
- test -d {{.BIN_DIR}}
deps:helm:
desc: Ensure supported Helm version is installed
internal: true
deps:
- deps:bin-dir
preconditions:
- which curl
- which tar
cmds:
- cmd: echo "Downloading Helm v{{.HELM_VERSION}}..."
- cmd: curl -sSfL 'https://get.helm.sh/helm-v{{.HELM_VERSION}}-{{OS}}-{{ARCH}}.tar.gz' --output - | tar xzvOf - '{{OS}}-{{ARCH}}/helm' > {{.HELM_BIN}}
- cmd: chmod +x {{.HELM_BIN}}
status:
- test -x {{.HELM_BIN}}
deps:kubectl:
desc: Ensure supported kubectl version is installed
internal: true
deps:
- deps:bin-dir
preconditions:
- which curl
cmds:
- cmd: echo "Downloading Kubectl v{{.KUBECTL_VERSION}}..."
- cmd: curl -L "https://dl.k8s.io/release/v{{.KUBECTL_VERSION}}/bin/{{OS}}/{{ARCH}}/kubectl" -o {{.KUBECTL_BIN}}
- cmd: chmod +x {{.KUBECTL_BIN}}
status:
- test -x {{.KUBECTL_BIN}}
deps:kind:
desc: Ensure supported kind version is installed
internal: true
deps:
- deps:bin-dir
preconditions:
- which go
cmds:
- cmd: echo "Downloading Kind v{{.KIND_VERSION}}..."
- cmd: GOBIN={{.BIN_DIR}} go install sigs.k8s.io/kind@v{{.KIND_VERSION}}
- cmd: mv {{.BIN_DIR}}/kind {{.KIND_BIN}}
status:
- test -x {{.KIND_BIN}}