-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
68 lines (53 loc) · 2.43 KB
/
Taskfile.yaml
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
## # Description: Taskfile for k3d cluster
## # In the tasks below, a mix of shell commands combined with Go templates is used as a way to make the tasks more dynamic
## # and record the go template syntax for future use.
version: "3"
env:
CLUSTER_NAME: kubepal
KUBE: export KUBECONFIG=/mnt/c/Users/{{.USER}}/.kube/config # WSL path to kubeconfig file on Windows host
# Include the github actions tasks
includes:
run: .github/Taskfile.yml
tasks:
create:
desc: |
Create and access a k3d cluster.
If operating on WSL, the KUBECONFIG env var will point to the Windows host.
{{ if and (eq OS "windows") (eq (env "KUBECONFIG") "") }}Kubeconfig path: {{.USERPROFILE}}\.kube\config{{end}}
{{ if and (eq OS "linux") (ne (env "KUBECONFIG") "") }}Kubeconfig path: {{(env "KUBECONFIG")}}{{end}}
cmds:
- '{{if eq OS "linux"}}source .github/scripts/server.sh{{end}}' # Source the server.sh script to start docker
# If KUBECONFIG env var is not set, set it to point to the Windows host (or the host where the kubeconfig file is located)
- '{{if eq OS "linux"}}[ -z "$KUBECONFIG" ] && echo "Set KUBECONFIG env var ==> {{.KUBE}}" \
&& exit 1 || k3d cluster create {{.CLUSTER_NAME}} --api-port 6443 -p 8080:80@loadbalancer --agents 2{{end}}'
- '{{if eq OS "windows"}}k3d cluster create {{.CLUSTER_NAME}} --api-port 6443 -p 8080:80@loadbalancer --agents 2{{end}}' # If host is Windows, create cluster
status:
- k3d cluster list {{.CLUSTER_NAME}} # If cluster exists, skip the task
silent: true
tf_init:
desc: "Initialize terraform"
cmds:
- terraform -chdir='{{fromSlash "kube/minik8s"}}' init
status: # If terraform is initialized, skip the task
- terraform -chdir='{{fromSlash "kube/minik8s"}}' state list
deploy:
desc: "Bootstrap cluster and deploy apps"
cmds:
- task: create
- task: tf_init
- terraform -chdir='{{fromSlash "kube/minik8s"}}' test
- terraform -chdir='{{fromSlash "kube/minik8s"}}' apply -auto-approve
delete:
desc: "Delete cluster"
cmds:
- k3d cluster delete {{.CLUSTER_NAME}}
- '{{if eq OS "linux"}}rm -rf kube/minik8s/.terraf*{{end}}'
- '{{if eq OS "windows"}}powershell Remove-Item "kube\bootstrap\.terraf*" -Recurse -Force{{end}}'
silent: true
test:
desc: "Run static tests"
cmds:
- task: run:lint
- task: run:trivy
- task: run:checkov
- task: run:diff