-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathTaskfile.yml
More file actions
302 lines (280 loc) · 11.8 KB
/
Taskfile.yml
File metadata and controls
302 lines (280 loc) · 11.8 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
version: 3
output: prefixed
vars:
GREEN: \033[0;32m
BLUE: \033[0;34m
RED: \033[0;31m
NC: \033[0m
E2E_NETWORK: pg-extensions-e2e
DAGGER_ENGINE_NAME: dagger-engine-pg-extensions
REGISTRY_NAME: registry.pg-extensions
REGISTRY_HOST_PORT: 5000
# renovate: datasource=git-refs depName=kind lookupName=https://github.com/aweris/daggerverse currentValue=main
DAGGER_KIND_SHA: dadbc09a1e0790ccbf1d88f796308b26a12f0488
# renovate: datasource=docker depName=kindest/node versioning=docker
KIND_NODE_VERSION: v1.34.2@sha256:745f8ed46d8e99517774768227fd1a0af34a6bf395aef9c7ed98fbce0e263918
K8S_VERSION: '{{ regexReplaceAll "^v([0-9.]+).*" .KIND_NODE_VERSION "$1" }}'
KIND_CLUSTER_NAME: pg-extensions-{{ .K8S_VERSION }}
tasks:
default:
desc: Build all targets (default)
cmds:
- task: bake:all
prereqs:
desc: Ensure prerequisites are met
run: once
silent: true
cmds:
- echo -e "{{.BLUE}}Checking prerequisites...{{.NC}}"
- command -v dagger >/dev/null 2>&1 || { echo -e "{{.RED}}Dagger is not installed.{{.NC}}"; exit 1; }
- command -v docker >/dev/null 2>&1 || { echo -e "{{.RED}}Docker is not installed.{{.NC}}"; exit 1; }
- docker --version >/dev/null 2>&1 || { echo -e "{{.RED}}Cannot run docker command.{{.NC}}"; exit 1; }
- docker buildx version >/dev/null 2>&1 || { echo -e "{{.RED}}Docker Buildx not available.{{.NC}}"; exit 1; }
- docker context inspect >/dev/null 2>&1 || { echo -e "{{.RED}}Docker context not configured.{{.NC}}"; exit 1; }
- echo -e "{{.GREEN}}All prerequisites satisfied!{{.NC}}"
checks:
desc: Run checks for the specified target
deps:
- prereqs
prefix: 'checks-{{.TARGET}}'
silent: true
preconditions:
- sh: test -f "{{.TARGET}}/metadata.hcl"
msg: 'Not a valid target, metadata.hcl file is missing. Target: {{.TARGET}}'
cmds:
- echo -e "{{.BLUE}}Checking target {{.TARGET}}...{{.NC}}"
- docker buildx bake -f {{.TARGET}}/metadata.hcl -f docker-bake.hcl --check
requires:
vars:
- name: TARGET
checks:all:
desc: Run checks for all the available targets
vars:
TARGETS:
sh: dagger call -sm ./dagger/maintenance/ get-targets | tr -d '[]"' | tr ',' '\n'
cmds:
- for:
var: TARGETS
vars:
TARGET: "{{.ITEM}}"
task: checks
bake:
desc: Bake the specified target
deps:
- prereqs
prefix: 'bake-{{.TARGET}}'
silent: true
vars:
PUSH: '{{.PUSH | default "false"}}'
DRY_RUN: '{{.DRY_RUN | default "false"}}'
preconditions:
- sh: test -f "{{.TARGET}}/metadata.hcl"
msg: 'Not a valid target, metadata.hcl file is missing. Target: {{.TARGET}}'
cmds:
- echo -e "{{.BLUE}}Baking target {{.TARGET}} (push={{.PUSH}})...{{.NC}}"
- |
if [ "{{.DRY_RUN}}" = "true" ]; then
echo -e "{{.GREEN}}[DRY RUN] docker buildx bake -f {{.TARGET}}/metadata.hcl -f docker-bake.hcl --push={{.PUSH}}{{.NC}}"
else
docker buildx bake -f {{.TARGET}}/metadata.hcl -f docker-bake.hcl --push={{.PUSH}}
fi
- echo -e "{{.GREEN}}--- Successfully baked {{.TARGET}} ---{{.NC}}"
requires:
vars:
- name: TARGET
bake:all:
desc: Bake all the available targets
vars:
TARGETS:
sh: dagger call -sm ./dagger/maintenance/ get-targets | tr -d '[]"' | tr ',' '\n'
cmds:
- for:
var: TARGETS
vars:
TARGET: "{{.ITEM}}"
task: bake
update-os-libs:
desc: Update OS libs on the specified target
deps:
- prereqs
prefix: 'update-os-libs-{{.TARGET}}'
silent: true
cmds:
- echo -e "{{.BLUE}}Updating OS libs for {{.TARGET}}...{{.NC}}"
- dagger call -sm ./dagger/maintenance/ update-oslibs --source . --target {{.TARGET}} export --path .
requires:
vars:
- name: TARGET
update-os-libs:all:
desc: Update OS libs for all the available targets
vars:
TARGETS:
sh: dagger call -sm ./dagger/maintenance/ get-oslibs-targets | tr -d '[]"' | tr ',' '\n'
cmds:
- for:
var: TARGETS
vars:
TARGET: "{{.ITEM}}"
task: update-os-libs
create-extension:
desc: Scaffold a new extension directory
cmds:
- dagger call -sm ./dagger/maintenance/ create --name {{.NAME}} export --path ./{{.NAME}}
requires:
vars:
- name: NAME
e2e:create-docker-network:
desc: Create Docker network to connect all the services, such as the Registry, Kind nodes, Chainsaw, etc.
run: once
internal: true
cmds:
- docker network create {{ .E2E_NETWORK }}
status:
- docker network inspect {{ .E2E_NETWORK }}
e2e:start-container-registry:
desc: Start a local Docker registry to push the built images for E2E tests
deps:
- e2e:create-docker-network
internal: true
run: once
vars:
# renovate: datasource=docker depName=registry versioning=docker
REGISTRY_VERSION: 3.0.0@sha256:cd92709b4191c5779cd7215ccd695db6c54652e7a62843197e367427efb84d0e
cmds:
- >
docker run -d --name {{ .REGISTRY_NAME }} --rm -p {{ .REGISTRY_HOST_PORT }}:5000
--network {{ .E2E_NETWORK }} registry:{{ .REGISTRY_VERSION }}
status:
- test "$(docker inspect -f {{`'{{json .State.Running}}'`}} {{ .REGISTRY_NAME }})" == "true"
e2e:start-dagger-engine:
desc: Start a custom Dagger engine so we can connect it to the E2E Docker network
deps:
- e2e:create-docker-network
internal: true
run: once
vars:
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver
DAGGER_ENGINE_VERSION: v0.19.8
cmds:
- >
docker run -d -v /var/lib/dagger --name {{ .DAGGER_ENGINE_NAME }} --restart always --network {{ .E2E_NETWORK }}
--privileged registry.dagger.io/engine:{{ .DAGGER_ENGINE_VERSION }}
status:
- test "$(docker inspect -f {{`'{{json .State.Running}}'`}} {{ .DAGGER_ENGINE_NAME }})" == "true"
e2e:setup-kind:
desc: Setup Kind cluster for E2E tests
deps:
- e2e:start-container-registry
- e2e:start-dagger-engine
internal: true
run: once
vars:
REGISTRY_DIR: /etc/containerd/certs.d/localhost:{{ .REGISTRY_HOST_PORT }}
DOCKER_SOCKET:
sh: docker context inspect -f {{`'{{json .Endpoints.docker.Host}}'`}} $(docker context show)
env:
_EXPERIMENTAL_DAGGER_RUNNER_HOST: container://{{ .DAGGER_ENGINE_NAME }}
cmds:
- >
dagger call -m github.com/aweris/daggerverse/kind@{{ .DAGGER_KIND_SHA }} --socket {{ .DOCKER_SOCKET }}
container with-env-variable --name=KIND_EXPERIMENTAL_DOCKER_NETWORK --value={{ .E2E_NETWORK }} with-env-variable --name=CACHE_BUSTER --value="$(date)"
with-file --source=kind-config.yaml --path=/root/kind-config.yaml
with-exec --args="kind","create","cluster","--name","{{ .KIND_CLUSTER_NAME }}","--image","kindest/node:{{ .KIND_NODE_VERSION }}","--config","/root/kind-config.yaml" sync
- docker exec "{{ .KIND_CLUSTER_NAME }}-control-plane" mkdir -p "{{ .REGISTRY_DIR }}"
- |
cat <<EOF | docker exec -i "{{ .KIND_CLUSTER_NAME }}-control-plane" cp /dev/stdin "{{ .REGISTRY_DIR }}/hosts.toml"
[host."http://{{ .REGISTRY_NAME }}:5000"]
EOF
status:
- >
test "$(dagger call -m github.com/aweris/daggerverse/kind@{{ .DAGGER_KIND_SHA }}
--socket {{ .DOCKER_SOCKET }} cluster --name {{ .KIND_CLUSTER_NAME }} exist)" == "true"
e2e:install-cnpg:
desc: Install CloudNativePG operator in the Kind cluster
deps:
- e2e:setup-kind
internal: true
vars:
# renovate: datasource=github-tags depName=cloudnative-pg/cloudnative-pg versioning=semver extractVersion=^v(?<version>\d+\.\d+)\.\d+$
CNPG_RELEASE: 1.28
# renovate: datasource=docker depName=alpine/kubectl versioning=docker
KUBECTL_VERSION: 1.34.2@sha256:96a7d245a74d461925a56e3024d2f027c2a7a822b3e9e0117ec558db42de9c35
DOCKER_SOCKET:
sh: docker context inspect -f {{`'{{json .Endpoints.docker.Host}}'`}} $(docker context show)
CNPG_MANIFEST:
sh: |
if [ "{{ .CNPG_RELEASE }}" = "main" ]; then
echo "https://raw.githubusercontent.com/cloudnative-pg/artifacts/main/manifests/operator-manifest.yaml"
else
echo "https://raw.githubusercontent.com/cloudnative-pg/artifacts/release-{{ .CNPG_RELEASE }}/manifests/operator-manifest.yaml"
fi
env:
_EXPERIMENTAL_DAGGER_RUNNER_HOST: container://{{ .DAGGER_ENGINE_NAME }}
cmds:
- |
KUBECONFIG=$(dagger call -m github.com/aweris/daggerverse/kind@{{ .DAGGER_KIND_SHA }} \
--socket {{ .DOCKER_SOCKET }} container \
with-exec --args "kind","get","kubeconfig","--internal","--name","{{ .KIND_CLUSTER_NAME }}" stdout)
dagger core container from --address=alpine/kubectl:{{ .KUBECTL_VERSION }} \
with-new-file --contents "${KUBECONFIG}" --path /root/.kube/config --expand \
with-env-variable --name=CACHEBUSTER --value="$(date)" \
with-exec --args="apply","--server-side","-f","{{ .CNPG_MANIFEST }}" --use-entrypoint sync
dagger core container from --address=alpine/kubectl:{{ .KUBECTL_VERSION }} \
with-new-file --contents "${KUBECONFIG}" --path /root/.kube/config --expand \
with-env-variable --name=CACHEBUSTER --value="$(date)" \
with-exec \
--args="wait","--for=condition=Available","--timeout=2m","-n","cnpg-system","deployments","cnpg-controller-manager" \
--use-entrypoint sync
status:
- |
KUBECONFIG=$(dagger call -m github.com/aweris/daggerverse/kind@{{ .DAGGER_KIND_SHA }} \
--socket {{ .DOCKER_SOCKET }} container \
with-exec --args "kind","get","kubeconfig","--internal","--name","{{ .KIND_CLUSTER_NAME }}" stdout)
dagger core container from --address=alpine/kubectl:{{ .KUBECTL_VERSION }} \
with-new-file --contents "${KUBECONFIG}" --path /root/.kube/config --expand \
with-env-variable --name=CACHEBUSTER --value="$(date)" \
with-exec \
--args="get","--namespace=cnpg-system","deployments.apps","cnpg-controller-manager" \
--use-entrypoint sync
e2e:export-kubeconfig:
desc: Export Kind cluster kubeconfig at path defined by KUBECONFIG_PATH var (default ~/.kube/config)
deps:
- e2e:setup-kind
vars:
KUBECONFIG_PATH: '{{.KUBECONFIG_PATH| default "~/.kube/config"}}'
DOCKER_SOCKET:
sh: docker context inspect -f {{`'{{json .Endpoints.docker.Host}}'`}} $(docker context show)
env:
_EXPERIMENTAL_DAGGER_RUNNER_HOST: container://{{ .DAGGER_ENGINE_NAME }}
cmds:
- |
CONFIG=$(dagger call -m github.com/aweris/daggerverse/kind@{{ .DAGGER_KIND_SHA }} \
--socket {{ .DOCKER_SOCKET }} container \
with-exec --args "kind","get","kubeconfig","--name","{{ .KIND_CLUSTER_NAME }}" stdout)
mkdir -p $(dirname {{ .KUBECONFIG_PATH }})
echo "${CONFIG}" > {{ .KUBECONFIG_PATH }}
e2e:setup-env:
desc: Setup E2E environment
silent: true
deps:
- e2e:start-container-registry
- e2e:start-dagger-engine
- e2e:install-cnpg
cmds:
- echo -e "{{.GREEN}}--- E2E environment setup complete ---{{.NC}}"
e2e:cleanup:
desc: Cleanup E2E resources
deps:
- e2e:start-dagger-engine
vars:
DOCKER_SOCKET:
sh: docker context inspect -f {{`'{{json .Endpoints.docker.Host}}'`}} $(docker context show)
env:
_EXPERIMENTAL_DAGGER_RUNNER_HOST: container://{{ .DAGGER_ENGINE_NAME }}
cmds:
- >
dagger call -m github.com/aweris/daggerverse/kind@{{ .DAGGER_KIND_SHA }}
--socket {{ .DOCKER_SOCKET }} cluster --name {{ .KIND_CLUSTER_NAME }} delete || true
- docker rm -fv {{ .DAGGER_ENGINE_NAME }} || true
- docker rm -fv {{ .REGISTRY_NAME }} || true
- docker network rm {{ .E2E_NETWORK }} || true